Something went wrong. Try again.
Reactos
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054/* * Wininet - HTTP tests * * Copyright 2002 Aric Stewart * Copyright 2004 Mike McCormack * Copyright 2005 Hans Leidekker * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */
#include <stdarg.h>#include <stdio.h>#include <stdlib.h>#include <limits.h>
#include "windef.h"#include "winbase.h"#include "wininet.h"#include "winineti.h"#include "winsock2.h"
#include "wine/test.h"
/* Undocumented security flags */#define _SECURITY_FLAG_CERT_REV_FAILED 0x00800000#define _SECURITY_FLAG_CERT_INVALID_CA 0x01000000#define _SECURITY_FLAG_CERT_INVALID_CN 0x02000000#define _SECURITY_FLAG_CERT_INVALID_DATE 0x04000000
#define TEST_URL "http://test.winehq.org/tests/hello.html"
static BOOL first_connection_to_test_url = TRUE;static BOOL https_support = TRUE;
/* Adapted from dlls/urlmon/tests/protocol.c */
#define SET_EXPECT2(status, num) \ expect[status] = num
#define SET_EXPECT(status) \ SET_EXPECT2(status, 1)
#define SET_OPTIONAL2(status, num) \ optional[status] = num
#define SET_OPTIONAL(status) \ SET_OPTIONAL2(status, 1)
/* SET_WINE_ALLOW's should be used with an appropriate * todo_wine CHECK_NOTIFIED at a later point in the code */#define SET_WINE_ALLOW2(status, num) \ wine_allow[status] = num
#define SET_WINE_ALLOW(status) \ SET_WINE_ALLOW2(status, 1)
#define CHECK_EXPECT(status) \ do { \ if (!expect[status] && !optional[status] && wine_allow[status]) \ { \ todo_wine ok(expect[status], "unexpected status %d (%s)\n", status, \ status < MAX_INTERNET_STATUS && status_string[status] ? \ status_string[status] : "unknown"); \ wine_allow[status]--; \ } \ else \ { \ ok(expect[status] || optional[status], "unexpected status %d (%s)\n", status, \ status < MAX_INTERNET_STATUS && status_string[status] ? \ status_string[status] : "unknown"); \ if (expect[status]) expect[status]--; \ else if(optional[status]) optional[status]--; \ } \ notified[status]++; \ }while(0)
/* CLEAR_NOTIFIED used in cases when notification behavior * differs between Windows versions */#define CLEAR_NOTIFIED(status) \ expect[status] = optional[status] = wine_allow[status] = notified[status] = 0;
#define CHECK_NOTIFIED2(status, num) \ do { \ ok(notified[status] + optional[status] == (num), \ "expected status %d (%s) %d times, received %d times\n", \ status, status < MAX_INTERNET_STATUS && status_string[status] ? \ status_string[status] : "unknown", (num), notified[status]); \ CLEAR_NOTIFIED(status); \ }while(0)
#define CHECK_NOTIFIED(status) \ CHECK_NOTIFIED2(status, 1)
#define CHECK_NOT_NOTIFIED(status) \ CHECK_NOTIFIED2(status, 0)
#define MAX_INTERNET_STATUS (INTERNET_STATUS_COOKIE_HISTORY+1)static int expect[MAX_INTERNET_STATUS], optional[MAX_INTERNET_STATUS], wine_allow[MAX_INTERNET_STATUS], notified[MAX_INTERNET_STATUS];static const char *status_string[MAX_INTERNET_STATUS];
static HANDLE complete_event, conn_close_event, conn_wait_event, server_req_rec_event, request_sent_event;static DWORD req_error;static BOOL is_ie7plus = TRUE;
#define TESTF_REDIRECT 0x01#define TESTF_COMPRESSED 0x02#define TESTF_CHUNKED 0x04
typedef struct { const char *url; const char *redirected_url; const char *host; const char *path; const char *headers; DWORD flags; const char *post_data; const char *content;} test_data_t;
static const test_data_t test_data[] = { { "http://test.winehq.org/tests/data.php", "http://test.winehq.org/tests/data.php", "test.winehq.org", "/tests/data.php", "", TESTF_CHUNKED }, { "http://test.winehq.org/tests/redirect", "http://test.winehq.org/tests/hello.html", "test.winehq.org", "/tests/redirect", "", TESTF_REDIRECT }, { "http://test.winehq.org/tests/gzip.php", "http://test.winehq.org/tests/gzip.php", "test.winehq.org", "/tests/gzip.php", "Accept-Encoding: gzip, deflate", TESTF_COMPRESSED }, { "http://test.winehq.org/tests/post.php", "http://test.winehq.org/tests/post.php", "test.winehq.org", "/tests/post.php", "Content-Type: application/x-www-form-urlencoded", 0, "mode=Test", "mode => Test\n" }};
static INTERNET_STATUS_CALLBACK (WINAPI *pInternetSetStatusCallbackA)(HINTERNET ,INTERNET_STATUS_CALLBACK);static INTERNET_STATUS_CALLBACK (WINAPI *pInternetSetStatusCallbackW)(HINTERNET ,INTERNET_STATUS_CALLBACK);static BOOL (WINAPI *pInternetGetSecurityInfoByURLA)(LPSTR,PCCERT_CHAIN_CONTEXT*,DWORD*);
static BOOL is_lang_english(void){ static HMODULE hkernel32 = NULL; static LANGID (WINAPI *pGetThreadUILanguage)(void) = NULL; static LANGID (WINAPI *pGetUserDefaultUILanguage)(void) = NULL;
if (!hkernel32) { hkernel32 = GetModuleHandleA("kernel32.dll"); pGetThreadUILanguage = (void*)GetProcAddress(hkernel32, "GetThreadUILanguage"); pGetUserDefaultUILanguage = (void*)GetProcAddress(hkernel32, "GetUserDefaultUILanguage"); } if (pGetThreadUILanguage) return PRIMARYLANGID(pGetThreadUILanguage()) == LANG_ENGLISH; if (pGetUserDefaultUILanguage) return PRIMARYLANGID(pGetUserDefaultUILanguage()) == LANG_ENGLISH;
return PRIMARYLANGID(GetUserDefaultLangID()) == LANG_ENGLISH;}
static int strcmp_wa(LPCWSTR strw, const char *stra){ WCHAR buf[512]; MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, ARRAY_SIZE(buf)); return lstrcmpW(strw, buf);}
static BOOL proxy_active(void){ HKEY internet_settings; DWORD proxy_enable; DWORD size;
if (RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", 0, KEY_QUERY_VALUE, &internet_settings) != ERROR_SUCCESS) return FALSE;
size = sizeof(DWORD); if (RegQueryValueExA(internet_settings, "ProxyEnable", NULL, NULL, (LPBYTE) &proxy_enable, &size) != ERROR_SUCCESS) proxy_enable = 0;
RegCloseKey(internet_settings);
return proxy_enable != 0;}
static void init_events(void){ complete_event = CreateEventW(NULL, FALSE, FALSE, NULL); conn_close_event = CreateEventW(NULL, FALSE, FALSE, NULL); conn_wait_event = CreateEventW(NULL, FALSE, FALSE, NULL); server_req_rec_event = CreateEventW(NULL, FALSE, FALSE, NULL); request_sent_event = CreateEventW(NULL, FALSE, FALSE, NULL);}
static void free_events(void){ CloseHandle(complete_event); CloseHandle(conn_close_event); CloseHandle(conn_wait_event); CloseHandle(server_req_rec_event); CloseHandle(request_sent_event);}
static void reset_events(void){ ResetEvent(complete_event); ResetEvent(conn_close_event); ResetEvent(conn_wait_event); ResetEvent(server_req_rec_event); ResetEvent(request_sent_event);}
#define test_status_code(a,b) _test_status_code(__LINE__,a,b, FALSE)#define test_status_code_todo(a,b) _test_status_code(__LINE__,a,b, TRUE)static void _test_status_code(unsigned line, HINTERNET req, DWORD excode, BOOL is_todo){ DWORD code, size, index; char exbuf[12], bufa[10]; WCHAR bufw[10]; BOOL res;
code = 0xdeadbeef; size = sizeof(code); res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &code, &size, NULL); ok_(__FILE__,line)(res, "[1] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number) failed: %u\n", GetLastError()); todo_wine_if (is_todo) ok_(__FILE__,line)(code == excode, "code = %d, expected %d\n", code, excode); ok_(__FILE__,line)(size == sizeof(code), "size = %u\n", size);
code = 0xdeadbeef; index = 0; size = sizeof(code); res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &code, &size, &index); ok_(__FILE__,line)(res, "[2] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number index) failed: %u\n", GetLastError()); ok_(__FILE__,line)(!index, "index = %d, expected 0\n", index); ok_(__FILE__,line)(size == sizeof(code), "size = %u\n", size);
sprintf(exbuf, "%u", excode);
size = sizeof(bufa); res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE, bufa, &size, NULL); ok_(__FILE__,line)(res, "[3] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError()); todo_wine_if (is_todo) ok_(__FILE__,line)(!strcmp(bufa, exbuf), "unexpected status code %s, expected %s\n", bufa, exbuf); ok_(__FILE__,line)(size == strlen(exbuf), "unexpected size %d for \"%s\"\n", size, exbuf);
size = 0; res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE, NULL, &size, NULL); ok_(__FILE__,line)(!res && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "[4] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError()); ok_(__FILE__,line)(size == strlen(exbuf)+1, "unexpected size %d for \"%s\"\n", size, exbuf);
size = sizeof(bufw); res = HttpQueryInfoW(req, HTTP_QUERY_STATUS_CODE, bufw, &size, NULL); ok_(__FILE__,line)(res, "[5] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError()); todo_wine_if (is_todo) ok_(__FILE__,line)(!strcmp_wa(bufw, exbuf), "unexpected status code %s, expected %s\n", bufa, exbuf); ok_(__FILE__,line)(size == strlen(exbuf)*sizeof(WCHAR), "unexpected size %d for \"%s\"\n", size, exbuf);
size = 0; res = HttpQueryInfoW(req, HTTP_QUERY_STATUS_CODE, bufw, &size, NULL); ok_(__FILE__,line)(!res && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "[6] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError()); ok_(__FILE__,line)(size == (strlen(exbuf)+1)*sizeof(WCHAR), "unexpected size %d for \"%s\"\n", size, exbuf);
if(0) { size = sizeof(bufw); res = HttpQueryInfoW(req, HTTP_QUERY_STATUS_CODE, NULL, &size, NULL); ok(!res && GetLastError() == ERROR_INVALID_PARAMETER, "HttpQueryInfo(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError()); ok(size == sizeof(bufw), "unexpected size %d\n", size); }
code = 0xdeadbeef; index = 1; size = sizeof(code); res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &code, &size, &index); ok_(__FILE__,line)(!res && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "[7] HttpQueryInfoA failed: %x(%d)\n", res, GetLastError());
code = 0xdeadbeef; size = sizeof(code); res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_REQUEST_HEADERS, &code, &size, NULL); ok_(__FILE__,line)(!res && GetLastError() == ERROR_HTTP_INVALID_QUERY_REQUEST, "[8] HttpQueryInfoA failed: %x(%d)\n", res, GetLastError());}
#define test_request_flags(a,b) _test_request_flags(__LINE__,a,b,FALSE)#define test_request_flags_todo(a,b) _test_request_flags(__LINE__,a,b,TRUE)static void _test_request_flags(unsigned line, HINTERNET req, DWORD exflags, BOOL is_todo){ DWORD flags, size; BOOL res;
flags = 0xdeadbeef; size = sizeof(flags); res = InternetQueryOptionW(req, INTERNET_OPTION_REQUEST_FLAGS, &flags, &size); ok_(__FILE__,line)(res, "InternetQueryOptionW(INTERNET_OPTION_REQUEST_FLAGS) failed: %u\n", GetLastError());
/* FIXME: Remove once we have INTERNET_REQFLAG_CACHE_WRITE_DISABLED implementation */ flags &= ~INTERNET_REQFLAG_CACHE_WRITE_DISABLED; todo_wine_if (is_todo) ok_(__FILE__,line)(flags == exflags, "flags = %x, expected %x\n", flags, exflags);}
#define test_request_url(a,b) _test_request_url(__LINE__,a,b)static void _test_request_url(unsigned line, HINTERNET req, const char *expected_url){ char buf[INTERNET_MAX_URL_LENGTH]; DWORD size = sizeof(buf); BOOL res;
res = InternetQueryOptionA(req, INTERNET_OPTION_URL, buf, &size); ok_(__FILE__,line)(res, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError()); ok_(__FILE__,line)(size == strlen(expected_url), "size = %u\n", size); ok_(__FILE__,line)(!strcmp(buf, expected_url), "unexpected URL %s, expected %s\n", buf, expected_url);}
#define test_http_version(a) _test_http_version(__LINE__,a)static void _test_http_version(unsigned line, HINTERNET req){ HTTP_VERSION_INFO v = {0xdeadbeef, 0xdeadbeef}; DWORD size; BOOL res;
size = sizeof(v); res = InternetQueryOptionW(req, INTERNET_OPTION_HTTP_VERSION, &v, &size); ok_(__FILE__,line)(res, "InternetQueryOptionW(INTERNET_OPTION_HTTP_VERSION) failed: %u\n", GetLastError()); ok_(__FILE__,line)(v.dwMajorVersion == 1, "dwMajorVersion = %d\n", v.dwMajorVersion); ok_(__FILE__,line)(v.dwMinorVersion == 1, "dwMinorVersion = %d\n", v.dwMinorVersion);}
static int close_handle_cnt;
static VOID WINAPI callback( HINTERNET hInternet, DWORD_PTR dwContext, DWORD dwInternetStatus, LPVOID lpvStatusInformation, DWORD dwStatusInformationLength){ ros_skip_flaky CHECK_EXPECT(dwInternetStatus); switch (dwInternetStatus) { case INTERNET_STATUS_RESOLVING_NAME: if(winetest_debug > 1) trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESOLVING_NAME \"%s\" %d\n", GetCurrentThreadId(), hInternet, dwContext, (LPCSTR)lpvStatusInformation,dwStatusInformationLength); *(LPSTR)lpvStatusInformation = '\0'; break; case INTERNET_STATUS_NAME_RESOLVED: if(winetest_debug > 1) trace("%04x:Callback %p 0x%lx INTERNET_STATUS_NAME_RESOLVED \"%s\" %d\n", GetCurrentThreadId(), hInternet, dwContext, (LPCSTR)lpvStatusInformation,dwStatusInformationLength); *(LPSTR)lpvStatusInformation = '\0'; break; case INTERNET_STATUS_CONNECTING_TO_SERVER: if(winetest_debug > 1) trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTING_TO_SERVER \"%s\" %d\n", GetCurrentThreadId(), hInternet, dwContext, (LPCSTR)lpvStatusInformation,dwStatusInformationLength); ok(dwStatusInformationLength == strlen(lpvStatusInformation)+1, "unexpected size %u\n", dwStatusInformationLength); *(LPSTR)lpvStatusInformation = '\0'; break; case INTERNET_STATUS_CONNECTED_TO_SERVER: if(winetest_debug > 1) trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTED_TO_SERVER \"%s\" %d\n", GetCurrentThreadId(), hInternet, dwContext, (LPCSTR)lpvStatusInformation,dwStatusInformationLength); ok(dwStatusInformationLength == strlen(lpvStatusInformation)+1, "unexpected size %u\n", dwStatusInformationLength); *(LPSTR)lpvStatusInformation = '\0'; break; case INTERNET_STATUS_SENDING_REQUEST: if(winetest_debug > 1) trace("%04x:Callback %p 0x%lx INTERNET_STATUS_SENDING_REQUEST %p %d\n", GetCurrentThreadId(), hInternet, dwContext, lpvStatusInformation,dwStatusInformationLength); break; case INTERNET_STATUS_REQUEST_SENT: ok(dwStatusInformationLength == sizeof(DWORD), "info length should be sizeof(DWORD) instead of %d\n", dwStatusInformationLength); if(winetest_debug > 1) trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_SENT 0x%x %d\n", GetCurrentThreadId(), hInternet, dwContext, *(DWORD *)lpvStatusInformation,dwStatusInformationLength); break; case INTERNET_STATUS_RECEIVING_RESPONSE: if(winetest_debug > 1) trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RECEIVING_RESPONSE %p %d\n", GetCurrentThreadId(), hInternet, dwContext, lpvStatusInformation,dwStatusInformationLength); break; case INTERNET_STATUS_RESPONSE_RECEIVED: ok(dwStatusInformationLength == sizeof(DWORD), "info length should be sizeof(DWORD) instead of %d\n", dwStatusInformationLength); if(winetest_debug > 1) trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESPONSE_RECEIVED 0x%x %d\n", GetCurrentThreadId(), hInternet, dwContext, *(DWORD *)lpvStatusInformation,dwStatusInformationLength); break; case INTERNET_STATUS_CTL_RESPONSE_RECEIVED: if(winetest_debug > 1) trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CTL_RESPONSE_RECEIVED %p %d\n", GetCurrentThreadId(), hInternet,dwContext, lpvStatusInformation,dwStatusInformationLength); break; case INTERNET_STATUS_PREFETCH: if(winetest_debug > 1) trace("%04x:Callback %p 0x%lx INTERNET_STATUS_PREFETCH %p %d\n", GetCurrentThreadId(), hInternet, dwContext, lpvStatusInformation,dwStatusInformationLength); break; case INTERNET_STATUS_CLOSING_CONNECTION: if(winetest_debug > 1) trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CLOSING_CONNECTION %p %d\n", GetCurrentThreadId(), hInternet, dwContext, lpvStatusInformation,dwStatusInformationLength); break; case INTERNET_STATUS_CONNECTION_CLOSED: if(winetest_debug > 1) trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTION_CLOSED %p %d\n", GetCurrentThreadId(), hInternet, dwContext, lpvStatusInformation,dwStatusInformationLength); break; case INTERNET_STATUS_HANDLE_CREATED: ok(dwStatusInformationLength == sizeof(HINTERNET), "info length should be sizeof(HINTERNET) instead of %d\n", dwStatusInformationLength); if(winetest_debug > 1) trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CREATED %p %d\n", GetCurrentThreadId(), hInternet, dwContext, *(HINTERNET *)lpvStatusInformation,dwStatusInformationLength); CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY); SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY); break; case INTERNET_STATUS_HANDLE_CLOSING: ok(dwStatusInformationLength == sizeof(HINTERNET), "info length should be sizeof(HINTERNET) instead of %d\n", dwStatusInformationLength); if(winetest_debug > 1) trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %d\n", GetCurrentThreadId(), hInternet, dwContext, *(HINTERNET *)lpvStatusInformation, dwStatusInformationLength); if(!InterlockedDecrement(&close_handle_cnt)) SetEvent(complete_event); break; case INTERNET_STATUS_REQUEST_COMPLETE: { INTERNET_ASYNC_RESULT *iar = (INTERNET_ASYNC_RESULT *)lpvStatusInformation; ok(dwStatusInformationLength == sizeof(INTERNET_ASYNC_RESULT), "info length should be sizeof(INTERNET_ASYNC_RESULT) instead of %d\n", dwStatusInformationLength); ok(iar->dwResult == 1 || iar->dwResult == 0, "iar->dwResult = %ld\n", iar->dwResult); if(winetest_debug > 1) trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_COMPLETE {%ld,%d} %d\n", GetCurrentThreadId(), hInternet, dwContext, iar->dwResult,iar->dwError,dwStatusInformationLength); req_error = iar->dwError; if(!close_handle_cnt) SetEvent(complete_event); break; } case INTERNET_STATUS_REDIRECT: if(winetest_debug > 1) trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REDIRECT \"%s\" %d\n", GetCurrentThreadId(), hInternet, dwContext, (LPCSTR)lpvStatusInformation, dwStatusInformationLength); *(LPSTR)lpvStatusInformation = '\0'; CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY); SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY); break; case INTERNET_STATUS_INTERMEDIATE_RESPONSE: if(winetest_debug > 1) trace("%04x:Callback %p 0x%lx INTERNET_STATUS_INTERMEDIATE_RESPONSE %p %d\n", GetCurrentThreadId(), hInternet, dwContext, lpvStatusInformation, dwStatusInformationLength); break; default: if(winetest_debug > 1) trace("%04x:Callback %p 0x%lx %d %p %d\n", GetCurrentThreadId(), hInternet, dwContext, dwInternetStatus, lpvStatusInformation, dwStatusInformationLength); }}
typedef struct { HINTERNET session; HINTERNET connection; HINTERNET request;} test_request_t;
#define open_simple_request(a,b,c,d,e) _open_simple_request(__LINE__,a,b,c,d,e)static void _open_simple_request(unsigned line, test_request_t *req, const char *host, int port, const char *verb, const char *url){ req->session = InternetOpenA(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); ok_(__FILE__,line)(req->session != NULL, "InternetOpenA failed: %u\n", GetLastError());
req->connection = InternetConnectA(req->session, host, port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); ok_(__FILE__,line)(req->connection != NULL, "InternetConnectA failed: %u\n", GetLastError());
req->request = HttpOpenRequestA(req->connection, verb, url, NULL, NULL, NULL, 0, 0); ok_(__FILE__,line)(req->request != NULL, "HttpOpenRequest failed: %u\n", GetLastError());}
#define close_request(a) _close_request(__LINE__,a)static void _close_request(unsigned line, test_request_t *req){ BOOL ret;
ret = InternetCloseHandle(req->request); ok_(__FILE__,line)(ret, "InternetCloseHandle(request) failed: %u\n", GetLastError()); ret = InternetCloseHandle(req->connection); ok_(__FILE__,line)(ret, "InternetCloseHandle(connection) failed: %u\n", GetLastError()); ret = InternetCloseHandle(req->session); ok_(__FILE__,line)(ret, "InternetCloseHandle(session) failed: %u\n", GetLastError());}
#define receive_simple_request(a,b,c) _receive_simple_request(__LINE__,a,b,c)static DWORD _receive_simple_request(unsigned line, HINTERNET req, char *buf, size_t buf_size){ DWORD read = 0; BOOL ret;
ret = InternetReadFile(req, buf, buf_size, &read); ok_(__FILE__,line)(ret, "InternetReadFile failed: %u\n", GetLastError());
return read;}
static void close_async_handle(HINTERNET handle, int handle_cnt){ BOOL res;
close_handle_cnt = handle_cnt;
SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING, handle_cnt); res = InternetCloseHandle(handle); ok(res, "InternetCloseHandle failed: %u\n", GetLastError()); WaitForSingleObject(complete_event, INFINITE); CHECK_NOTIFIED2(INTERNET_STATUS_HANDLE_CLOSING, handle_cnt);}
static void InternetReadFile_test(int flags, const test_data_t *test){ char *post_data = NULL; BOOL res, on_async = TRUE; CHAR buffer[4000]; WCHAR wbuffer[4000]; DWORD length, length2, index, exlen = 0, post_len = 0; const char *types[2] = { "*", NULL }; HINTERNET hi, hic = 0, hor = 0; DWORD contents_length, accepts_ranges; BOOL not_supported;
trace("Starting InternetReadFile test with flags 0x%x on url %s\n",flags,test->url); reset_events();
trace("InternetOpenA <--\n"); hi = InternetOpenA((test->flags & TESTF_COMPRESSED) ? "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" : "", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, flags); ok((hi != 0x0),"InternetOpen failed with error %u\n", GetLastError()); trace("InternetOpenA -->\n");
if (hi == 0x0) goto abort;
pInternetSetStatusCallbackA(hi,&callback);
SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
trace("InternetConnectA <--\n"); hic=InternetConnectA(hi, test->host, INTERNET_INVALID_PORT_NUMBER, NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef); ok((hic != 0x0),"InternetConnect failed with error %u\n", GetLastError()); trace("InternetConnectA -->\n");
if (hic == 0x0) goto abort;
CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED); SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
trace("HttpOpenRequestA <--\n"); hor = HttpOpenRequestA(hic, test->post_data ? "POST" : "GET", test->path, NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RELOAD, 0xdeadbead); if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) { /* * If the internet name can't be resolved we are probably behind * a firewall or in some other way not directly connected to the * Internet. Not enough reason to fail the test. Just ignore and * abort. */ } else { ok((hor != 0x0),"HttpOpenRequest failed with error %u\n", GetLastError()); } trace("HttpOpenRequestA -->\n");
if (hor == 0x0) goto abort;
test_request_flags(hor, INTERNET_REQFLAG_NO_HEADERS); test_request_url(hor, test->url);
length = sizeof(buffer); res = HttpQueryInfoA(hor, HTTP_QUERY_RAW_HEADERS, buffer, &length, 0x0); ok(res, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError()); ok(length == 0 || (length == 1 && !*buffer) /* win10 */, "HTTP_QUERY_RAW_HEADERS: expected length 0, but got %d\n", length); ok(!strcmp(buffer, ""), "HTTP_QUERY_RAW_HEADERS: expected string \"\", but got \"%s\"\n", buffer);
CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED); CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME); CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED); SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT,2); SET_OPTIONAL2(INTERNET_STATUS_COOKIE_RECEIVED,2); if (first_connection_to_test_url) { SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME); SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED); } SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER); SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER); SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST, (test->flags & TESTF_REDIRECT) ? 2 : 1); SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT, (test->flags & TESTF_REDIRECT) ? 2 : 1); SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE, (test->flags & TESTF_REDIRECT) ? 2 : 1); SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED, (test->flags & TESTF_REDIRECT) ? 2 : 1); if(test->flags & TESTF_REDIRECT) { SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION, 2); SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED, 2); } SET_EXPECT(INTERNET_STATUS_REDIRECT); SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER); SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER); if (flags & INTERNET_FLAG_ASYNC) SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
if(test->flags & TESTF_COMPRESSED) { BOOL b = TRUE;
res = InternetSetOptionA(hor, INTERNET_OPTION_HTTP_DECODING, &b, sizeof(b)); ok(res || broken(!res && GetLastError() == ERROR_INTERNET_INVALID_OPTION), "InternetSetOption failed: %u\n", GetLastError()); if(!res) goto abort; }
test_status_code(hor, 0);
trace("HttpSendRequestA -->\n"); if(test->post_data) { post_len = strlen(test->post_data); post_data = HeapAlloc(GetProcessHeap(), 0, post_len); memcpy(post_data, test->post_data, post_len); } SetLastError(0xdeadbeef); res = HttpSendRequestA(hor, test->headers, -1, post_data, post_len); if (flags & INTERNET_FLAG_ASYNC) ok(!res && (GetLastError() == ERROR_IO_PENDING), "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n"); else ok(res || (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED), "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError()); trace("HttpSendRequestA <--\n");
if (flags & INTERNET_FLAG_ASYNC) { WaitForSingleObject(complete_event, INFINITE); ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error); } HeapFree(GetProcessHeap(), 0, post_data);
CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT); CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_RECEIVED); if (first_connection_to_test_url) { if (! proxy_active()) { CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME); CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED); } else { CLEAR_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME); CLEAR_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED); } } else { CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME); CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED); } CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST, (test->flags & TESTF_REDIRECT) ? 2 : 1); CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT, (test->flags & TESTF_REDIRECT) ? 2 : 1); CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE, (test->flags & TESTF_REDIRECT) ? 2 : 1); CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED, (test->flags & TESTF_REDIRECT) ? 2 : 1); if(test->flags & TESTF_REDIRECT) CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT); if (flags & INTERNET_FLAG_ASYNC) CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE); /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */ CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER); CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
test_request_flags(hor, 0);
length = 100; res = InternetQueryOptionA(hor,INTERNET_OPTION_URL,buffer,&length); ok(res, "InternetQueryOptionA(INTERNET_OPTION_URL) failed with error %d\n", GetLastError());
length = sizeof(buffer)-2; memset(buffer, 0x77, sizeof(buffer)); SetLastError(0xdeadbeef); res = HttpQueryInfoA(hor,HTTP_QUERY_RAW_HEADERS,buffer,&length,0x0); ok(res, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError()); ok(GetLastError() == 0 || broken(GetLastError() == 0xdeadbeef /* XP/W2K3 */), "Last Error not reset %u\n", GetLastError()); /* show that the function writes data past the length returned */ ok(buffer[length-2], "Expected any header character, got 0x00\n"); ok(!buffer[length-1], "Expected 0x00, got %02X\n", buffer[length-1]); ok(!buffer[length], "Expected 0x00, got %02X\n", buffer[length]); ok(buffer[length+1] == 0x77, "Expected 0x77, got %02X\n", buffer[length+1]);
length2 = length; res = HttpQueryInfoA(hor,HTTP_QUERY_RAW_HEADERS,buffer,&length2,0x0); ok(!res, "Expected 0x00, got %d\n", res); ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError()); ok(length2 == length+1, "Expected %d, got %d\n", length+1, length2); /* the in length of the buffer must be +1 but the length returned does not count this */ length2 = length+1; memset(buffer, 0x77, sizeof(buffer)); res = HttpQueryInfoA(hor,HTTP_QUERY_RAW_HEADERS,buffer,&length2,0x0); ok(res, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError()); ok(buffer[length2] == 0x00, "Expected 0x00, got %02X\n", buffer[length2]); ok(buffer[length2+1] == 0x77, "Expected 0x77, got %02X\n", buffer[length2+1]); ok(length2 == length, "Value should not have changed: %d != %d\n", length2, length);
length = sizeof(wbuffer)-2*sizeof(WCHAR); memset(wbuffer, 0x77, sizeof(wbuffer)); res = HttpQueryInfoW(hor, HTTP_QUERY_RAW_HEADERS, wbuffer, &length, 0x0); ok(res, "HttpQueryInfoW(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError()); ok(length % sizeof(WCHAR) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length); length /= sizeof(WCHAR); /* show that the function writes data past the length returned */ ok(wbuffer[length-2], "Expected any header character, got 0x0000\n"); ok(!wbuffer[length-1], "Expected 0x0000, got %04X\n", wbuffer[length-1]); ok(!wbuffer[length], "Expected 0x0000, got %04X\n", wbuffer[length]); ok(wbuffer[length+1] == 0x7777 || broken(wbuffer[length+1] != 0x7777), "Expected 0x7777, got %04X\n", wbuffer[length+1]);
length2 = length*sizeof(WCHAR); res = HttpQueryInfoW(hor,HTTP_QUERY_RAW_HEADERS,wbuffer,&length2,0x0); ok(!res, "Expected 0x00, got %d\n", res); ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError()); ok(length2 % sizeof(WCHAR) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length2); length2 /= sizeof(WCHAR); ok(length2 == length+1, "Expected %d, got %d\n", length+1, length2); /* the in length of the buffer must be +1 but the length returned does not count this */ length2 = (length+1)*sizeof(WCHAR); memset(wbuffer, 0x77, sizeof(wbuffer)); res = HttpQueryInfoW(hor,HTTP_QUERY_RAW_HEADERS,wbuffer,&length2,0x0); ok(res, "HttpQueryInfoW(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError()); ok(length2 % sizeof(WCHAR) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length2); length2 /= sizeof(WCHAR); ok(!wbuffer[length2], "Expected 0x0000, got %04X\n", wbuffer[length2]); ok(wbuffer[length2+1] == 0x7777, "Expected 0x7777, got %04X\n", wbuffer[length2+1]); ok(length2 == length, "Value should not have changed: %d != %d\n", length2, length);
test_request_url(hor, test->redirected_url);
index = 0; length = 0; SetLastError(0xdeadbeef); ok(HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_LENGTH,NULL,&length,&index) == FALSE,"Query worked\n"); if(test->flags & TESTF_COMPRESSED) ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError()); ok(index == 0, "Index was incremented\n");
index = 0; length = 16; res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_LENGTH,&buffer,&length,&index); trace("Option HTTP_QUERY_CONTENT_LENGTH -> %i %s (%u)\n",res,buffer,GetLastError()); if(test->flags & TESTF_COMPRESSED) { ok(!res && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %x (%u)\n", res, GetLastError()); contents_length = 0; } else { contents_length = atoi(buffer); } ok(!res || index == 1, "Index was not incremented although result is %x (index = %u)\n", res, index);
length = 64; *buffer = 0; res = HttpQueryInfoA(hor,HTTP_QUERY_ACCEPT_RANGES,&buffer,&length,0x0); trace("Option HTTP_QUERY_ACCEPT_RANGES -> %i %s (%u)\n",res,buffer,GetLastError()); accepts_ranges = res && !strcmp(buffer, "bytes");
length = 100; res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_TYPE,buffer,&length,0x0); buffer[length]=0; trace("Option HTTP_QUERY_CONTENT_TYPE -> %i %s\n",res,buffer);
length = 100; res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_ENCODING,buffer,&length,0x0); buffer[length]=0; trace("Option HTTP_QUERY_CONTENT_ENCODING -> %i %s\n",res,buffer);
SetLastError(0xdeadbeef); length = InternetSetFilePointer(hor, 0, NULL, FILE_END, 0); not_supported = length == INVALID_SET_FILE_POINTER && GetLastError() == ERROR_INTERNET_INVALID_OPERATION; if (accepts_ranges) todo_wine ok((length == contents_length && (GetLastError() == ERROR_SUCCESS || broken(GetLastError() == 0xdeadbeef))) || broken(not_supported), "Got unexpected length %#x, GetLastError() %u, contents_length %u, accepts_ranges %#x.\n", length, GetLastError(), contents_length, accepts_ranges); else ok(not_supported, "Got unexpected length %#x, GetLastError() %u.\n", length, GetLastError());
if (length != INVALID_SET_FILE_POINTER) { SetLastError(0xdeadbeef); length = InternetSetFilePointer(hor, 0, NULL, FILE_BEGIN, 0); ok(!length && (GetLastError() == ERROR_SUCCESS || broken(GetLastError() == 0xdeadbeef)), "Got unexpected length %#x, GetLastError() %u.\n", length, GetLastError()); }
SetLastError(0xdeadbeef); res = InternetReadFile(NULL, buffer, 100, &length); ok(!res, "InternetReadFile should have failed\n"); ok(GetLastError() == ERROR_INVALID_HANDLE, "InternetReadFile should have set last error to ERROR_INVALID_HANDLE instead of %u\n", GetLastError());
length = 100; if(winetest_debug > 1) trace("Entering Query loop\n");
while (TRUE) { if (flags & INTERNET_FLAG_ASYNC) SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
/* IE11 calls those in InternetQueryDataAvailable call. */ SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE); SET_OPTIONAL(INTERNET_STATUS_RESPONSE_RECEIVED);
length = 0; res = InternetQueryDataAvailable(hor,&length,0x0,0x0);
CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
if (flags & INTERNET_FLAG_ASYNC) { if (res) { CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE); if(exlen) { ok(length >= exlen, "length %u < exlen %u\n", length, exlen); exlen = 0; } } else if (GetLastError() == ERROR_IO_PENDING) { if(winetest_debug > 1) trace("pending\n"); /* on some tests, InternetQueryDataAvailable returns non-zero length and ERROR_IO_PENDING */ if(!(test->flags & TESTF_CHUNKED)) ok(!length, "InternetQueryDataAvailable returned ERROR_IO_PENDING and %u length\n", length); WaitForSingleObject(complete_event, INFINITE); exlen = length; ok(exlen, "length = 0\n"); CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE); CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED); ok(req_error, "req_error = 0\n"); continue; }else { ok(0, "InternetQueryDataAvailable failed: %u\n", GetLastError()); } }else { ok(res, "InternetQueryDataAvailable failed: %u\n", GetLastError()); } CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
if(winetest_debug > 1) trace("length %u\n", length); if(test->flags & TESTF_CHUNKED) ok(length <= 8192, "length = %d, expected <= 8192\n", length); if (length) { char *buffer; buffer = HeapAlloc(GetProcessHeap(),0,length+1);
res = InternetReadFile(hor,buffer,length,&length);
buffer[length]=0;
if(winetest_debug > 1) trace("ReadFile -> %s %i\n", res ? "TRUE" : "FALSE", length);
if(test->content) ok(!strcmp(buffer, test->content), "buffer = '%s', expected '%s'\n", buffer, test->content); HeapFree(GetProcessHeap(),0,buffer); }else { ok(!on_async, "Returned zero size in response to request complete\n"); break; } on_async = FALSE; } if(test->flags & TESTF_REDIRECT) { CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION, 2); CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED, 2); }abort: if(winetest_debug > 1) trace("aborting\n"); close_async_handle(hi, 2); first_connection_to_test_url = FALSE;}
static void InternetReadFile_chunked_test(void){ BOOL res; CHAR buffer[4000]; DWORD length, got; const char *types[2] = { "*", NULL }; HINTERNET hi, hic = 0, hor = 0;
trace("Starting InternetReadFile chunked test\n");
trace("InternetOpenA <--\n"); hi = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); ok((hi != 0x0),"InternetOpen failed with error %u\n", GetLastError()); trace("InternetOpenA -->\n");
if (hi == 0x0) goto abort;
trace("InternetConnectA <--\n"); hic=InternetConnectA(hi, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER, NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef); ok((hic != 0x0),"InternetConnect failed with error %u\n", GetLastError()); trace("InternetConnectA -->\n");
if (hic == 0x0) goto abort;
trace("HttpOpenRequestA <--\n"); hor = HttpOpenRequestA(hic, "GET", "/tests/chunked", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RELOAD, 0xdeadbead); if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) { /* * If the internet name can't be resolved we are probably behind * a firewall or in some other way not directly connected to the * Internet. Not enough reason to fail the test. Just ignore and * abort. */ } else { ok((hor != 0x0),"HttpOpenRequest failed with error %u\n", GetLastError()); } trace("HttpOpenRequestA -->\n");
if (hor == 0x0) goto abort;
trace("HttpSendRequestA -->\n"); SetLastError(0xdeadbeef); res = HttpSendRequestA(hor, "", -1, NULL, 0); ok(res || (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED), "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError()); trace("HttpSendRequestA <--\n");
test_request_flags(hor, 0);
length = 100; res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_TYPE,buffer,&length,0x0); buffer[length]=0; trace("Option CONTENT_TYPE -> %i %s\n",res,buffer);
SetLastError( 0xdeadbeef ); length = 100; res = HttpQueryInfoA(hor,HTTP_QUERY_TRANSFER_ENCODING,buffer,&length,0x0); buffer[length]=0; trace("Option TRANSFER_ENCODING -> %i %s\n",res,buffer); ok( res || ( proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND ), "Failed to get TRANSFER_ENCODING option, error %u\n", GetLastError() ); ok( !strcmp( buffer, "chunked" ) || ( ! res && proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND ), "Wrong transfer encoding '%s'\n", buffer );
SetLastError( 0xdeadbeef ); length = 16; res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_LENGTH,&buffer,&length,0x0); ok( !res, "Found CONTENT_LENGTH option '%s'\n", buffer ); ok( GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "Wrong error %u\n", GetLastError() );
length = 100; trace("Entering Query loop\n");
while (TRUE) { res = InternetQueryDataAvailable(hor,&length,0x0,0x0); ok(!(!res && length != 0),"InternetQueryDataAvailable failed with non-zero length\n"); ok(res, "InternetQueryDataAvailable failed, error %d\n", GetLastError()); trace("got %u available\n",length); if (length) { char *buffer = HeapAlloc(GetProcessHeap(),0,length+1);
SetLastError(0xdeadbeef); res = InternetReadFile(hor,buffer,length,&got); ok(GetLastError() == 0 || broken(GetLastError() == 0xdeadbeef /* XP/W2K3 */), "Last Error not reset %u\n", GetLastError());
buffer[got]=0; trace("ReadFile -> %i %i\n",res,got); ok( length == got, "only got %u of %u available\n", got, length ); ok( buffer[got-1] == '\n', "received partial line '%s'\n", buffer );
HeapFree(GetProcessHeap(),0,buffer); if (!got) break; } if (length == 0) { got = 0xdeadbeef; SetLastError(0xdeadbeef); res = InternetReadFile( hor, buffer, 1, &got ); ok( res, "InternetReadFile failed: %u\n", GetLastError() ); ok(GetLastError() == 0 || broken(GetLastError() == 0xdeadbeef /* XP/W2K3 */), "Last Error not reset %u\n", GetLastError()); ok( !got, "got %u\n", got ); break; } }abort: trace("aborting\n"); if (hor != 0x0) { res = InternetCloseHandle(hor); ok (res, "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n"); } if (hi != 0x0) { res = InternetCloseHandle(hi); ok (res, "InternetCloseHandle of handle opened by InternetOpenA failed\n"); }}
static void InternetReadFileExA_test(int flags){ DWORD rc; DWORD length; const char *types[2] = { "*", NULL }; HINTERNET hi, hic = 0, hor = 0; INTERNET_BUFFERSA inetbuffers;
trace("Starting InternetReadFileExA test with flags 0x%x\n",flags); reset_events();
trace("InternetOpenA <--\n"); hi = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, flags); ok((hi != 0x0),"InternetOpen failed with error %u\n", GetLastError()); trace("InternetOpenA -->\n");
if (hi == 0x0) goto abort;
pInternetSetStatusCallbackA(hi,&callback);
SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
trace("InternetConnectA <--\n"); hic=InternetConnectA(hi, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER, NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef); ok((hic != 0x0),"InternetConnect failed with error %u\n", GetLastError()); trace("InternetConnectA -->\n");
if (hic == 0x0) goto abort;
CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED); SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
trace("HttpOpenRequestA <--\n"); hor = HttpOpenRequestA(hic, "GET", "/tests/redirect", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RELOAD, 0xdeadbead); if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) { /* * If the internet name can't be resolved we are probably behind * a firewall or in some other way not directly connected to the * Internet. Not enough reason to fail the test. Just ignore and * abort. */ } else { ok((hor != 0x0),"HttpOpenRequest failed with error %u\n", GetLastError()); } trace("HttpOpenRequestA -->\n");
if (hor == 0x0) goto abort;
CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED); CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME); CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED); if (first_connection_to_test_url) { SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME); SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED); } SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT, 2); SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER); SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER); SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST, 2); SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT, 2); SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE, 2); SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED, 2); SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION, 2); SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED, 2); SET_EXPECT(INTERNET_STATUS_REDIRECT); SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER); SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER); if (flags & INTERNET_FLAG_ASYNC) SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE); else SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE);
trace("HttpSendRequestA -->\n"); SetLastError(0xdeadbeef); rc = HttpSendRequestA(hor, "", -1, NULL, 0); if (flags & INTERNET_FLAG_ASYNC) ok(((rc == 0)&&(GetLastError() == ERROR_IO_PENDING)), "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n"); else ok((rc != 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED, "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError()); trace("HttpSendRequestA <--\n");
if (!rc && (GetLastError() == ERROR_IO_PENDING)) { WaitForSingleObject(complete_event, INFINITE); ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error); }
if (first_connection_to_test_url) { CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME); CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED); } else { CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME); CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED); } CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST, 2); CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT, 2); CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE, 2); CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED, 2); CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION, 2); CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED, 2); CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT); if (flags & INTERNET_FLAG_ASYNC) CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE); else todo_wine CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE); CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT); /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */ CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER); CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
if(is_ie7plus) { rc = InternetReadFileExW(hor, NULL, 0, 0xdeadcafe); ok(!rc && (GetLastError() == ERROR_INVALID_PARAMETER), "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n", rc ? "TRUE" : "FALSE", GetLastError()); }
/* tests invalid dwStructSize */ inetbuffers.dwStructSize = sizeof(inetbuffers)+1; inetbuffers.lpcszHeader = NULL; inetbuffers.dwHeadersLength = 0; inetbuffers.dwBufferLength = 10; inetbuffers.lpvBuffer = HeapAlloc(GetProcessHeap(), 0, 10); inetbuffers.dwOffsetHigh = 1234; inetbuffers.dwOffsetLow = 5678; rc = InternetReadFileExA(hor, &inetbuffers, 0, 0xdeadcafe); ok(!rc && (GetLastError() == ERROR_INVALID_PARAMETER), "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n", rc ? "TRUE" : "FALSE", GetLastError()); HeapFree(GetProcessHeap(), 0, inetbuffers.lpvBuffer);
test_request_flags(hor, 0);
/* tests to see whether lpcszHeader is used - it isn't */ inetbuffers.dwStructSize = sizeof(inetbuffers); inetbuffers.lpcszHeader = (LPCSTR)0xdeadbeef; inetbuffers.dwHeadersLength = 255; inetbuffers.dwBufferLength = 0; inetbuffers.lpvBuffer = NULL; inetbuffers.dwOffsetHigh = 1234; inetbuffers.dwOffsetLow = 5678; rc = InternetReadFileExA(hor, &inetbuffers, 0, 0xdeadcafe); ok(rc, "InternetReadFileEx failed with error %u\n", GetLastError()); trace("read %i bytes\n", inetbuffers.dwBufferLength);
rc = InternetReadFileExA(NULL, &inetbuffers, 0, 0xdeadcafe); ok(!rc && (GetLastError() == ERROR_INVALID_HANDLE), "InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %u\n", rc ? "TRUE" : "FALSE", GetLastError());
length = 0; trace("Entering Query loop\n");
while (TRUE) { inetbuffers.dwStructSize = sizeof(inetbuffers); inetbuffers.dwBufferLength = 1024; inetbuffers.lpvBuffer = HeapAlloc(GetProcessHeap(), 0, inetbuffers.dwBufferLength+1); inetbuffers.dwOffsetHigh = 1234; inetbuffers.dwOffsetLow = 5678;
SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE); SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED); SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE); rc = InternetReadFileExA(hor, &inetbuffers, IRF_ASYNC | IRF_USE_CONTEXT, 0xcafebabe); if (!rc) { if (GetLastError() == ERROR_IO_PENDING) { trace("InternetReadFileEx -> PENDING\n"); ok(flags & INTERNET_FLAG_ASYNC, "Should not get ERROR_IO_PENDING without INTERNET_FLAG_ASYNC\n"); CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE); WaitForSingleObject(complete_event, INFINITE); CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE); CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED); ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error); } else { trace("InternetReadFileEx -> FAILED %u\n", GetLastError()); break; } } else { trace("InternetReadFileEx -> SUCCEEDED\n"); CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE); if (inetbuffers.dwBufferLength) { CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE); CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED); } else { /* Win98 still sends these when 0 bytes are read, WinXP does not */ CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE); CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED); } }
trace("read %i bytes\n", inetbuffers.dwBufferLength); ((char *)inetbuffers.lpvBuffer)[inetbuffers.dwBufferLength] = '\0';
ok(inetbuffers.dwOffsetHigh == 1234 && inetbuffers.dwOffsetLow == 5678, "InternetReadFileEx sets offsets to 0x%x%08x\n", inetbuffers.dwOffsetHigh, inetbuffers.dwOffsetLow);
HeapFree(GetProcessHeap(), 0, inetbuffers.lpvBuffer);
if (!inetbuffers.dwBufferLength) break;
length += inetbuffers.dwBufferLength; } ok(length > 0, "failed to read any of the document\n"); trace("Finished. Read %d bytes\n", length);
abort: close_async_handle(hi, 2); first_connection_to_test_url = FALSE;}
static void InternetOpenUrlA_test(void){ HINTERNET myhinternet, myhttp; char buffer[0x400]; DWORD size, readbytes, totalbytes=0; BOOL ret;
ret = DeleteUrlCacheEntryA(TEST_URL); ok(ret || GetLastError() == ERROR_FILE_NOT_FOUND, "DeleteUrlCacheEntry returned %x, GetLastError() = %d\n", ret, GetLastError());
myhinternet = InternetOpenA("Winetest",0,NULL,NULL,INTERNET_FLAG_NO_CACHE_WRITE); ok((myhinternet != 0), "InternetOpen failed, error %u\n",GetLastError()); size = 0x400; ret = InternetCanonicalizeUrlA(TEST_URL, buffer, &size,ICU_BROWSER_MODE); ok( ret, "InternetCanonicalizeUrl failed, error %u\n",GetLastError());
SetLastError(0); myhttp = InternetOpenUrlA(myhinternet, TEST_URL, 0, 0, INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE|INTERNET_FLAG_TRANSFER_BINARY,0); if (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) return; /* WinXP returns this when not connected to the net */ ok((myhttp != 0),"InternetOpenUrl failed, error %u\n",GetLastError()); ret = InternetReadFile(myhttp, buffer,0x400,&readbytes); ok( ret, "InternetReadFile failed, error %u\n",GetLastError()); totalbytes += readbytes; while (readbytes && InternetReadFile(myhttp, buffer,0x400,&readbytes)) totalbytes += readbytes; trace("read 0x%08x bytes\n",totalbytes);
InternetCloseHandle(myhttp); InternetCloseHandle(myhinternet);
ret = DeleteUrlCacheEntryA(TEST_URL); ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND, "INTERNET_FLAG_NO_CACHE_WRITE flag doesn't work\n");}
static void HttpSendRequestEx_test(void){ HINTERNET hSession; HINTERNET hConnect; HINTERNET hRequest;
INTERNET_BUFFERSA BufferIn; DWORD dwBytesWritten, dwBytesRead, error; CHAR szBuffer[256]; int i; BOOL ret;
static char szPostData[] = "mode=Test"; static const char szContentType[] = "Content-Type: application/x-www-form-urlencoded";
hSession = InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0); ok( hSession != NULL ,"Unable to open Internet session\n"); hConnect = InternetConnectA(hSession, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); ok( hConnect != NULL, "Unable to connect to http://test.winehq.org\n"); hRequest = HttpOpenRequestA(hConnect, "POST", "/tests/post.php", NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0); if (!hRequest && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) { skip( "Network unreachable, skipping test\n" ); goto done; } ok( hRequest != NULL, "Failed to open request handle err %u\n", GetLastError());
test_request_flags(hRequest, INTERNET_REQFLAG_NO_HEADERS);
BufferIn.dwStructSize = sizeof(BufferIn); BufferIn.Next = (INTERNET_BUFFERSA*)0xdeadcab; BufferIn.lpcszHeader = szContentType; BufferIn.dwHeadersLength = sizeof(szContentType)-1; BufferIn.dwHeadersTotal = sizeof(szContentType)-1; BufferIn.lpvBuffer = szPostData; BufferIn.dwBufferLength = 3; BufferIn.dwBufferTotal = sizeof(szPostData)-1; BufferIn.dwOffsetLow = 0; BufferIn.dwOffsetHigh = 0;
SetLastError(0xdeadbeef); ret = HttpSendRequestExA(hRequest, &BufferIn, NULL, 0 ,0); error = GetLastError(); ok(ret, "HttpSendRequestEx Failed with error %u\n", error); ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %u\n", error);
test_request_flags(hRequest, INTERNET_REQFLAG_NO_HEADERS);
for (i = 3; szPostData[i]; i++) ok(InternetWriteFile(hRequest, &szPostData[i], 1, &dwBytesWritten), "InternetWriteFile failed\n");
test_request_flags(hRequest, INTERNET_REQFLAG_NO_HEADERS);
ok(HttpEndRequestA(hRequest, NULL, 0, 0), "HttpEndRequest Failed\n");
test_request_flags(hRequest, 0);
ok(InternetReadFile(hRequest, szBuffer, 255, &dwBytesRead), "Unable to read response\n"); szBuffer[dwBytesRead] = 0;
ok(dwBytesRead == 13,"Read %u bytes instead of 13\n",dwBytesRead); ok(strncmp(szBuffer,"mode => Test\n",dwBytesRead)==0 || broken(proxy_active()),"Got string %s\n",szBuffer);
ok(InternetCloseHandle(hRequest), "Close request handle failed\n");done: ok(InternetCloseHandle(hConnect), "Close connect handle failed\n"); ok(InternetCloseHandle(hSession), "Close session handle failed\n");}
static void InternetOpenRequest_test(void){ HINTERNET session, connect, request; static const char *types[] = { "*", "", NULL }; static const WCHAR slash[] = {'/', 0}, any[] = {'*', 0}, empty[] = {0}; static const WCHAR *typesW[] = { any, empty, NULL }; BOOL ret;
session = InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); ok(session != NULL ,"Unable to open Internet session\n");
connect = InternetConnectA(session, NULL, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); ok(connect == NULL, "InternetConnectA should have failed\n"); ok(GetLastError() == ERROR_INVALID_PARAMETER, "InternetConnectA with NULL server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
connect = InternetConnectA(session, "", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); ok(connect == NULL, "InternetConnectA should have failed\n"); ok(GetLastError() == ERROR_INVALID_PARAMETER, "InternetConnectA with blank server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
connect = InternetConnectA(session, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); ok(connect != NULL, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, types, INTERNET_FLAG_NO_CACHE_WRITE, 0); if (!request && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) { skip( "Network unreachable, skipping test\n" ); goto done; } ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
ret = HttpSendRequestW(request, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed: %u\n", GetLastError()); ok(InternetCloseHandle(request), "Close request handle failed\n");
request = HttpOpenRequestW(connect, NULL, slash, NULL, NULL, typesW, INTERNET_FLAG_NO_CACHE_WRITE, 0); ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
ret = HttpSendRequestA(request, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed: %u\n", GetLastError()); ok(InternetCloseHandle(request), "Close request handle failed\n");
done: ok(InternetCloseHandle(connect), "Close connect handle failed\n"); ok(InternetCloseHandle(session), "Close session handle failed\n");}
static void test_cache_read(void){ HINTERNET session, connection, req; FILETIME now, tomorrow, yesterday; BYTE content[1000], buf[2000]; char file_path[MAX_PATH]; ULARGE_INTEGER li; HANDLE file; DWORD size; unsigned i; BOOL res;
static const char cache_only_url[] = "http://test.winehq.org/tests/cache-only"; BYTE cache_headers[] = "HTTP/1.1 200 OK\r\n\r\n";
trace("Testing cache read...\n"); reset_events();
for(i = 0; i < sizeof(content); i++) content[i] = '0' + (i%10);
GetSystemTimeAsFileTime(&now); li.u.HighPart = now.dwHighDateTime; li.u.LowPart = now.dwLowDateTime; li.QuadPart += (LONGLONG)10000000 * 3600 * 24; tomorrow.dwHighDateTime = li.u.HighPart; tomorrow.dwLowDateTime = li.u.LowPart; li.QuadPart -= (LONGLONG)10000000 * 3600 * 24 * 2; yesterday.dwHighDateTime = li.u.HighPart; yesterday.dwLowDateTime = li.u.LowPart;
res = CreateUrlCacheEntryA(cache_only_url, sizeof(content), "", file_path, 0); ok(res, "CreateUrlCacheEntryA failed: %u\n", GetLastError());
file = CreateFileA(file_path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
WriteFile(file, content, sizeof(content), &size, NULL); CloseHandle(file);
res = CommitUrlCacheEntryA(cache_only_url, file_path, tomorrow, yesterday, NORMAL_CACHE_ENTRY, cache_headers, sizeof(cache_headers)-1, "", 0); ok(res, "CommitUrlCacheEntryA failed: %u\n", GetLastError());
session = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC); ok(session != NULL,"InternetOpen failed with error %u\n", GetLastError());
pInternetSetStatusCallbackA(session, callback);
SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED); connection = InternetConnectA(session, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef); ok(connection != NULL,"InternetConnect failed with error %u\n", GetLastError()); CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED); req = HttpOpenRequestA(connection, "GET", "/tests/cache-only", NULL, NULL, NULL, 0, 0xdeadbead); ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError()); CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
SET_WINE_ALLOW(INTERNET_STATUS_CONNECTING_TO_SERVER); SET_WINE_ALLOW(INTERNET_STATUS_CONNECTED_TO_SERVER); SET_WINE_ALLOW(INTERNET_STATUS_SENDING_REQUEST); SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_SENT); SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE); SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED); SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE);
res = HttpSendRequestA(req, NULL, -1, NULL, 0); todo_wine ok(res, "HttpSendRequest failed: %u\n", GetLastError());
if(res) { size = 0; res = InternetQueryDataAvailable(req, &size, 0, 0); ok(res, "InternetQueryDataAvailable failed: %u\n", GetLastError()); ok(size == sizeof(content), "size = %u\n", size);
size = sizeof(buf); res = InternetReadFile(req, buf, sizeof(buf), &size); ok(res, "InternetReadFile failed: %u\n", GetLastError()); ok(size == sizeof(content), "size = %u\n", size); ok(!memcmp(content, buf, sizeof(content)), "unexpected content\n"); }
close_async_handle(session, 2);
CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER); CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER); CLEAR_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST); CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_SENT); CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE); CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED); CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
res = DeleteUrlCacheEntryA(cache_only_url); ok(res, "DeleteUrlCacheEntryA failed: %u\n", GetLastError());}
static void test_http_cache(void){ HINTERNET session, connect, request; char file_name[MAX_PATH], url[INTERNET_MAX_URL_LENGTH]; DWORD size, file_size; BYTE buf[100]; HANDLE file; BOOL ret; FILETIME filetime_zero = {0};
static const char cached_content[] = "data read from cache"; static const char *types[] = { "*", "", NULL };
session = InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); ok(session != NULL ,"Unable to open Internet session\n");
connect = InternetConnectA(session, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); ok(connect != NULL, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
request = HttpOpenRequestA(connect, NULL, "/tests/hello.html", NULL, NULL, types, INTERNET_FLAG_NEED_FILE, 0); if (!request && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) { skip( "Network unreachable, skipping test\n" );
ok(InternetCloseHandle(connect), "Close connect handle failed\n"); ok(InternetCloseHandle(session), "Close session handle failed\n");
return; } ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
size = sizeof(url); ret = InternetQueryOptionA(request, INTERNET_OPTION_URL, url, &size); ok(ret, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError()); ok(!strcmp(url, "http://test.winehq.org/tests/hello.html"), "Wrong URL %s\n", url);
size = sizeof(file_name); ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size); ok(!ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n"); ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND, "GetLastError()=%u\n", GetLastError()); ok(!size, "size = %d\n", size);
ret = HttpSendRequestA(request, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
size = sizeof(file_name); ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size); ok(ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
file = CreateFileA(file_name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError()); file_size = GetFileSize(file, NULL); ok(file_size == 106, "file size = %u\n", file_size);
size = sizeof(buf); ret = InternetReadFile(request, buf, sizeof(buf), &size); ok(ret, "InternetReadFile failed: %u\n", GetLastError()); ok(size == 100, "size = %u\n", size);
file_size = GetFileSize(file, NULL); ok(file_size == 106, "file size = %u\n", file_size); CloseHandle(file);
ret = DeleteFileA(file_name); ok(!ret && GetLastError() == ERROR_SHARING_VIOLATION, "Deleting file returned %x(%u)\n", ret, GetLastError());
ok(InternetCloseHandle(request), "Close request handle failed\n");
file = CreateFileA(file_name, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError()); ret = WriteFile(file, cached_content, sizeof(cached_content), &size, NULL); ok(ret && size, "WriteFile failed: %d, %d\n", ret, size); ret = CommitUrlCacheEntryA(url, file_name, filetime_zero, filetime_zero, NORMAL_CACHE_ENTRY, NULL, 0, NULL, 0); ok(ret, "CommitUrlCacheEntry failed: %d\n", GetLastError()); CloseHandle(file);
/* Send the same request, requiring it to be retrieved from the cache */ request = HttpOpenRequestA(connect, "GET", "/tests/hello.html", NULL, NULL, NULL, INTERNET_FLAG_FROM_CACHE, 0);
ret = HttpSendRequestA(request, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed\n");
size = sizeof(buf); ret = InternetReadFile(request, buf, sizeof(buf), &size); ok(ret, "InternetReadFile failed: %u\n", GetLastError()); ok(size == 100, "size = %u\n", size); buf[99] = 0; todo_wine ok(!strcmp((char*)buf, cached_content), "incorrect page data: %s\n", (char*)buf);
ok(InternetCloseHandle(request), "Close request handle failed\n");
DeleteUrlCacheEntryA(url); request = HttpOpenRequestA(connect, "GET", "/tests/hello.html", NULL, NULL, NULL, INTERNET_FLAG_FROM_CACHE, 0); ret = HttpSendRequestA(request, NULL, 0, NULL, 0); todo_wine ok(!ret, "HttpSendRequest succeeded\n"); if(!ret) ok(GetLastError() == ERROR_FILE_NOT_FOUND, "GetLastError() = %d\n", GetLastError()); ok(InternetCloseHandle(request), "Close request handle failed\n");
request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, types, INTERNET_FLAG_NO_CACHE_WRITE, 0); ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
size = sizeof(file_name); ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size); ok(!ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n"); ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND, "GetLastError()=%u\n", GetLastError()); ok(!size, "size = %d\n", size);
ret = HttpSendRequestA(request, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
size = sizeof(file_name); file_name[0] = 0; ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size); if (ret) { file = CreateFileA(file_name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError()); CloseHandle(file); } else { /* < IE8 */ ok(file_name[0] == 0, "Didn't expect a file name\n"); }
ok(InternetCloseHandle(request), "Close request handle failed\n"); ok(InternetCloseHandle(connect), "Close connect handle failed\n"); ok(InternetCloseHandle(session), "Close session handle failed\n");
test_cache_read();}
static void InternetLockRequestFile_test(void){ char file_name[MAX_PATH]; test_request_t req; HANDLE lock, lock2; DWORD size; BOOL ret;
open_simple_request(&req, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, "/tests/hello.html");
size = sizeof(file_name); ret = InternetQueryOptionA(req.request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size); ok(!ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n"); ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND, "GetLastError()=%u\n", GetLastError()); ok(!size, "size = %d\n", size);
lock = NULL; ret = InternetLockRequestFile(req.request, &lock); ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND, "InternetLockRequestFile returned: %x(%u)\n", ret, GetLastError());
ret = HttpSendRequestA(req.request, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
size = sizeof(file_name); ret = InternetQueryOptionA(req.request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size); ok(ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
ret = InternetLockRequestFile(req.request, &lock); ok(ret, "InternetLockRequestFile returned: %x(%u)\n", ret, GetLastError()); ok(lock != NULL, "lock == NULL\n");
ret = InternetLockRequestFile(req.request, &lock2); ok(ret, "InternetLockRequestFile returned: %x(%u)\n", ret, GetLastError()); ok(lock == lock2, "lock != lock2\n");
ret = InternetUnlockRequestFile(lock2); ok(ret, "InternetUnlockRequestFile failed: %u\n", GetLastError());
ret = DeleteFileA(file_name); ok(!ret && GetLastError() == ERROR_SHARING_VIOLATION, "Deleting file returned %x(%u)\n", ret, GetLastError());
ok(InternetCloseHandle(req.request), "Close request handle failed\n");
ret = DeleteFileA(file_name); ok(!ret && GetLastError() == ERROR_SHARING_VIOLATION, "Deleting file returned %x(%u)\n", ret, GetLastError());
ret = InternetUnlockRequestFile(lock); ok(ret, "InternetUnlockRequestFile failed: %u\n", GetLastError());
ret = DeleteFileA(file_name); ok(ret, "Deleting file returned %x(%u)\n", ret, GetLastError());}
static void HttpHeaders_test(void){ HINTERNET hSession; HINTERNET hConnect; HINTERNET hRequest; CHAR buffer[256]; WCHAR wbuffer[256]; DWORD len = 256; DWORD oldlen; DWORD index = 0; BOOL ret;
hSession = InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0); ok( hSession != NULL ,"Unable to open Internet session\n"); hConnect = InternetConnectA(hSession, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); ok( hConnect != NULL, "Unable to connect to http://test.winehq.org\n"); hRequest = HttpOpenRequestA(hConnect, "POST", "/tests/post.php", NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0); if (!hRequest && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) { skip( "Network unreachable, skipping test\n" ); goto done; } ok( hRequest != NULL, "Failed to open request handle\n");
index = 0; len = sizeof(buffer); strcpy(buffer,"Warning"); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Warning hearder reported as Existing\n");
ok(HttpAddRequestHeadersA(hRequest,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD), "Failed to add new header\n");
index = 0; len = sizeof(buffer); strcpy(buffer,"Warning"); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n"); ok(index == 1, "Index was not incremented\n"); ok(strcmp(buffer,"test1")==0, "incorrect string was returned(%s)\n",buffer); ok(len == 5, "Invalid length (exp. 5, got %d)\n", len); ok((len < sizeof(buffer)) && (buffer[len] == 0), "Buffer not NULL-terminated\n"); /* len show only 5 characters but the buffer is NULL-terminated*/ len = sizeof(buffer); strcpy(buffer,"Warning"); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Second Index Should Not Exist\n");
index = 0; len = 5; /* could store the string but not the NULL terminator */ strcpy(buffer,"Warning"); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index) == FALSE,"Query succeeded on a too small buffer\n"); ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError()); ok(index == 0, "Index was incremented\n"); ok(strcmp(buffer,"Warning")==0, "incorrect string was returned(%s)\n",buffer); /* string not touched */ ok(len == 6, "Invalid length (exp. 6, got %d)\n", len); /* unlike success, the length includes the NULL-terminator */
/* a call with NULL will fail but will return the length */ index = 0; len = sizeof(buffer); SetLastError(0xdeadbeef); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS, NULL,&len,&index) == FALSE,"Query worked\n"); ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError()); ok(len > 40, "Invalid length (exp. more than 40, got %d)\n", len); ok(index == 0, "Index was incremented\n");
/* even for a len that is too small */ index = 0; len = 15; SetLastError(0xdeadbeef); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS, NULL,&len,&index) == FALSE,"Query worked\n"); ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError()); ok(len > 40, "Invalid length (exp. more than 40, got %d)\n", len); ok(index == 0, "Index was incremented\n");
index = 0; len = 0; SetLastError(0xdeadbeef); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS, NULL,&len,&index) == FALSE,"Query worked\n"); ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError()); ok(len > 40, "Invalid length (exp. more than 40, got %d)\n", len); ok(index == 0, "Index was incremented\n"); oldlen = len; /* bytes; at least long enough to hold buffer & nul */
/* a working query */ index = 0; len = sizeof(buffer); memset(buffer, 'x', sizeof(buffer)); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n"); ok(len + sizeof(CHAR) <= oldlen, "Result longer than advertised\n"); ok((len < sizeof(buffer)-sizeof(CHAR)) && (buffer[len/sizeof(CHAR)] == 0),"No NUL at end\n"); ok(len == strlen(buffer) * sizeof(CHAR), "Length wrong\n"); /* what's in the middle differs between Wine and Windows so currently we check only the beginning and the end */ ok(strncmp(buffer, "POST /tests/post.php HTTP/1", 25)==0, "Invalid beginning of headers string\n"); ok(strcmp(buffer + strlen(buffer) - 4, "\r\n\r\n")==0, "Invalid end of headers string\n"); ok(index == 0, "Index was incremented\n");
/* Like above two tests, but for W version */
index = 0; len = 0; SetLastError(0xdeadbeef); ok(HttpQueryInfoW(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS, NULL,&len,&index) == FALSE,"Query worked\n"); ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError()); ok(len > 80, "Invalid length (exp. more than 80, got %d)\n", len); ok(index == 0, "Index was incremented\n"); oldlen = len; /* bytes; at least long enough to hold buffer & nul */
/* a working query */ index = 0; len = sizeof(wbuffer); memset(wbuffer, 'x', sizeof(wbuffer)); ok(HttpQueryInfoW(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS, wbuffer,&len,&index),"Unable to query header\n"); ok(len + sizeof(WCHAR) <= oldlen, "Result longer than advertised\n"); ok(len == lstrlenW(wbuffer) * sizeof(WCHAR), "Length wrong\n"); ok((len < sizeof(wbuffer)-sizeof(WCHAR)) && (wbuffer[len/sizeof(WCHAR)] == 0),"No NUL at end\n"); ok(index == 0, "Index was incremented\n");
/* end of W version tests */
/* Without HTTP_QUERY_FLAG_REQUEST_HEADERS */ index = 0; len = sizeof(buffer); memset(buffer, 'x', sizeof(buffer)); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF, buffer,&len,&index) == TRUE,"Query failed\n"); ok(len == 2 || len == 4 /* win10 */, "Expected 2 or 4, got %d\n", len); ok(memcmp(buffer, "\r\n\r\n", len) == 0, "Expected CRLF, got '%s'\n", buffer); ok(index == 0, "Index was incremented\n");
ok(HttpAddRequestHeadersA(hRequest,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD), "Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");
index = 0; len = sizeof(buffer); strcpy(buffer,"Warning"); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n"); ok(index == 1, "Index was not incremented\n"); ok(strcmp(buffer,"test1")==0, "incorrect string was returned(%s)\n",buffer); len = sizeof(buffer); strcpy(buffer,"Warning"); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n"); ok(index == 2, "Index was not incremented\n"); ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer); len = sizeof(buffer); strcpy(buffer,"Warning"); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
ok(HttpAddRequestHeadersA(hRequest,"Warning:test3",-1,HTTP_ADDREQ_FLAG_REPLACE), "Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE\n");
index = 0; len = sizeof(buffer); strcpy(buffer,"Warning"); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n"); ok(index == 1, "Index was not incremented\n"); ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer); len = sizeof(buffer); strcpy(buffer,"Warning"); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n"); ok(index == 2, "Index was not incremented\n"); ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer); len = sizeof(buffer); strcpy(buffer,"Warning"); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
ok(HttpAddRequestHeadersA(hRequest,"Warning:test4",-1,HTTP_ADDREQ_FLAG_ADD_IF_NEW)==0, "HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header\n");
index = 0; len = sizeof(buffer); strcpy(buffer,"Warning"); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n"); ok(index == 1, "Index was not incremented\n"); ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer); len = sizeof(buffer); strcpy(buffer,"Warning"); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n"); ok(index == 2, "Index was not incremented\n"); ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer); len = sizeof(buffer); strcpy(buffer,"Warning"); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
ok(HttpAddRequestHeadersA(hRequest,"Warning:test4",-1, HTTP_ADDREQ_FLAG_COALESCE), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
index = 0; len = sizeof(buffer); strcpy(buffer,"Warning"); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n"); ok(index == 1, "Index was not incremented\n"); ok(strcmp(buffer,"test2, test4")==0, "incorrect string was returned(%s)\n", buffer); len = sizeof(buffer); strcpy(buffer,"Warning"); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n"); ok(index == 2, "Index was not incremented\n"); ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer); len = sizeof(buffer); strcpy(buffer,"Warning"); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
ok(HttpAddRequestHeadersA(hRequest,"Warning:test5",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
index = 0; len = sizeof(buffer); strcpy(buffer,"Warning"); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n"); ok(index == 1, "Index was not incremented\n"); ok(strcmp(buffer,"test2, test4, test5")==0, "incorrect string was returned(%s)\n",buffer); len = sizeof(buffer); strcpy(buffer,"Warning"); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n"); ok(index == 2, "Index was not incremented\n"); ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer); len = sizeof(buffer); strcpy(buffer,"Warning"); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
ok(HttpAddRequestHeadersA(hRequest,"Warning:test6",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
index = 0; len = sizeof(buffer); strcpy(buffer,"Warning"); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n"); ok(index == 1, "Index was not incremented\n"); ok(strcmp(buffer,"test2, test4, test5; test6")==0, "incorrect string was returned(%s)\n",buffer); len = sizeof(buffer); strcpy(buffer,"Warning"); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n"); ok(index == 2, "Index was not incremented\n"); ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer); len = sizeof(buffer); strcpy(buffer,"Warning"); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
ok(HttpAddRequestHeadersA(hRequest,"Warning:test7",-1, HTTP_ADDREQ_FLAG_ADD|HTTP_ADDREQ_FLAG_REPLACE), "HTTP_ADDREQ_FLAG_ADD with HTTP_ADDREQ_FLAG_REPALCE Did not work\n");
index = 0; len = sizeof(buffer); strcpy(buffer,"Warning"); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n"); ok(index == 1, "Index was not incremented\n"); ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer); len = sizeof(buffer); strcpy(buffer,"Warning"); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n"); ok(index == 2, "Index was not incremented\n"); ok(strcmp(buffer,"test7")==0, "incorrect string was returned(%s)\n",buffer); len = sizeof(buffer); strcpy(buffer,"Warning"); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
/* Ensure that blank headers are ignored and don't cause a failure */ ok(HttpAddRequestHeadersA(hRequest,"\r\nBlankTest:value\r\n\r\n",-1, HTTP_ADDREQ_FLAG_ADD_IF_NEW), "Failed to add header with blank entries in list\n");
index = 0; len = sizeof(buffer); strcpy(buffer,"BlankTest"); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n"); ok(index == 1, "Index was not incremented\n"); ok(strcmp(buffer,"value")==0, "incorrect string was returned(%s)\n",buffer);
/* Ensure that malformed header separators are ignored and don't cause a failure */ ok(HttpAddRequestHeadersA(hRequest,"\r\rMalformedTest:value\n\nMalformedTestTwo: value2\rMalformedTestThree: value3\n\n\r\r\n",-1, HTTP_ADDREQ_FLAG_ADD|HTTP_ADDREQ_FLAG_REPLACE), "Failed to add header with malformed entries in list\n");
index = 0; len = sizeof(buffer); strcpy(buffer,"MalformedTest"); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n"); ok(index == 1, "Index was not incremented\n"); ok(strcmp(buffer,"value")==0, "incorrect string was returned(%s)\n",buffer); index = 0; len = sizeof(buffer); strcpy(buffer,"MalformedTestTwo"); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n"); ok(index == 1, "Index was not incremented\n"); ok(strcmp(buffer,"value2")==0, "incorrect string was returned(%s)\n",buffer); index = 0; len = sizeof(buffer); strcpy(buffer,"MalformedTestThree"); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n"); ok(index == 1, "Index was not incremented\n"); ok(strcmp(buffer,"value3")==0, "incorrect string was returned(%s)\n",buffer);
ret = HttpAddRequestHeadersA(hRequest, "Authorization: Basic\r\n", -1, HTTP_ADDREQ_FLAG_ADD); ok(ret, "unable to add header %u\n", GetLastError());
index = 0; buffer[0] = 0; len = sizeof(buffer); ret = HttpQueryInfoA(hRequest, HTTP_QUERY_AUTHORIZATION|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &len, &index); ok(ret, "unable to query header %u\n", GetLastError()); ok(index == 1, "index was not incremented\n"); ok(!strcmp(buffer, "Basic"), "incorrect string was returned (%s)\n", buffer);
ret = HttpAddRequestHeadersA(hRequest, "Authorization:\r\n", -1, HTTP_ADDREQ_FLAG_REPLACE); ok(ret, "unable to remove header %u\n", GetLastError());
index = 0; len = sizeof(buffer); SetLastError(0xdeadbeef); ok(!HttpQueryInfoA(hRequest, HTTP_QUERY_AUTHORIZATION|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &len, &index), "header still present\n"); ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "got %u\n", GetLastError());
ok(InternetCloseHandle(hRequest), "Close request handle failed\n");done: ok(InternetCloseHandle(hConnect), "Close connect handle failed\n"); ok(InternetCloseHandle(hSession), "Close session handle failed\n");}
static const char garbagemsg[] ="Garbage: Header\r\n";
static const char contmsg[] ="HTTP/1.1 100 Continue\r\n";
static const char expandcontmsg[] ="HTTP/1.1 100 Continue\r\n""Server: winecontinue\r\n""Tag: something witty\r\n";
static const char okmsg[] ="HTTP/1.1 200 OK\r\n""Server: winetest\r\n""\r\n";
static const char okmsg201[] ="HTTP/1.1 201 OK\r\n""Server: winetest\r\n""\r\n";
static const char okmsg2[] ="HTTP/1.1 200 OK\r\n""Date: Mon, 01 Dec 2008 13:44:34 GMT\r\n""Server: winetest\r\n""Content-Length: 0\r\n""Set-Cookie: one\r\n""Set-Cookie: two\r\n""\r\n";
static DWORD64 content_length;static const char largemsg[] ="HTTP/1.1 200 OK\r\n""Content-Length: %I64u\r\n""\r\n";
static const char okmsg_cookie_path[] ="HTTP/1.1 200 OK\r\n""Date: Mon, 01 Dec 2008 13:44:34 GMT\r\n""Server: winetest\r\n""Content-Length: 0\r\n""Set-Cookie: subcookie2=data; path=/test_cookie_set_path\r\n""\r\n";
static const char okmsg_cookie[] ="HTTP/1.1 200 OK\r\n""Date: Mon, 01 Dec 2008 13:44:34 GMT\r\n""Server: winetest\r\n""Content-Length: 0\r\n""Set-Cookie: testcookie=testvalue\r\n""\r\n";
static const char notokmsg[] ="HTTP/1.1 400 Bad Request\r\n""Server: winetest\r\n""\r\n";
static const char noauthmsg[] ="HTTP/1.1 401 Unauthorized\r\n""Server: winetest\r\n""Connection: close\r\n""WWW-Authenticate: Basic realm=\"placebo\"\r\n""\r\n";
static const char noauthmsg2[] ="HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed\r\n""HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed""\0d`0|6\n""Server: winetest\r\n";
static const char proxymsg[] ="HTTP/1.1 407 Proxy Authentication Required\r\n""Server: winetest\r\n""Proxy-Connection: close\r\n""Proxy-Authenticate: Basic realm=\"placebo\"\r\n""\r\n";
static const char page1[] ="<HTML>\r\n""<HEAD><TITLE>wininet test page</TITLE></HEAD>\r\n""<BODY>The quick brown fox jumped over the lazy dog<P></BODY>\r\n""</HTML>\r\n\r\n";
static const char ok_with_length[] ="HTTP/1.1 200 OK\r\n""Connection: Keep-Alive\r\n""Content-Length: 18\r\n\r\n""HTTP/1.1 211 OK\r\n\r\n";
static const char ok_with_length2[] ="HTTP/1.1 210 OK\r\n""Connection: Keep-Alive\r\n""Content-Length: 19\r\n\r\n""HTTP/1.1 211 OK\r\n\r\n";
struct server_info { HANDLE hEvent; int port;};
static int test_cache_gzip;static const char *send_buffer;static int server_socket;
static DWORD CALLBACK server_thread(LPVOID param){ struct server_info *si = param; int r, c = -1, i, on, count = 0; SOCKET s; struct sockaddr_in sa; char *buffer; size_t buffer_size; WSADATA wsaData; int last_request = 0; char host_header[22]; char host_header_override[30]; static int test_no_cache = 0;
WSAStartup(MAKEWORD(1,1), &wsaData);
s = socket(AF_INET, SOCK_STREAM, 0); if (s == INVALID_SOCKET) return 1;
on = 1; setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char*)&on, sizeof on);
memset(&sa, 0, sizeof sa); sa.sin_family = AF_INET; sa.sin_port = htons(si->port); sa.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
r = bind(s, (struct sockaddr*) &sa, sizeof sa); if (r<0) return 1;
listen(s, 0);
SetEvent(si->hEvent);
sprintf(host_header, "Host: localhost:%d", si->port); sprintf(host_header_override, "Host: test.local:%d\r\n", si->port); buffer = HeapAlloc(GetProcessHeap(), 0, buffer_size = 1000);
do { if(c == -1) c = accept(s, NULL, NULL);
memset(buffer, 0, buffer_size); for(i=0;; i++) { if(i == buffer_size) buffer = HeapReAlloc(GetProcessHeap(), 0, buffer, buffer_size *= 2);
r = recv(c, buffer+i, 1, 0); if (r != 1) break; if (i<4) continue; if (buffer[i-2] == '\n' && buffer[i] == '\n' && buffer[i-3] == '\r' && buffer[i-1] == '\r') break; } if (strstr(buffer, "GET /test1")) { if (!strstr(buffer, "Content-Length: 0")) { send(c, okmsg, sizeof okmsg-1, 0); send(c, page1, sizeof page1-1, 0); } else send(c, notokmsg, sizeof notokmsg-1, 0); } if (strstr(buffer, "CONNECT ")) { if (!strstr(buffer, "Content-Length: 0")) send(c, notokmsg, sizeof notokmsg-1, 0); else send(c, proxymsg, sizeof proxymsg-1, 0); } if (strstr(buffer, "/test2")) { if (strstr(buffer, "Proxy-Authorization: Basic bWlrZToxMTAx")) { send(c, okmsg, sizeof okmsg-1, 0); send(c, page1, sizeof page1-1, 0); } else send(c, proxymsg, sizeof proxymsg-1, 0); } if (strstr(buffer, "/test3")) { if (strstr(buffer, "Authorization: Basic dXNlcjpwd2Q=")) send(c, okmsg, sizeof okmsg-1, 0); else send(c, noauthmsg, sizeof noauthmsg-1, 0); } if (strstr(buffer, "/test4")) { if (strstr(buffer, "Connection: Close")) send(c, okmsg, sizeof okmsg-1, 0); else send(c, notokmsg, sizeof notokmsg-1, 0); } if (strstr(buffer, "POST /test5") || strstr(buffer, "RPC_IN_DATA /test5") || strstr(buffer, "RPC_OUT_DATA /test5")) { if (strstr(buffer, "Content-Length: 0")) { send(c, okmsg, sizeof okmsg-1, 0); send(c, page1, sizeof page1-1, 0); } else send(c, notokmsg, sizeof notokmsg-1, 0); } if (strstr(buffer, "GET /test6")) { send(c, contmsg, sizeof contmsg-1, 0); send(c, contmsg, sizeof contmsg-1, 0); send(c, okmsg, sizeof okmsg-1, 0); send(c, page1, sizeof page1-1, 0); } if (strstr(buffer, "POST /test7")) { if (strstr(buffer, "Content-Length: 100")) { if (strstr(buffer, "POST /test7b")) recvfrom(c, buffer, buffer_size, 0, NULL, NULL); send(c, okmsg, sizeof okmsg-1, 0); send(c, page1, sizeof page1-1, 0); } else send(c, notokmsg, sizeof notokmsg-1, 0); } if (strstr(buffer, "/test8")) { if (!strstr(buffer, "Connection: Close") && strstr(buffer, "Connection: Keep-Alive") && !strstr(buffer, "Cache-Control: no-cache") && !strstr(buffer, "Pragma: no-cache") && strstr(buffer, host_header)) send(c, okmsg, sizeof okmsg-1, 0); else send(c, notokmsg, sizeof notokmsg-1, 0); } if (strstr(buffer, "/test9")) { if (!strstr(buffer, "Connection: Close") && !strstr(buffer, "Connection: Keep-Alive") && !strstr(buffer, "Cache-Control: no-cache") && !strstr(buffer, "Pragma: no-cache") && strstr(buffer, host_header)) send(c, okmsg, sizeof okmsg-1, 0); else send(c, notokmsg, sizeof notokmsg-1, 0); } if (strstr(buffer, "/testA")) { if (!strstr(buffer, "Connection: Close") && !strstr(buffer, "Connection: Keep-Alive") && (strstr(buffer, "Cache-Control: no-cache") || strstr(buffer, "Pragma: no-cache")) && strstr(buffer, host_header)) send(c, okmsg, sizeof okmsg-1, 0); else send(c, notokmsg, sizeof notokmsg-1, 0); } if (strstr(buffer, "/testC")) { if (strstr(buffer, "cookie=biscuit")) send(c, okmsg, sizeof okmsg-1, 0); else send(c, notokmsg, sizeof notokmsg-1, 0); } if (strstr(buffer, "/testD")) { send(c, okmsg2, sizeof okmsg2-1, 0); } if (strstr(buffer, "/testE")) { send(c, noauthmsg2, sizeof noauthmsg2-1, 0); } if (strstr(buffer, "GET /quit")) { send(c, okmsg, sizeof okmsg-1, 0); send(c, page1, sizeof page1-1, 0); last_request = 1; } if (strstr(buffer, "GET /testF")) { send(c, expandcontmsg, sizeof expandcontmsg-1, 0); send(c, garbagemsg, sizeof garbagemsg-1, 0); send(c, contmsg, sizeof contmsg-1, 0); send(c, garbagemsg, sizeof garbagemsg-1, 0); send(c, okmsg, sizeof okmsg-1, 0); send(c, page1, sizeof page1-1, 0); } if (strstr(buffer, "GET /testG")) { send(c, page1, sizeof page1-1, 0); }
if (strstr(buffer, "GET /testJ")) { if (count == 0) { count++; send(c, ok_with_length, sizeof(ok_with_length)-1, 0); } else { send(c, ok_with_length2, sizeof(ok_with_length2)-1, 0); count = 0; } } if (strstr(buffer, "GET /testH")) { send(c, ok_with_length2, sizeof(ok_with_length2)-1, 0); recvfrom(c, buffer, buffer_size, 0, NULL, NULL); send(c, ok_with_length, sizeof(ok_with_length)-1, 0); }
if (strstr(buffer, "GET /test_no_content")) { static const char nocontentmsg[] = "HTTP/1.1 204 No Content\r\nConnection: close\r\n\r\n"; send(c, nocontentmsg, sizeof(nocontentmsg)-1, 0); } if (strstr(buffer, "GET /test_conn_close")) { static const char conn_close_response[] = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\nsome content"; send(c, conn_close_response, sizeof(conn_close_response)-1, 0); WaitForSingleObject(conn_close_event, INFINITE); trace("closing connection\n"); } if (strstr(buffer, "GET /test_cache_control_no_cache")) { static const char no_cache_response[] = "HTTP/1.1 200 OK\r\nCache-Control: no-cache\r\n\r\nsome content"; if(!test_no_cache++) send(c, no_cache_response, sizeof(no_cache_response)-1, 0); else send(c, okmsg, sizeof(okmsg)-1, 0); } if (strstr(buffer, "GET /test_cache_control_no_store")) { static const char no_cache_response[] = "HTTP/1.1 200 OK\r\nCache-Control: junk, \t No-StOrE\r\n\r\nsome content"; send(c, no_cache_response, sizeof(no_cache_response)-1, 0); } if (strstr(buffer, "GET /test_cache_gzip")) { static const char gzip_response[] = "HTTP/1.1 200 OK\r\nContent-Encoding: gzip\r\nContent-Type: text/html\r\n\r\n" "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\x4b\xaf\xca\x2c\x50\x28" "\x49\x2d\x2e\xe1\x02\x00\x62\x92\xc7\x6c\x0a\x00\x00\x00"; if(!test_cache_gzip++) send(c, gzip_response, sizeof(gzip_response), 0); else send(c, notokmsg, sizeof(notokmsg)-1, 0); } if (strstr(buffer, "HEAD /test_head")) { static const char head_response[] = "HTTP/1.1 200 OK\r\n" "Connection: Keep-Alive\r\n" "Content-Length: 100\r\n" "\r\n";
send(c, head_response, sizeof(head_response), 0); continue; } if (strstr(buffer, "GET /send_from_buffer")) send(c, send_buffer, strlen(send_buffer), 0); if (strstr(buffer, "/test_cache_control_verb")) { if (!memcmp(buffer, "GET ", sizeof("GET ")-1) && !strstr(buffer, "Cache-Control: no-cache\r\n")) send(c, okmsg, sizeof(okmsg)-1, 0); else if (strstr(buffer, "Cache-Control: no-cache\r\n")) send(c, okmsg, sizeof(okmsg)-1, 0); else send(c, notokmsg, sizeof(notokmsg)-1, 0); } if (strstr(buffer, "/test_request_content_length")) { static char msg[] = "HTTP/1.1 200 OK\r\nConnection: Keep-Alive\r\n\r\n"; static int seen_content_length;
if (!seen_content_length) { if (strstr(buffer, "Content-Length: 0")) { seen_content_length = 1; send(c, msg, sizeof msg-1, 0); } else send(c, notokmsg, sizeof notokmsg-1, 0); WaitForSingleObject(complete_event, 5000); } else { if (strstr(buffer, "Content-Length: 0")) send(c, msg, sizeof msg-1, 0); else send(c, notokmsg, sizeof notokmsg-1, 0); WaitForSingleObject(complete_event, 5000); } } if (strstr(buffer, "GET /test_premature_disconnect")) trace("closing connection\n"); if (strstr(buffer, "HEAD /upload.txt")) { if (strstr(buffer, "Authorization: Basic dXNlcjpwd2Q=")) send(c, okmsg, sizeof okmsg-1, 0); else send(c, noauthmsg, sizeof noauthmsg-1, 0); } if (strstr(buffer, "PUT /upload2.txt")) { if (strstr(buffer, "Authorization: Basic dXNlcjpwd2Q=")) send(c, okmsg, sizeof okmsg-1, 0); else send(c, notokmsg, sizeof notokmsg-1, 0); } if (strstr(buffer, "HEAD /upload3.txt")) { if (strstr(buffer, "Authorization: Basic dXNlcjE6cHdkMQ==")) send(c, okmsg, sizeof okmsg-1, 0); else send(c, noauthmsg, sizeof noauthmsg-1, 0); } if (strstr(buffer, "HEAD /upload4.txt")) { if (strstr(buffer, "Authorization: Bearer dXNlcjE6cHdkMQ==")) send(c, okmsg, sizeof okmsg-1, 0); else if (strstr(buffer, "Authorization: Basic dXNlcjpwd2Q=")) send(c, okmsg201, sizeof okmsg-1, 0); else send(c, noauthmsg, sizeof noauthmsg-1, 0); } if (strstr(buffer, "/test_cookie_path1")) { if (strstr(buffer, "subcookie=data")) send(c, okmsg, sizeof okmsg-1, 0); else send(c, notokmsg, sizeof notokmsg-1, 0); } if (strstr(buffer, "/test_cookie_path2")) { if (strstr(buffer, "subcookie2=data")) send(c, okmsg, sizeof okmsg-1, 0); else send(c, notokmsg, sizeof notokmsg-1, 0); } if (strstr(buffer, "/test_cookie_set_path")) { send(c, okmsg_cookie_path, sizeof okmsg_cookie_path-1, 0); } if (strstr(buffer, "/test_cookie_merge")) { if (strstr(buffer, "subcookie=data") && !strstr(buffer, "manual_cookie=test")) send(c, okmsg, sizeof okmsg-1, 0); else send(c, notokmsg, sizeof notokmsg-1, 0); } if (strstr(buffer, "/test_cookie_set_host_override")) { send(c, okmsg_cookie, sizeof okmsg_cookie-1, 0); } if (strstr(buffer, "/test_cookie_check_host_override")) { if (strstr(buffer, "Cookie:") && strstr(buffer, "testcookie=testvalue")) send(c, okmsg, sizeof okmsg-1, 0); else send(c, notokmsg, sizeof notokmsg-1, 0); } if (strstr(buffer, "/test_cookie_check_different_host")) { if (!strstr(buffer, "foo") && strstr(buffer, "cookie=biscuit")) send(c, okmsg, sizeof okmsg-1, 0); else send(c, notokmsg, sizeof notokmsg-1, 0); } if (strstr(buffer, "/test_host_override")) { if (strstr(buffer, host_header_override)) send(c, okmsg, sizeof okmsg-1, 0); else send(c, notokmsg, sizeof notokmsg-1, 0); } if (strstr(buffer, "/async_read")) { const char *page1_mid = page1 + (sizeof page1 - 1)/2; const char *page1_end = page1 + sizeof page1 - 1; send(c, okmsg, sizeof okmsg-1, 0); send(c, page1, page1_mid - page1, 0); WaitForSingleObject(conn_wait_event, INFINITE); send(c, page1_mid, page1_end - page1_mid, 0); } if (strstr(buffer, "/socket")) { server_socket = c; SetEvent(server_req_rec_event); WaitForSingleObject(conn_wait_event, INFINITE); } if (strstr(buffer, "/echo_request")) { send(c, okmsg, sizeof(okmsg)-1, 0); send(c, buffer, strlen(buffer), 0); } if (strstr(buffer, "GET /test_remove_dot_segments")) { send(c, okmsg, sizeof(okmsg)-1, 0); }
if (strstr(buffer, "HEAD /test_large_content")) { char msg[sizeof(largemsg) + 16]; sprintf(msg, largemsg, content_length); send(c, msg, strlen(msg), 0); } if (strstr(buffer, "HEAD /test_auth_host1")) { if (strstr(buffer, "Authorization: Basic dGVzdDE6cGFzcw==")) send(c, okmsg, sizeof okmsg-1, 0); else send(c, noauthmsg, sizeof noauthmsg-1, 0); } if (strstr(buffer, "HEAD /test_auth_host2")) { if (strstr(buffer, "Authorization: Basic dGVzdDE6cGFzczI=")) send(c, okmsg, sizeof okmsg-1, 0); else send(c, noauthmsg, sizeof noauthmsg-1, 0); } shutdown(c, 2); closesocket(c); c = -1; } while (!last_request);
closesocket(s); HeapFree(GetProcessHeap(), 0, buffer);
return 0;}
static void test_basic_request(int port, const char *verb, const char *url){ test_request_t req; DWORD r, count, error; char buffer[0x100];
trace("basic request %s %s\n", verb, url);
open_simple_request(&req, "localhost", port, verb, url);
SetLastError(0xdeadbeef); r = HttpSendRequestA(req.request, NULL, 0, NULL, 0); error = GetLastError(); ok(error == ERROR_SUCCESS || broken(error != ERROR_SUCCESS), "expected ERROR_SUCCESS, got %u\n", error); ok(r, "HttpSendRequest failed: %u\n", GetLastError());
count = 0; memset(buffer, 0, sizeof buffer); SetLastError(0xdeadbeef); r = InternetReadFile(req.request, buffer, sizeof buffer, &count); ok(r, "InternetReadFile failed %u\n", GetLastError()); ok(count == sizeof page1 - 1, "count was wrong\n"); ok(!memcmp(buffer, page1, sizeof page1), "http data wrong, got: %s\n", buffer);
close_request(&req);}
static void test_proxy_indirect(int port){ test_request_t req; DWORD r, sz; char buffer[0x40];
open_simple_request(&req, "localhost", port, NULL, "/test2");
r = HttpSendRequestA(req.request, NULL, 0, NULL, 0); ok(r, "HttpSendRequest failed %u\n", GetLastError());
sz = sizeof buffer; r = HttpQueryInfoA(req.request, HTTP_QUERY_PROXY_AUTHENTICATE, buffer, &sz, NULL); ok(r || GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "HttpQueryInfo failed: %d\n", GetLastError()); if (!r) { skip("missing proxy header, not testing remaining proxy headers\n"); goto out; } ok(!strcmp(buffer, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
test_status_code(req.request, 407); test_request_flags(req.request, 0);
sz = sizeof buffer; r = HttpQueryInfoA(req.request, HTTP_QUERY_STATUS_TEXT, buffer, &sz, NULL); ok(r, "HttpQueryInfo failed\n"); ok(!strcmp(buffer, "Proxy Authentication Required"), "proxy text wrong\n");
sz = sizeof buffer; r = HttpQueryInfoA(req.request, HTTP_QUERY_VERSION, buffer, &sz, NULL); ok(r, "HttpQueryInfo failed\n"); ok(!strcmp(buffer, "HTTP/1.1"), "http version wrong\n");
sz = sizeof buffer; r = HttpQueryInfoA(req.request, HTTP_QUERY_SERVER, buffer, &sz, NULL); ok(r, "HttpQueryInfo failed\n"); ok(!strcmp(buffer, "winetest"), "http server wrong\n");
sz = sizeof buffer; r = HttpQueryInfoA(req.request, HTTP_QUERY_CONTENT_ENCODING, buffer, &sz, NULL); ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "HttpQueryInfo should fail\n"); ok(r == FALSE, "HttpQueryInfo failed\n");
out: close_request(&req);}
static void test_proxy_direct(int port){ HINTERNET hi, hc, hr; DWORD r, sz, error; char buffer[0x40], *url; WCHAR bufferW[0x40]; static const char url_fmt[] = "http://test.winehq.org:%u/test2"; static CHAR username[] = "mike", password[] = "1101", useragent[] = "winetest"; static const WCHAR usernameW[] = {'m','i','k','e',0}, passwordW[] = {'1','1','0','1',0}, useragentW[] = {'w','i','n','e','t','e','s','t',0};
/* specify proxy type without the proxy and bypass */ SetLastError(0xdeadbeef); hi = InternetOpenW(NULL, INTERNET_OPEN_TYPE_PROXY, NULL, NULL, 0); error = GetLastError(); ok(error == ERROR_INVALID_PARAMETER || broken(error == ERROR_SUCCESS) /* WinXPProSP2 */, "got %u\n", error); ok(hi == NULL || broken(!!hi) /* WinXPProSP2 */, "open should have failed\n");
sprintf(buffer, "localhost:%d\n", port); hi = InternetOpenA(NULL, INTERNET_OPEN_TYPE_PROXY, buffer, NULL, 0); ok(hi != NULL, "open failed\n");
/* try connect without authorization */ hc = InternetConnectA(hi, "test.winehq.org", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); ok(hc != NULL, "connect failed\n");
hr = HttpOpenRequestA(hc, NULL, "/test2", NULL, NULL, NULL, 0, 0); ok(hr != NULL, "HttpOpenRequest failed\n");
sz = 0; SetLastError(0xdeadbeef); r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_PASSWORD, NULL, &sz); ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError()); ok(!r, "unexpected success\n"); ok(sz == 1, "got %u\n", sz);
sz = 0; SetLastError(0xdeadbeef); r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, NULL, &sz); ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError()); ok(!r, "unexpected success\n"); ok(sz == 1, "got %u\n", sz);
sz = sizeof(buffer); SetLastError(0xdeadbeef); r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_PASSWORD, buffer, &sz); ok(r, "unexpected failure %u\n", GetLastError()); ok(!sz, "got %u\n", sz);
sz = sizeof(buffer); SetLastError(0xdeadbeef); r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, buffer, &sz); ok(r, "unexpected failure %u\n", GetLastError()); ok(!sz, "got %u\n", sz);
sz = 0; SetLastError(0xdeadbeef); r = InternetQueryOptionA(hr, INTERNET_OPTION_PASSWORD, NULL, &sz); ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError()); ok(!r, "unexpected success\n"); ok(sz == 1, "got %u\n", sz);
sz = 0; SetLastError(0xdeadbeef); r = InternetQueryOptionA(hr, INTERNET_OPTION_USERNAME, NULL, &sz); ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError()); ok(!r, "unexpected success\n"); ok(sz == 1, "got %u\n", sz);
sz = sizeof(buffer); SetLastError(0xdeadbeef); r = InternetQueryOptionA(hr, INTERNET_OPTION_PASSWORD, buffer, &sz); ok(r, "unexpected failure %u\n", GetLastError()); ok(!sz, "got %u\n", sz);
sz = sizeof(buffer); SetLastError(0xdeadbeef); r = InternetQueryOptionA(hr, INTERNET_OPTION_USERNAME, buffer, &sz); ok(r, "unexpected failure %u\n", GetLastError()); ok(!sz, "got %u\n", sz);
sz = 0; SetLastError(0xdeadbeef); r = InternetQueryOptionA(hr, INTERNET_OPTION_URL, NULL, &sz); ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError()); ok(!r, "unexpected success\n"); ok(sz == 34, "got %u\n", sz);
sz = sizeof(buffer); SetLastError(0xdeadbeef); r = InternetQueryOptionA(hr, INTERNET_OPTION_URL, buffer, &sz); ok(r, "unexpected failure %u\n", GetLastError()); ok(sz == 33, "got %u\n", sz);
r = HttpSendRequestW(hr, NULL, 0, NULL, 0); ok(r || broken(!r), "HttpSendRequest failed %u\n", GetLastError()); if (!r) { win_skip("skipping proxy tests on broken wininet\n"); goto done; }
test_status_code(hr, 407);
/* set the user + password then try again */ r = InternetSetOptionA(hi, INTERNET_OPTION_PROXY_USERNAME, username, 4); ok(!r, "unexpected success\n");
r = InternetSetOptionA(hc, INTERNET_OPTION_PROXY_USERNAME, username, 4); ok(r, "failed to set user\n");
r = InternetSetOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, username, 4); ok(r, "failed to set user\n");
buffer[0] = 0; sz = 3; SetLastError(0xdeadbeef); r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, buffer, &sz); ok(!r, "unexpected failure %u\n", GetLastError()); ok(!buffer[0], "got %s\n", buffer); ok(sz == strlen(username) + 1, "got %u\n", sz);
buffer[0] = 0; sz = 0; SetLastError(0xdeadbeef); r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, buffer, &sz); ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError()); ok(!r, "unexpected success\n"); ok(sz == strlen(username) + 1, "got %u\n", sz);
bufferW[0] = 0; sz = 0; SetLastError(0xdeadbeef); r = InternetQueryOptionW(hr, INTERNET_OPTION_PROXY_USERNAME, bufferW, &sz); ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError()); ok(!r, "unexpected success\n"); ok(sz == (lstrlenW(usernameW) + 1) * sizeof(WCHAR), "got %u\n", sz);
buffer[0] = 0; sz = sizeof(buffer); r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, buffer, &sz); ok(r, "failed to get username\n"); ok(!strcmp(buffer, username), "got %s\n", buffer); ok(sz == strlen(username), "got %u\n", sz);
buffer[0] = 0; sz = sizeof(bufferW); r = InternetQueryOptionW(hr, INTERNET_OPTION_PROXY_USERNAME, bufferW, &sz); ok(r, "failed to get username\n"); ok(!lstrcmpW(bufferW, usernameW), "wrong username\n"); ok(sz == lstrlenW(usernameW), "got %u\n", sz);
r = InternetSetOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, username, 1); ok(r, "failed to set user\n");
buffer[0] = 0; sz = sizeof(buffer); r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, buffer, &sz); ok(r, "failed to get username\n"); ok(!strcmp(buffer, username), "got %s\n", buffer); ok(sz == strlen(username), "got %u\n", sz);
r = InternetSetOptionA(hi, INTERNET_OPTION_USER_AGENT, useragent, 1); ok(r, "failed to set useragent\n");
buffer[0] = 0; sz = 0; SetLastError(0xdeadbeef); r = InternetQueryOptionA(hi, INTERNET_OPTION_USER_AGENT, buffer, &sz); ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError()); ok(!r, "unexpected success\n"); ok(sz == strlen(useragent) + 1, "got %u\n", sz);
buffer[0] = 0; sz = sizeof(buffer); r = InternetQueryOptionA(hi, INTERNET_OPTION_USER_AGENT, buffer, &sz); ok(r, "failed to get user agent\n"); ok(!strcmp(buffer, useragent), "got %s\n", buffer); ok(sz == strlen(useragent), "got %u\n", sz);
bufferW[0] = 0; sz = 0; SetLastError(0xdeadbeef); r = InternetQueryOptionW(hi, INTERNET_OPTION_USER_AGENT, bufferW, &sz); ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError()); ok(!r, "unexpected success\n"); ok(sz == (lstrlenW(useragentW) + 1) * sizeof(WCHAR), "got %u\n", sz);
bufferW[0] = 0; sz = sizeof(bufferW); r = InternetQueryOptionW(hi, INTERNET_OPTION_USER_AGENT, bufferW, &sz); ok(r, "failed to get user agent\n"); ok(!lstrcmpW(bufferW, useragentW), "wrong user agent\n"); ok(sz == lstrlenW(useragentW), "got %u\n", sz);
r = InternetSetOptionA(hr, INTERNET_OPTION_USERNAME, username, 1); ok(r, "failed to set user\n");
buffer[0] = 0; sz = 0; SetLastError(0xdeadbeef); r = InternetQueryOptionA(hr, INTERNET_OPTION_USERNAME, buffer, &sz); ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError()); ok(!r, "unexpected success\n"); ok(sz == strlen(username) + 1, "got %u\n", sz);
buffer[0] = 0; sz = sizeof(buffer); r = InternetQueryOptionA(hr, INTERNET_OPTION_USERNAME, buffer, &sz); ok(r, "failed to get user\n"); ok(!strcmp(buffer, username), "got %s\n", buffer); ok(sz == strlen(username), "got %u\n", sz);
bufferW[0] = 0; sz = 0; SetLastError(0xdeadbeef); r = InternetQueryOptionW(hr, INTERNET_OPTION_USERNAME, bufferW, &sz); ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError()); ok(!r, "unexpected success\n"); ok(sz == (lstrlenW(usernameW) + 1) * sizeof(WCHAR), "got %u\n", sz);
bufferW[0] = 0; sz = sizeof(bufferW); r = InternetQueryOptionW(hr, INTERNET_OPTION_USERNAME, bufferW, &sz); ok(r, "failed to get user\n"); ok(!lstrcmpW(bufferW, usernameW), "wrong user\n"); ok(sz == lstrlenW(usernameW), "got %u\n", sz);
r = InternetSetOptionA(hr, INTERNET_OPTION_PASSWORD, password, 1); ok(r, "failed to set password\n");
buffer[0] = 0; sz = 0; SetLastError(0xdeadbeef); r = InternetQueryOptionA(hr, INTERNET_OPTION_PASSWORD, buffer, &sz); ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError()); ok(!r, "unexpected success\n"); ok(sz == strlen(password) + 1, "got %u\n", sz);
buffer[0] = 0; sz = sizeof(buffer); r = InternetQueryOptionA(hr, INTERNET_OPTION_PASSWORD, buffer, &sz); ok(r, "failed to get password\n"); ok(!strcmp(buffer, password), "got %s\n", buffer); ok(sz == strlen(password), "got %u\n", sz);
bufferW[0] = 0; sz = 0; SetLastError(0xdeadbeef); r = InternetQueryOptionW(hr, INTERNET_OPTION_PASSWORD, bufferW, &sz); ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError()); ok(!r, "unexpected success\n"); ok(sz == (lstrlenW(passwordW) + 1) * sizeof(WCHAR), "got %u\n", sz);
bufferW[0] = 0; sz = sizeof(bufferW); r = InternetQueryOptionW(hr, INTERNET_OPTION_PASSWORD, bufferW, &sz); ok(r, "failed to get password\n"); ok(!lstrcmpW(bufferW, passwordW), "wrong password\n"); ok(sz == lstrlenW(passwordW), "got %u\n", sz);
url = HeapAlloc(GetProcessHeap(), 0, strlen(url_fmt) + 11); sprintf(url, url_fmt, port); buffer[0] = 0; sz = 0; SetLastError(0xdeadbeef); r = InternetQueryOptionA(hr, INTERNET_OPTION_URL, buffer, &sz); ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError()); ok(!r, "unexpected success\n"); ok(sz == strlen(url) + 1, "got %u\n", sz);
buffer[0] = 0; sz = sizeof(buffer); r = InternetQueryOptionA(hr, INTERNET_OPTION_URL, buffer, &sz); ok(r, "failed to get url\n"); ok(!strcmp(buffer, url), "got %s\n", buffer); ok(sz == strlen(url), "got %u\n", sz);
bufferW[0] = 0; sz = 0; SetLastError(0xdeadbeef); r = InternetQueryOptionW(hr, INTERNET_OPTION_URL, bufferW, &sz); ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError()); ok(!r, "unexpected success\n"); ok(sz == (strlen(url) + 1) * sizeof(WCHAR), "got %u\n", sz);
bufferW[0] = 0; sz = sizeof(bufferW); r = InternetQueryOptionW(hr, INTERNET_OPTION_URL, bufferW, &sz); ok(r, "failed to get url\n"); ok(!strcmp_wa(bufferW, url), "wrong url\n"); ok(sz == strlen(url), "got %u\n", sz); HeapFree(GetProcessHeap(), 0, url);
r = InternetSetOptionA(hr, INTERNET_OPTION_PROXY_PASSWORD, password, 4); ok(r, "failed to set password\n");
buffer[0] = 0; sz = 0; SetLastError(0xdeadbeef); r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_PASSWORD, buffer, &sz); ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError()); ok(!r, "unexpected success\n"); ok(sz == strlen(password) + 1, "got %u\n", sz);
buffer[0] = 0; sz = sizeof(buffer); r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_PASSWORD, buffer, &sz); ok(r, "failed to get password\n"); ok(!strcmp(buffer, password), "got %s\n", buffer); ok(sz == strlen(password), "got %u\n", sz);
bufferW[0] = 0; sz = 0; SetLastError(0xdeadbeef); r = InternetQueryOptionW(hr, INTERNET_OPTION_PROXY_PASSWORD, bufferW, &sz); ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError()); ok(!r, "unexpected success\n"); ok(sz == (lstrlenW(passwordW) + 1) * sizeof(WCHAR), "got %u\n", sz);
bufferW[0] = 0; sz = sizeof(bufferW); r = InternetQueryOptionW(hr, INTERNET_OPTION_PROXY_PASSWORD, bufferW, &sz); ok(r, "failed to get password\n"); ok(!lstrcmpW(bufferW, passwordW), "wrong password\n"); ok(sz == lstrlenW(passwordW), "got %u\n", sz);
r = HttpSendRequestW(hr, NULL, 0, NULL, 0); if (!r) { win_skip("skipping proxy tests on broken wininet\n"); goto done; } ok(r, "HttpSendRequest failed %u\n", GetLastError()); sz = sizeof buffer; r = HttpQueryInfoA(hr, HTTP_QUERY_STATUS_CODE, buffer, &sz, NULL); ok(r, "HttpQueryInfo failed\n"); ok(!strcmp(buffer, "200"), "proxy code wrong\n");
InternetCloseHandle(hr); InternetCloseHandle(hc); InternetCloseHandle(hi);
sprintf(buffer, "localhost:%d\n", port); hi = InternetOpenA("winetest", INTERNET_OPEN_TYPE_PROXY, buffer, NULL, 0); ok(hi != NULL, "InternetOpen failed\n");
hc = InternetConnectA(hi, "test.winehq.org", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); ok(hc != NULL, "InternetConnect failed\n");
hr = HttpOpenRequestA(hc, "POST", "/test2", NULL, NULL, NULL, INTERNET_FLAG_SECURE, 0); ok(hr != NULL, "HttpOpenRequest failed\n");
r = HttpSendRequestA(hr, NULL, 0, (char *)"data", sizeof("data")); ok(r, "HttpSendRequest failed %u\n", GetLastError());
test_status_code(hr, 407);
done: InternetCloseHandle(hr); InternetCloseHandle(hc); InternetCloseHandle(hi);}
static void test_header_handling_order(int port){ static const char authorization[] = "Authorization: Basic dXNlcjpwd2Q="; static const char connection[] = "Connection: Close"; static const char *types[2] = { "*", NULL }; char data[32]; HINTERNET session, connect, request; DWORD size, status, data_len; BOOL ret;
session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); ok(session != NULL, "InternetOpen failed\n");
connect = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); ok(connect != NULL, "InternetConnect failed\n");
request = HttpOpenRequestA(connect, NULL, "/test3", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION, 0); ok(request != NULL, "HttpOpenRequest failed\n");
ret = HttpAddRequestHeadersA(request, authorization, ~0u, HTTP_ADDREQ_FLAG_ADD); ok(ret, "HttpAddRequestHeaders failed\n");
ret = HttpSendRequestA(request, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed\n");
test_status_code(request, 200); test_request_flags(request, 0);
InternetCloseHandle(request);
request = HttpOpenRequestA(connect, NULL, "/test4", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION, 0); ok(request != NULL, "HttpOpenRequest failed\n");
ret = HttpSendRequestA(request, connection, ~0u, NULL, 0); ok(ret, "HttpSendRequest failed\n");
status = 0; size = sizeof(status); ret = HttpQueryInfoA( request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL ); ok(ret, "HttpQueryInfo failed\n"); ok(status == 200 || status == 400 /* IE6 */, "got status %u, expected 200 or 400\n", status);
InternetCloseHandle(request); InternetCloseHandle(connect);
connect = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); ok(connect != NULL, "InternetConnect failed\n");
request = HttpOpenRequestA(connect, "POST", "/test7", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION, 0); ok(request != NULL, "HttpOpenRequest failed\n");
ret = HttpAddRequestHeadersA(request, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW); ok(ret, "HttpAddRequestHeaders failed\n");
ret = HttpSendRequestA(request, connection, ~0u, NULL, 0); ok(ret, "HttpSendRequest failed\n");
status = 0; size = sizeof(status); ret = HttpQueryInfoA( request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL ); ok(ret, "HttpQueryInfo failed\n"); ok(status == 200, "got status %u, expected 200\n", status);
InternetCloseHandle(request); InternetCloseHandle(connect);
connect = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); ok(connect != NULL, "InternetConnect failed\n");
request = HttpOpenRequestA(connect, "POST", "/test7b", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION, 0); ok(request != NULL, "HttpOpenRequest failed\n");
ret = HttpAddRequestHeadersA(request, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW); ok(ret, "HttpAddRequestHeaders failed\n");
data_len = sizeof(data); memset(data, 'a', sizeof(data)); ret = HttpSendRequestA(request, NULL, 0, data, data_len); ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
status = 0; size = sizeof(status); ret = HttpQueryInfoA( request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL ); ok(ret, "HttpQueryInfo failed\n"); ok(status == 200, "got status %u, expected 200\n", status);
InternetCloseHandle(request); InternetCloseHandle(connect); InternetCloseHandle(session);}
static void test_connection_header(int port){ HINTERNET ses, con, req; BOOL ret;
ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); ok(ses != NULL, "InternetOpen failed\n");
con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); ok(con != NULL, "InternetConnect failed\n");
req = HttpOpenRequestA(con, NULL, "/test8", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0); ok(req != NULL, "HttpOpenRequest failed\n");
ret = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed\n");
test_status_code(req, 200);
InternetCloseHandle(req);
req = HttpOpenRequestA(con, NULL, "/test9", NULL, NULL, NULL, 0, 0); ok(req != NULL, "HttpOpenRequest failed\n");
ret = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed\n");
test_status_code(req, 200);
InternetCloseHandle(req);
req = HttpOpenRequestA(con, NULL, "/test9", NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0); ok(req != NULL, "HttpOpenRequest failed\n");
ret = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed\n");
test_status_code(req, 200);
InternetCloseHandle(req);
req = HttpOpenRequestA(con, "POST", "/testA", NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0); ok(req != NULL, "HttpOpenRequest failed\n");
ret = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed\n");
test_status_code(req, 200);
InternetCloseHandle(req); InternetCloseHandle(con); InternetCloseHandle(ses);}
static void test_header_override(int port){ char buffer[128], host_header_override[30], full_url[128]; HINTERNET ses, con, req; DWORD size, count, err; BOOL ret;
sprintf(host_header_override, "Host: test.local:%d\r\n", port); sprintf(full_url, "http://localhost:%d/test_host_override", port);
ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); ok(ses != NULL, "InternetOpen failed\n");
con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); ok(con != NULL, "InternetConnect failed\n");
req = HttpOpenRequestA(con, NULL, "/test_host_override", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0); ok(req != NULL, "HttpOpenRequest failed\n");
size = sizeof(buffer) - 1; count = 0; memset(buffer, 0, sizeof(buffer)); ret = HttpQueryInfoA(req, HTTP_QUERY_HOST | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, &count); err = GetLastError(); ok(!ret, "HttpQueryInfo succeeded\n"); ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "Expected error ERROR_HTTP_HEADER_NOT_FOUND, got %d\n", err);
test_request_url(req, full_url);
ret = HttpAddRequestHeadersA(req, host_header_override, ~0u, HTTP_ADDREQ_FLAG_COALESCE); ok(ret, "HttpAddRequestHeaders failed\n");
size = sizeof(buffer) - 1; count = 0; memset(buffer, 0, sizeof(buffer)); ret = HttpQueryInfoA(req, HTTP_QUERY_HOST | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, &count); ok(ret, "HttpQueryInfo failed\n");
test_request_url(req, full_url);
ret = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed\n");
test_status_code(req, 200);
InternetCloseHandle(req); req = HttpOpenRequestA(con, NULL, "/test_host_override", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0); ok(req != NULL, "HttpOpenRequest failed\n");
ret = HttpAddRequestHeadersA(req, host_header_override, ~0u, HTTP_ADDREQ_FLAG_COALESCE); ok(ret, "HttpAddRequestHeaders failed\n");
ret = HttpAddRequestHeadersA(req, host_header_override, ~0u, HTTP_ADDREQ_FLAG_COALESCE); ok(ret, "HttpAddRequestHeaders failed\n");
ret = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed\n");
test_status_code(req, 400);
InternetCloseHandle(req); req = HttpOpenRequestA(con, NULL, "/test_host_override", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0); ok(req != NULL, "HttpOpenRequest failed\n");
ret = HttpAddRequestHeadersA(req, host_header_override, ~0u, HTTP_ADDREQ_FLAG_ADD); ok(ret, "HttpAddRequestHeaders failed\n");
ret = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed\n");
test_status_code(req, 200);
InternetCloseHandle(req); req = HttpOpenRequestA(con, NULL, "/test_host_override", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0); ok(req != NULL, "HttpOpenRequest failed\n");
ret = HttpAddRequestHeadersA(req, host_header_override, ~0u, HTTP_ADDREQ_FLAG_REPLACE); if(ret) { /* win10 returns success */ trace("replacing host header is supported.\n");
ret = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed\n");
test_status_code(req, 200); }else { trace("replacing host header is not supported.\n");
err = GetLastError(); ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "Expected error ERROR_HTTP_HEADER_NOT_FOUND, got %d\n", err);
ret = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed\n");
test_status_code(req, 400); }
InternetCloseHandle(req); InternetSetCookieA("http://localhost", "cookie", "biscuit"); req = HttpOpenRequestA(con, NULL, "/testC", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0); ok(req != NULL, "HttpOpenRequest failed\n");
ret = HttpAddRequestHeadersA(req, host_header_override, ~0u, HTTP_ADDREQ_FLAG_ADD); ok(ret, "HttpAddRequestHeaders failed\n");
ret = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed\n");
test_status_code(req, 200);
InternetCloseHandle(req); req = HttpOpenRequestA(con, NULL, "/test_cookie_set_host_override", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0); ok(req != NULL, "HttpOpenRequest failed\n");
ret = HttpAddRequestHeadersA(req, host_header_override, ~0u, HTTP_ADDREQ_FLAG_ADD); ok(ret, "HttpAddRequestHeaders failed\n");
ret = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed\n");
test_status_code(req, 200);
InternetCloseHandle(req); req = HttpOpenRequestA(con, NULL, "/test_cookie_check_host_override", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0); ok(req != NULL, "HttpOpenRequest failed\n");
ret = HttpAddRequestHeadersA(req, host_header_override, ~0u, HTTP_ADDREQ_FLAG_ADD); ok(ret, "HttpAddRequestHeaders failed\n");
ret = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed\n");
test_status_code(req, 200);
InternetCloseHandle(req); req = HttpOpenRequestA(con, NULL, "/test_cookie_check_host_override", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0); ok(req != NULL, "HttpOpenRequest failed\n");
ret = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed\n");
test_status_code(req, 200);
InternetCloseHandle(req); InternetSetCookieA("http://test.local", "foo", "bar"); req = HttpOpenRequestA(con, NULL, "/test_cookie_check_different_host", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0); ok(req != NULL, "HttpOpenRequest failed\n");
ret = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed\n");
test_status_code(req, 200);
InternetCloseHandle(req); req = HttpOpenRequestA(con, NULL, "/test_cookie_check_different_host", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0); ok(req != NULL, "HttpOpenRequest failed\n");
ret = HttpAddRequestHeadersA(req, host_header_override, ~0u, HTTP_ADDREQ_FLAG_ADD); ok(ret, "HttpAddRequestHeaders failed\n");
ret = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed\n");
test_status_code(req, 200);
InternetCloseHandle(req); InternetCloseHandle(con); InternetCloseHandle(ses);
ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); ok(ses != NULL, "InternetOpenA failed\n");
con = InternetConnectA(ses, "localhost", port, "test1", "pass", INTERNET_SERVICE_HTTP, 0, 0); ok(con != NULL, "InternetConnectA failed %u\n", GetLastError());
req = HttpOpenRequestA( con, "HEAD", "/test_auth_host1", NULL, NULL, NULL, 0, 0); ok(req != NULL, "HttpOpenRequestA failed %u\n", GetLastError());
ret = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(ret, "HttpSendRequestA failed %u\n", GetLastError());
test_status_code(req, 200);
InternetCloseHandle(req); InternetCloseHandle(con); InternetCloseHandle(ses);
ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); ok(ses != NULL, "InternetOpenA failed\n");
con = InternetConnectA( ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); ok(con != NULL, "InternetConnectA failed %u\n", GetLastError());
req = HttpOpenRequestA(con, "HEAD", "/test_auth_host1", NULL, NULL, NULL, 0, 0); ok(req != NULL, "HttpOpenRequestA failed %u\n", GetLastError());
ret = HttpAddRequestHeadersA(req, host_header_override, ~0u, HTTP_ADDREQ_FLAG_ADD); ok(ret, "HttpAddRequestHeaders failed\n");
ret = HttpSendRequestA( req, NULL, 0, NULL, 0 ); ok( ret, "HttpSendRequestA failed %u\n", GetLastError() );
test_status_code(req, 200);
InternetCloseHandle(req); InternetCloseHandle(con); InternetCloseHandle(ses);
ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); ok(ses != NULL, "InternetOpenA failed\n");
con = InternetConnectA(ses, "localhost", port, "test1", "pass2", INTERNET_SERVICE_HTTP, 0, 0); ok(con != NULL, "InternetConnectA failed %u\n", GetLastError());
req = HttpOpenRequestA(con, "HEAD", "/test_auth_host2", NULL, NULL, NULL, 0, 0); ok(req != NULL, "HttpOpenRequestA failed %u\n", GetLastError());
ret = HttpAddRequestHeadersA(req, host_header_override, ~0u, HTTP_ADDREQ_FLAG_ADD); ok(ret, "HttpAddRequestHeaders failed\n");
ret = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(ret, "HttpSendRequestA failed %u\n", GetLastError());
test_status_code(req, 200);
InternetCloseHandle(req); InternetCloseHandle(con); InternetCloseHandle(ses);
ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); ok(ses != NULL, "InternetOpenA failed\n");
con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); ok(con != NULL, "InternetConnectA failed %u\n", GetLastError());
req = HttpOpenRequestA(con, "HEAD", "/test_auth_host2", NULL, NULL, NULL, 0, 0); ok(req != NULL, "HttpOpenRequestA failed %u\n", GetLastError());
ret = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(ret, "HttpSendRequestA failed %u\n", GetLastError());
test_status_code(req, 200);
InternetCloseHandle(req); InternetCloseHandle(con); InternetCloseHandle(ses);}
static void test_connection_closing(int port){ HINTERNET session, connection, req; DWORD res;
reset_events();
session = InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_ASYNC); ok(session != NULL,"InternetOpen failed with error %u\n", GetLastError());
pInternetSetStatusCallbackA(session, callback);
SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED); connection = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef); ok(connection != NULL,"InternetConnect failed with error %u\n", GetLastError()); CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED); req = HttpOpenRequestA(connection, "GET", "/testJ", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0xdeadbeaf); ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError()); CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT); SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY); SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER); SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER); SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST); SET_EXPECT(INTERNET_STATUS_REQUEST_SENT); SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE); SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED); SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION); SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED); SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
res = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(!res && (GetLastError() == ERROR_IO_PENDING), "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n"); WaitForSingleObject(complete_event, INFINITE); ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT); CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY); CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER); CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER); CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST); CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT); CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE); CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED); CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION); CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED); CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
test_status_code(req, 200);
SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT); SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY); SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER); SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER); SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST); SET_EXPECT(INTERNET_STATUS_REQUEST_SENT); SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE); SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED); SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
res = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(!res && (GetLastError() == ERROR_IO_PENDING), "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n"); WaitForSingleObject(complete_event, INFINITE); ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT); CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY); CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER); CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER); CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST); CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT); CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE); CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED); CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
test_status_code(req, 210);
SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT); SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY); SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER); SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER); SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST); SET_EXPECT(INTERNET_STATUS_REQUEST_SENT); SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE); SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED); SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION); SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED); SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
res = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(!res && (GetLastError() == ERROR_IO_PENDING), "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n"); WaitForSingleObject(complete_event, INFINITE); ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT); CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY); CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER); CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER); CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST); CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT); CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE); CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED); CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION); CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED); CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
test_status_code(req, 200);
SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION); SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED);
close_async_handle(session, 2);}
static void test_successive_HttpSendRequest(int port){ HINTERNET session, connection, req; DWORD res;
reset_events();
session = InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_ASYNC); ok(session != NULL,"InternetOpen failed with error %u\n", GetLastError());
pInternetSetStatusCallbackA(session, callback);
SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED); connection = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef); ok(connection != NULL,"InternetConnect failed with error %u\n", GetLastError()); CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED); req = HttpOpenRequestA(connection, "GET", "/testH", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0xdeadbeaf); ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError()); CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT); SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY); SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER); SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER); SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST); SET_EXPECT(INTERNET_STATUS_REQUEST_SENT); SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE); SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED); SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
res = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(!res && (GetLastError() == ERROR_IO_PENDING), "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n"); WaitForSingleObject(complete_event, INFINITE); ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT); CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY); CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER); CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER); CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST); CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT); CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE); CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED); CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
test_status_code(req, 210);
SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT); SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY); SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST); SET_EXPECT(INTERNET_STATUS_REQUEST_SENT); SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE); SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED); SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION); SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED); SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
res = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(!res && (GetLastError() == ERROR_IO_PENDING), "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n"); WaitForSingleObject(complete_event, INFINITE); ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT); CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY); CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST); CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT); CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE); CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED); CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION); CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED); CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
test_status_code(req, 200);
SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION); SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED);
close_async_handle(session, 2);}
static void test_no_content(int port){ HINTERNET session, connection, req; DWORD res;
trace("Testing 204 no content response...\n");
reset_events();
session = InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_ASYNC); ok(session != NULL,"InternetOpen failed with error %u\n", GetLastError());
pInternetSetStatusCallbackA(session, callback);
SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED); connection = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef); ok(connection != NULL,"InternetConnect failed with error %u\n", GetLastError()); CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED); req = HttpOpenRequestA(connection, "GET", "/test_no_content", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE, 0xdeadbead); ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError()); CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT); SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER); SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER); SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST); SET_EXPECT(INTERNET_STATUS_REQUEST_SENT); SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE); SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED); SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION); SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED); SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
res = HttpSendRequestA(req, NULL, -1, NULL, 0); ok(!res && (GetLastError() == ERROR_IO_PENDING), "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n"); WaitForSingleObject(complete_event, INFINITE); ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT); CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER); CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER); CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST); CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT); CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE); CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED); CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
close_async_handle(session, 2);
/* * The connection should be closed before closing handle. This is true for most * wininet versions (including Wine), but some old win2k versions fail to do that. */ CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION); CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);}
static void test_conn_close(int port){ HINTERNET session, connection, req; DWORD res, avail, size; BYTE buf[1024];
trace("Testing connection close connection...\n");
reset_events();
session = InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_ASYNC); ok(session != NULL,"InternetOpen failed with error %u\n", GetLastError());
pInternetSetStatusCallbackA(session, callback);
SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED); connection = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef); ok(connection != NULL,"InternetConnect failed with error %u\n", GetLastError()); CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED); req = HttpOpenRequestA(connection, "GET", "/test_conn_close", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE, 0xdeadbead); ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError()); CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT); SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER); SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER); SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST); SET_EXPECT(INTERNET_STATUS_REQUEST_SENT); SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE); SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED); SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
res = HttpSendRequestA(req, NULL, -1, NULL, 0); ok(!res && (GetLastError() == ERROR_IO_PENDING), "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n"); WaitForSingleObject(complete_event, INFINITE); ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT); CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER); CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER); CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST); CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT); CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE); CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED); CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
avail = 0; res = InternetQueryDataAvailable(req, &avail, 0, 0); ok(res, "InternetQueryDataAvailable failed: %u\n", GetLastError()); ok(avail != 0, "avail = 0\n");
size = 0; res = InternetReadFile(req, buf, avail, &size); ok(res, "InternetReadFile failed: %u\n", GetLastError());
/* IE11 calls those in InternetQueryDataAvailable call. */ SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE); SET_OPTIONAL(INTERNET_STATUS_RESPONSE_RECEIVED);
res = InternetQueryDataAvailable(req, &avail, 0, 0); ok(!res && (GetLastError() == ERROR_IO_PENDING), "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n"); ok(!avail, "avail = %u, expected 0\n", avail);
CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION); SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED); SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE); SetEvent(conn_close_event); WaitForSingleObject(complete_event, INFINITE); ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error); CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED); CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION); CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED); CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
close_async_handle(session, 2);}
static void test_no_cache(int port){ static const char cache_control_no_cache[] = "/test_cache_control_no_cache"; static const char cache_control_no_store[] = "/test_cache_control_no_store"; static const char cache_url_fmt[] = "http://localhost:%d%s";
char cache_url[256], buf[256]; HINTERNET ses, con, req; DWORD read, size; BOOL ret;
trace("Testing no-cache header\n");
ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); ok(ses != NULL,"InternetOpen failed with error %u\n", GetLastError());
con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); ok(con != NULL, "InternetConnect failed with error %u\n", GetLastError());
req = HttpOpenRequestA(con, NULL, cache_control_no_cache, NULL, NULL, NULL, 0, 0); ok(req != NULL, "HttpOpenRequest failed\n");
sprintf(cache_url, cache_url_fmt, port, cache_control_no_cache); DeleteUrlCacheEntryA(cache_url);
ret = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed with error %u\n", GetLastError()); size = 0; while(InternetReadFile(req, buf, sizeof(buf), &read) && read) size += read; ok(size == 12, "read %d bytes of data\n", size); InternetCloseHandle(req);
req = HttpOpenRequestA(con, NULL, cache_control_no_cache, NULL, NULL, NULL, 0, 0); ok(req != NULL, "HttpOpenRequest failed\n");
ret = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed with error %u\n", GetLastError()); size = 0; while(InternetReadFile(req, buf, sizeof(buf), &read) && read) size += read; ok(size == 0, "read %d bytes of data\n", size); InternetCloseHandle(req); DeleteUrlCacheEntryA(cache_url);
req = HttpOpenRequestA(con, NULL, cache_control_no_store, NULL, NULL, NULL, 0, 0); ok(req != NULL, "HttpOpenRequest failed\n");
sprintf(cache_url, cache_url_fmt, port, cache_control_no_store); DeleteUrlCacheEntryA(cache_url);
ret = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed with error %u\n", GetLastError()); size = 0; while(InternetReadFile(req, buf, sizeof(buf), &read) && read) size += read; ok(size == 12, "read %d bytes of data\n", size); InternetCloseHandle(req);
ret = DeleteUrlCacheEntryA(cache_url); ok(!ret && GetLastError()==ERROR_FILE_NOT_FOUND, "cache entry should not exist\n");
InternetCloseHandle(con); InternetCloseHandle(ses);}
static void test_cache_read_gzipped(int port){ static const char cache_url_fmt[] = "http://localhost:%d%s"; static const char get_gzip[] = "/test_cache_gzip"; static const char content[] = "gzip test\n"; static const char text_html[] = "text/html"; static const char raw_header[] = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
HINTERNET ses, con, req; DWORD read, size; char cache_url[256], buf[256]; BOOL ret;
trace("Testing reading compressed content from cache\n");
ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); ok(ses != NULL,"InternetOpen failed with error %u\n", GetLastError());
con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); ok(con != NULL, "InternetConnect failed with error %u\n", GetLastError());
req = HttpOpenRequestA(con, NULL, get_gzip, NULL, NULL, NULL, 0, 0); ok(req != NULL, "HttpOpenRequest failed\n");
ret = TRUE; ret = InternetSetOptionA(req, INTERNET_OPTION_HTTP_DECODING, &ret, sizeof(ret)); if(!ret && GetLastError()==ERROR_INTERNET_INVALID_OPTION) { win_skip("INTERNET_OPTION_HTTP_DECODING not supported\n"); InternetCloseHandle(req); InternetCloseHandle(con); InternetCloseHandle(ses); return; } ok(ret, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
ret = HttpSendRequestA(req, "Accept-Encoding: gzip", -1, NULL, 0); ok(ret, "HttpSendRequest failed with error %u\n", GetLastError()); size = 0; while(InternetReadFile(req, buf+size, sizeof(buf)-size, &read) && read) size += read; ok(size == 10, "read %d bytes of data\n", size); buf[size] = 0; ok(!strncmp(buf, content, size), "incorrect page content: %s\n", buf);
size = sizeof(buf)-1; ret = HttpQueryInfoA(req, HTTP_QUERY_CONTENT_TYPE, buf, &size, 0); ok(ret, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError()); buf[size] = 0; ok(!strncmp(text_html, buf, size), "buf = %s\n", buf);
size = sizeof(buf)-1; ret = HttpQueryInfoA(req, HTTP_QUERY_RAW_HEADERS_CRLF, buf, &size, 0); ok(ret, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError()); buf[size] = 0; ok(!strncmp(raw_header, buf, size), "buf = %s\n", buf); InternetCloseHandle(req);
req = HttpOpenRequestA(con, NULL, get_gzip, NULL, NULL, NULL, INTERNET_FLAG_FROM_CACHE, 0); ok(req != NULL, "HttpOpenRequest failed\n");
ret = TRUE; ret = InternetSetOptionA(req, INTERNET_OPTION_HTTP_DECODING, &ret, sizeof(ret)); ok(ret, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
ret = HttpSendRequestA(req, "Accept-Encoding: gzip", -1, NULL, 0); ok(ret, "HttpSendRequest failed with error %u\n", GetLastError()); size = 0; while(InternetReadFile(req, buf+size, sizeof(buf)-1-size, &read) && read) size += read; todo_wine ok(size == 10, "read %d bytes of data\n", size); buf[size] = 0; ok(!strncmp(buf, content, size), "incorrect page content: %s\n", buf);
size = sizeof(buf); ret = HttpQueryInfoA(req, HTTP_QUERY_CONTENT_ENCODING, buf, &size, 0); ok(!ret && GetLastError()==ERROR_HTTP_HEADER_NOT_FOUND, "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) returned %d, %d\n", ret, GetLastError());
size = sizeof(buf)-1; ret = HttpQueryInfoA(req, HTTP_QUERY_CONTENT_TYPE, buf, &size, 0); todo_wine ok(ret, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError()); buf[size] = 0; todo_wine ok(!strncmp(text_html, buf, size), "buf = %s\n", buf); InternetCloseHandle(req);
/* Decompression doesn't work while reading from cache */ test_cache_gzip = 0; sprintf(cache_url, cache_url_fmt, port, get_gzip); DeleteUrlCacheEntryA(cache_url);
req = HttpOpenRequestA(con, NULL, get_gzip, NULL, NULL, NULL, 0, 0); ok(req != NULL, "HttpOpenRequest failed\n");
ret = HttpSendRequestA(req, "Accept-Encoding: gzip", -1, NULL, 0); ok(ret, "HttpSendRequest failed with error %u\n", GetLastError()); size = 0; while(InternetReadFile(req, buf+size, sizeof(buf)-1-size, &read) && read) size += read; ok(size == 31, "read %d bytes of data\n", size); InternetCloseHandle(req);
req = HttpOpenRequestA(con, NULL, get_gzip, NULL, NULL, NULL, INTERNET_FLAG_FROM_CACHE, 0); ok(req != NULL, "HttpOpenRequest failed\n");
ret = TRUE; ret = InternetSetOptionA(req, INTERNET_OPTION_HTTP_DECODING, &ret, sizeof(ret)); ok(ret, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
ret = HttpSendRequestA(req, "Accept-Encoding: gzip", -1, NULL, 0); ok(ret, "HttpSendRequest failed with error %u\n", GetLastError()); size = 0; while(InternetReadFile(req, buf+size, sizeof(buf)-1-size, &read) && read) size += read; todo_wine ok(size == 31, "read %d bytes of data\n", size);
size = sizeof(buf); ret = HttpQueryInfoA(req, HTTP_QUERY_CONTENT_ENCODING, buf, &size, 0); todo_wine ok(ret, "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) failed: %d\n", GetLastError()); InternetCloseHandle(req);
InternetCloseHandle(con); InternetCloseHandle(ses);
/* Decompression doesn't work while reading from cache */ test_cache_gzip = 0; sprintf(cache_url, cache_url_fmt, port, get_gzip); DeleteUrlCacheEntryA(cache_url);
ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); ok(ses != NULL,"InternetOpen failed with error %u\n", GetLastError());
ret = TRUE; ret = InternetSetOptionA(ses, INTERNET_OPTION_HTTP_DECODING, &ret, sizeof(ret)); ok(ret, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); ok(con != NULL, "InternetConnect failed with error %u\n", GetLastError());
req = HttpOpenRequestA(con, NULL, get_gzip, NULL, NULL, NULL, 0, 0); ok(req != NULL, "HttpOpenRequest failed\n");
ret = HttpSendRequestA(req, "Accept-Encoding: gzip", -1, NULL, 0); ok(ret, "HttpSendRequest failed with error %u\n", GetLastError()); size = 0; while(InternetReadFile(req, buf+size, sizeof(buf)-1-size, &read) && read) size += read; ok(size == 10, "read %d bytes of data\n", size); buf[size] = 0; ok(!strncmp(buf, content, size), "incorrect page content: %s\n", buf); InternetCloseHandle(req);
InternetCloseHandle(con); InternetCloseHandle(ses);
/* Decompression doesn't work while reading from cache */ test_cache_gzip = 0; sprintf(cache_url, cache_url_fmt, port, get_gzip); DeleteUrlCacheEntryA(cache_url);
ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); ok(ses != NULL,"InternetOpen failed with error %u\n", GetLastError());
con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); ok(con != NULL, "InternetConnect failed with error %u\n", GetLastError());
ret = TRUE; ret = InternetSetOptionA(con, INTERNET_OPTION_HTTP_DECODING, &ret, sizeof(ret)); ok(ret, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
req = HttpOpenRequestA(con, NULL, get_gzip, NULL, NULL, NULL, 0, 0); ok(req != NULL, "HttpOpenRequest failed\n");
ret = HttpSendRequestA(req, "Accept-Encoding: gzip", -1, NULL, 0); ok(ret, "HttpSendRequest failed with error %u\n", GetLastError()); size = 0; while(InternetReadFile(req, buf+size, sizeof(buf)-1-size, &read) && read) size += read; ok(size == 10, "read %d bytes of data\n", size); buf[size] = 0; ok(!strncmp(buf, content, size), "incorrect page content: %s\n", buf); InternetCloseHandle(req);
InternetCloseHandle(con); InternetCloseHandle(ses);
DeleteUrlCacheEntryA(cache_url);}
static void test_HttpSendRequestW(int port){ static const WCHAR header[] = {'U','A','-','C','P','U',':',' ','x','8','6',0}; HINTERNET ses, con, req; DWORD error; BOOL ret;
ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_ASYNC); ok(ses != NULL, "InternetOpen failed\n");
con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); ok(con != NULL, "InternetConnect failed\n");
req = HttpOpenRequestA(con, NULL, "/test1", NULL, NULL, NULL, 0, 0); ok(req != NULL, "HttpOpenRequest failed\n");
SetLastError(0xdeadbeef); ret = HttpSendRequestW(req, header, ~0u, NULL, 0); error = GetLastError(); ok(!ret, "HttpSendRequestW succeeded\n"); ok(error == ERROR_IO_PENDING || broken(error == ERROR_HTTP_HEADER_NOT_FOUND) || /* IE6 */ broken(error == ERROR_INVALID_PARAMETER), /* IE5 */ "got %u expected ERROR_IO_PENDING\n", error);
InternetCloseHandle(req); InternetCloseHandle(con); InternetCloseHandle(ses);}
static void test_cookie_header(int port){ HINTERNET ses, con, req; DWORD size, error; BOOL ret; char buffer[256];
ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); ok(ses != NULL, "InternetOpen failed\n");
con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); ok(con != NULL, "InternetConnect failed\n");
InternetSetCookieA("http://localhost", "cookie", "biscuit");
req = HttpOpenRequestA(con, NULL, "/testC", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0); ok(req != NULL, "HttpOpenRequest failed\n");
buffer[0] = 0; size = sizeof(buffer); SetLastError(0xdeadbeef); ret = HttpQueryInfoA(req, HTTP_QUERY_COOKIE | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL); error = GetLastError(); ok(!ret, "HttpQueryInfo succeeded\n"); ok(error == ERROR_HTTP_HEADER_NOT_FOUND, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error);
ret = HttpAddRequestHeadersA(req, "Cookie: cookie=not biscuit\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD); ok(ret, "HttpAddRequestHeaders failed: %u\n", GetLastError());
buffer[0] = 0; size = sizeof(buffer); ret = HttpQueryInfoA(req, HTTP_QUERY_COOKIE | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL); ok(ret, "HttpQueryInfo failed: %u\n", GetLastError()); ok(!!strstr(buffer, "cookie=not biscuit"), "got '%s' expected \'cookie=not biscuit\'\n", buffer);
ret = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
test_status_code(req, 200);
buffer[0] = 0; size = sizeof(buffer); ret = HttpQueryInfoA(req, HTTP_QUERY_COOKIE | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL); ok(ret, "HttpQueryInfo failed: %u\n", GetLastError()); ok(!strstr(buffer, "cookie=not biscuit"), "'%s' should not contain \'cookie=not biscuit\'\n", buffer); ok(!!strstr(buffer, "cookie=biscuit"), "'%s' should contain \'cookie=biscuit\'\n", buffer);
InternetCloseHandle(req);
InternetSetCookieA("http://localhost/testCCCC", "subcookie", "data");
req = HttpOpenRequestA(con, NULL, "/test_cookie_path1", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0); ok(req != NULL, "HttpOpenRequest failed\n");
ret = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed\n");
test_status_code(req, 200); InternetCloseHandle(req);
req = HttpOpenRequestA(con, NULL, "/test_cookie_path1/abc", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0); ok(req != NULL, "HttpOpenRequest failed\n");
ret = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed\n");
test_status_code(req, 200); InternetCloseHandle(req);
req = HttpOpenRequestA(con, NULL, "/test_cookie_set_path", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0); ok(req != NULL, "HttpOpenRequest failed\n");
ret = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed\n");
test_status_code(req, 200); InternetCloseHandle(req);
req = HttpOpenRequestA(con, NULL, "/test_cookie_path2", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0); ok(req != NULL, "HttpOpenRequest failed\n");
ret = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed\n");
test_status_code(req, 400); InternetCloseHandle(req);
req = HttpOpenRequestA(con, NULL, "/test_cookie_merge", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0); ok(req != NULL, "HttpOpenRequest failed\n");
ret = HttpAddRequestHeadersA(req, "Cookie: manual_cookie=test\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD); ok(ret, "HttpAddRequestHeaders failed: %u\n", GetLastError());
ret = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed\n");
test_status_code(req, 200); InternetCloseHandle(req);
InternetCloseHandle(con); InternetCloseHandle(ses);}
static void test_basic_authentication(int port){ HINTERNET session, connect, request; BOOL ret;
session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); ok(session != NULL, "InternetOpen failed\n");
connect = InternetConnectA(session, "localhost", port, "user", "pwd", INTERNET_SERVICE_HTTP, 0, 0); ok(connect != NULL, "InternetConnect failed\n");
request = HttpOpenRequestA(connect, NULL, "/test3", NULL, NULL, NULL, 0, 0); ok(request != NULL, "HttpOpenRequest failed\n");
ret = HttpSendRequestA(request, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed %u\n", GetLastError());
test_status_code(request, 200); test_request_flags(request, 0);
InternetCloseHandle(request); InternetCloseHandle(connect); InternetCloseHandle(session);}
static void test_premature_disconnect(int port){ test_request_t req; DWORD err; BOOL ret;
open_simple_request(&req, "localhost", port, NULL, "/premature_disconnect");
SetLastError(0xdeadbeef); ret = HttpSendRequestA(req.request, NULL, 0, NULL, 0); err = GetLastError(); todo_wine ok(!ret, "HttpSendRequest succeeded\n"); todo_wine ok(err == ERROR_HTTP_INVALID_SERVER_RESPONSE, "got %u\n", err);
close_request(&req);}
static void test_invalid_response_headers(int port){ test_request_t req; DWORD size; BOOL ret; char buffer[256];
open_simple_request(&req, "localhost", port, NULL, "/testE");
ret = HttpSendRequestA(req.request, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed %u\n", GetLastError());
test_status_code(req.request, 401); test_request_flags(req.request, 0);
buffer[0] = 0; size = sizeof(buffer); ret = HttpQueryInfoA(req.request, HTTP_QUERY_RAW_HEADERS, buffer, &size, NULL); ok(ret, "HttpQueryInfo failed\n"); ok(!strcmp(buffer, "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"), "headers wrong \"%s\"\n", buffer);
buffer[0] = 0; size = sizeof(buffer); ret = HttpQueryInfoA(req.request, HTTP_QUERY_SERVER, buffer, &size, NULL); ok(ret, "HttpQueryInfo failed\n"); ok(!strcmp(buffer, "winetest"), "server wrong \"%s\"\n", buffer);
close_request(&req);}
static void test_response_without_headers(int port){ test_request_t req; DWORD r, count, size; char buffer[1024];
open_simple_request(&req, "localhost", port, NULL, "/testG");
test_request_flags(req.request, INTERNET_REQFLAG_NO_HEADERS);
r = HttpSendRequestA(req.request, NULL, 0, NULL, 0); ok(r, "HttpSendRequest failed %u\n", GetLastError());
test_request_flags_todo(req.request, INTERNET_REQFLAG_NO_HEADERS);
count = 0; memset(buffer, 0, sizeof buffer); r = InternetReadFile(req.request, buffer, sizeof buffer, &count); ok(r, "InternetReadFile failed %u\n", GetLastError()); todo_wine ok(count == sizeof page1 - 1, "count was wrong\n"); todo_wine ok(!memcmp(buffer, page1, sizeof page1), "http data wrong\n");
test_status_code(req.request, 200); test_request_flags_todo(req.request, INTERNET_REQFLAG_NO_HEADERS);
buffer[0] = 0; size = sizeof(buffer); r = HttpQueryInfoA(req.request, HTTP_QUERY_STATUS_TEXT, buffer, &size, NULL ); ok(r, "HttpQueryInfo failed %u\n", GetLastError()); ok(!strcmp(buffer, "OK"), "expected OK got: \"%s\"\n", buffer);
buffer[0] = 0; size = sizeof(buffer); r = HttpQueryInfoA(req.request, HTTP_QUERY_VERSION, buffer, &size, NULL); ok(r, "HttpQueryInfo failed %u\n", GetLastError()); ok(!strcmp(buffer, "HTTP/1.0"), "expected HTTP/1.0 got: \"%s\"\n", buffer);
buffer[0] = 0; size = sizeof(buffer); r = HttpQueryInfoA(req.request, HTTP_QUERY_RAW_HEADERS, buffer, &size, NULL); ok(r, "HttpQueryInfo failed %u\n", GetLastError()); ok(!strcmp(buffer, "HTTP/1.0 200 OK"), "raw headers wrong: \"%s\"\n", buffer);
close_request(&req);}
static void test_head_request(int port){ DWORD len, content_length; test_request_t req; BYTE buf[100]; BOOL ret;
open_simple_request(&req, "localhost", port, "HEAD", "/test_head");
ret = HttpSendRequestA(req.request, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
len = sizeof(content_length); content_length = -1; ret = HttpQueryInfoA(req.request, HTTP_QUERY_FLAG_NUMBER|HTTP_QUERY_CONTENT_LENGTH, &content_length, &len, 0); ok(ret, "HttpQueryInfo failed: %u\n", GetLastError()); ok(len == sizeof(DWORD), "len = %u\n", len); ok(content_length == 100, "content_length = %u\n", content_length);
len = -1; ret = InternetReadFile(req.request, buf, sizeof(buf), &len); ok(ret, "InternetReadFile failed: %u\n", GetLastError());
len = -1; ret = InternetReadFile(req.request, buf, sizeof(buf), &len); ok(ret, "InternetReadFile failed: %u\n", GetLastError());
close_request(&req);}
static void test_HttpQueryInfo(int port){ test_request_t req; DWORD size, index, error; char buffer[1024]; BOOL ret;
open_simple_request(&req, "localhost", port, NULL, "/testD");
size = sizeof(buffer); ret = HttpQueryInfoA(req.request, HTTP_QUERY_STATUS_TEXT, buffer, &size, &index); error = GetLastError(); ok(!ret || broken(ret), "HttpQueryInfo succeeded\n"); if (!ret) ok(error == ERROR_HTTP_HEADER_NOT_FOUND, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error);
ret = HttpSendRequestA(req.request, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed\n");
index = 0; size = sizeof(buffer); ret = HttpQueryInfoA(req.request, HTTP_QUERY_HOST | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, &index); ok(ret, "HttpQueryInfo failed %u\n", GetLastError()); ok(index == 1, "expected 1 got %u\n", index);
index = 0; size = sizeof(buffer); ret = HttpQueryInfoA(req.request, HTTP_QUERY_DATE | HTTP_QUERY_FLAG_SYSTEMTIME, buffer, &size, &index); ok(ret, "HttpQueryInfo failed %u\n", GetLastError()); ok(index == 1, "expected 1 got %u\n", index);
index = 0; size = sizeof(buffer); ret = HttpQueryInfoA(req.request, HTTP_QUERY_RAW_HEADERS, buffer, &size, &index); ok(ret, "HttpQueryInfo failed %u\n", GetLastError()); ok(index == 0, "expected 0 got %u\n", index);
size = sizeof(buffer); ret = HttpQueryInfoA(req.request, HTTP_QUERY_RAW_HEADERS, buffer, &size, &index); ok(ret, "HttpQueryInfo failed %u\n", GetLastError()); ok(index == 0, "expected 0 got %u\n", index);
index = 0xdeadbeef; /* invalid start index */ size = sizeof(buffer); ret = HttpQueryInfoA(req.request, HTTP_QUERY_RAW_HEADERS, buffer, &size, &index); todo_wine ok(!ret, "HttpQueryInfo should have failed\n"); todo_wine ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "Expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError());
index = 0; size = sizeof(buffer); ret = HttpQueryInfoA(req.request, HTTP_QUERY_RAW_HEADERS_CRLF, buffer, &size, &index); ok(ret, "HttpQueryInfo failed %u\n", GetLastError()); ok(index == 0, "expected 0 got %u\n", index);
size = sizeof(buffer); ret = HttpQueryInfoA(req.request, HTTP_QUERY_STATUS_TEXT, buffer, &size, &index); ok(ret, "HttpQueryInfo failed %u\n", GetLastError()); ok(index == 0, "expected 0 got %u\n", index);
size = sizeof(buffer); ret = HttpQueryInfoA(req.request, HTTP_QUERY_VERSION, buffer, &size, &index); ok(ret, "HttpQueryInfo failed %u\n", GetLastError()); ok(index == 0, "expected 0 got %u\n", index);
test_status_code(req.request, 200);
index = 0xdeadbeef; size = sizeof(buffer); ret = HttpQueryInfoA(req.request, HTTP_QUERY_FORWARDED, buffer, &size, &index); ok(!ret, "HttpQueryInfo succeeded\n"); ok(index == 0xdeadbeef, "expected 0xdeadbeef got %u\n", index);
index = 0; size = sizeof(buffer); ret = HttpQueryInfoA(req.request, HTTP_QUERY_SERVER, buffer, &size, &index); ok(ret, "HttpQueryInfo failed %u\n", GetLastError()); ok(index == 1, "expected 1 got %u\n", index);
index = 0; size = sizeof(buffer); strcpy(buffer, "Server"); ret = HttpQueryInfoA(req.request, HTTP_QUERY_CUSTOM, buffer, &size, &index); ok(ret, "HttpQueryInfo failed %u\n", GetLastError()); ok(index == 1, "expected 1 got %u\n", index);
index = 0; size = sizeof(buffer); ret = HttpQueryInfoA(req.request, HTTP_QUERY_SET_COOKIE, buffer, &size, &index); ok(ret, "HttpQueryInfo failed %u\n", GetLastError()); ok(index == 1, "expected 1 got %u\n", index);
size = sizeof(buffer); ret = HttpQueryInfoA(req.request, HTTP_QUERY_SET_COOKIE, buffer, &size, &index); ok(ret, "HttpQueryInfo failed %u\n", GetLastError()); ok(index == 2, "expected 2 got %u\n", index);
close_request(&req);}
static void test_options(int port){ INTERNET_DIAGNOSTIC_SOCKET_INFO idsi; HINTERNET ses, con, req; DWORD size, error; DWORD_PTR ctx; BOOL ret;
ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); ok(ses != NULL, "InternetOpen failed\n");
SetLastError(0xdeadbeef); ret = InternetSetOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, NULL, 0); error = GetLastError(); ok(!ret, "InternetSetOption succeeded\n"); ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
SetLastError(0xdeadbeef); ret = InternetSetOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, NULL, sizeof(ctx)); ok(!ret, "InternetSetOption succeeded\n"); error = GetLastError(); ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
SetLastError(0xdeadbeef); ret = InternetSetOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, &ctx, 0); ok(!ret, "InternetSetOption succeeded\n"); error = GetLastError(); ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
ctx = 1; ret = InternetSetOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, &ctx, sizeof(ctx)); ok(ret, "InternetSetOption failed %u\n", GetLastError());
SetLastError(0xdeadbeef); ret = InternetQueryOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, NULL, NULL); error = GetLastError(); ok(!ret, "InternetQueryOption succeeded\n"); ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
SetLastError(0xdeadbeef); ret = InternetQueryOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, &ctx, NULL); error = GetLastError(); ok(!ret, "InternetQueryOption succeeded\n"); ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
size = 0; SetLastError(0xdeadbeef); ret = InternetQueryOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, NULL, &size); error = GetLastError(); ok(!ret, "InternetQueryOption succeeded\n"); ok(error == ERROR_INSUFFICIENT_BUFFER, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error);
size = sizeof(ctx); SetLastError(0xdeadbeef); ret = InternetQueryOptionA(NULL, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size); error = GetLastError(); ok(!ret, "InternetQueryOption succeeded\n"); ok(error == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %u\n", error);
ctx = 0xdeadbeef; size = sizeof(ctx); ret = InternetQueryOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size); ok(ret, "InternetQueryOption failed %u\n", GetLastError()); ok(ctx == 1, "expected 1 got %lu\n", ctx);
con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); ok(con != NULL, "InternetConnect failed\n");
ctx = 0xdeadbeef; size = sizeof(ctx); ret = InternetQueryOptionA(con, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size); ok(ret, "InternetQueryOption failed %u\n", GetLastError()); ok(ctx == 0, "expected 0 got %lu\n", ctx);
ctx = 2; ret = InternetSetOptionA(con, INTERNET_OPTION_CONTEXT_VALUE, &ctx, sizeof(ctx)); ok(ret, "InternetSetOption failed %u\n", GetLastError());
ctx = 0xdeadbeef; size = sizeof(ctx); ret = InternetQueryOptionA(con, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size); ok(ret, "InternetQueryOption failed %u\n", GetLastError()); ok(ctx == 2, "expected 2 got %lu\n", ctx);
req = HttpOpenRequestA(con, NULL, "/test1", NULL, NULL, NULL, 0, 0); ok(req != NULL, "HttpOpenRequest failed\n");
ctx = 0xdeadbeef; size = sizeof(ctx); ret = InternetQueryOptionA(req, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size); ok(ret, "InternetQueryOption failed %u\n", GetLastError()); ok(ctx == 0, "expected 0 got %lu\n", ctx);
ctx = 3; ret = InternetSetOptionA(req, INTERNET_OPTION_CONTEXT_VALUE, &ctx, sizeof(ctx)); ok(ret, "InternetSetOption failed %u\n", GetLastError());
ctx = 0xdeadbeef; size = sizeof(ctx); ret = InternetQueryOptionA(req, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size); ok(ret, "InternetQueryOption failed %u\n", GetLastError()); ok(ctx == 3, "expected 3 got %lu\n", ctx);
size = sizeof(idsi); ret = InternetQueryOptionA(req, INTERNET_OPTION_DIAGNOSTIC_SOCKET_INFO, &idsi, &size); ok(ret, "InternetQueryOption failed %u\n", GetLastError());
size = 0; SetLastError(0xdeadbeef); ret = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, NULL, &size); error = GetLastError(); ok(!ret, "InternetQueryOption succeeded\n"); ok(error == ERROR_INTERNET_INVALID_OPERATION, "expected ERROR_INTERNET_INVALID_OPERATION, got %u\n", error);
/* INTERNET_OPTION_PROXY */ SetLastError(0xdeadbeef); ret = InternetQueryOptionA(ses, INTERNET_OPTION_PROXY, NULL, NULL); error = GetLastError(); ok(!ret, "InternetQueryOption succeeded\n"); ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
SetLastError(0xdeadbeef); ret = InternetQueryOptionA(ses, INTERNET_OPTION_PROXY, &ctx, NULL); error = GetLastError(); ok(!ret, "InternetQueryOption succeeded\n"); ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
size = 0; SetLastError(0xdeadbeef); ret = InternetQueryOptionA(ses, INTERNET_OPTION_PROXY, NULL, &size); error = GetLastError(); ok(!ret, "InternetQueryOption succeeded\n"); ok(error == ERROR_INSUFFICIENT_BUFFER, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error); ok(size >= sizeof(INTERNET_PROXY_INFOA), "expected size to be greater or equal to the struct size\n");
InternetCloseHandle(req); InternetCloseHandle(con); InternetCloseHandle(ses);}
typedef struct { const char *response_text; int status_code; const char *status_text; const char *raw_headers;} http_status_test_t;
static const http_status_test_t http_status_tests[] = { { "HTTP/1.1 200 OK\r\n" "Content-Length: 1\r\n" "\r\nx", 200, "OK" }, { "HTTP/1.1 404 Fail\r\n" "Content-Length: 1\r\n" "\r\nx", 404, "Fail" }, { "HTTP/1.1 200\r\n" "Content-Length: 1\r\n" "\r\nx", 200, "" }, { "HTTP/1.1 410 \r\n" "Content-Length: 1\r\n" "\r\nx", 410, "" }};
static void test_http_status(int port){ test_request_t req; char buf[1000]; DWORD i, size; BOOL res;
for(i = 0; i < ARRAY_SIZE(http_status_tests); i++) { send_buffer = http_status_tests[i].response_text;
open_simple_request(&req, "localhost", port, NULL, "/send_from_buffer");
res = HttpSendRequestA(req.request, NULL, 0, NULL, 0); ok(res, "HttpSendRequest failed\n");
test_status_code(req.request, http_status_tests[i].status_code);
size = sizeof(buf); res = HttpQueryInfoA(req.request, HTTP_QUERY_STATUS_TEXT, buf, &size, NULL); ok(res, "HttpQueryInfo failed: %u\n", GetLastError()); ok(!strcmp(buf, http_status_tests[i].status_text), "[%u] Unexpected status text \"%s\", expected \"%s\"\n", i, buf, http_status_tests[i].status_text);
close_request(&req); }}
static void test_cache_control_verb(int port){ HINTERNET session, connect, request; BOOL ret;
session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); ok(session != NULL, "InternetOpen failed\n");
connect = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); ok(connect != NULL, "InternetConnect failed\n");
request = HttpOpenRequestA(connect, "RPC_OUT_DATA", "/test_cache_control_verb", NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0); ok(request != NULL, "HttpOpenRequest failed\n"); ret = HttpSendRequestA(request, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed %u\n", GetLastError()); test_status_code(request, 200); InternetCloseHandle(request);
request = HttpOpenRequestA(connect, "POST", "/test_cache_control_verb", NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0); ok(request != NULL, "HttpOpenRequest failed\n"); ret = HttpSendRequestA(request, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed %u\n", GetLastError()); test_status_code(request, 200); InternetCloseHandle(request);
request = HttpOpenRequestA(connect, "HEAD", "/test_cache_control_verb", NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0); ok(request != NULL, "HttpOpenRequest failed\n"); ret = HttpSendRequestA(request, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed %u\n", GetLastError()); test_status_code(request, 200); InternetCloseHandle(request);
request = HttpOpenRequestA(connect, "GET", "/test_cache_control_verb", NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0); ok(request != NULL, "HttpOpenRequest failed\n"); ret = HttpSendRequestA(request, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed %u\n", GetLastError()); test_status_code(request, 200); InternetCloseHandle(request);
InternetCloseHandle(connect); InternetCloseHandle(session);}
static void test_request_content_length(int port){ char data[] = {'t','e','s','t'}; test_request_t req; BOOL ret;
reset_events(); open_simple_request(&req, "localhost", port, "POST", "/test_request_content_length");
ret = HttpSendRequestA(req.request, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed %u\n", GetLastError()); test_status_code(req.request, 200);
SetEvent(complete_event);
ret = HttpSendRequestA(req.request, NULL, 0, data, sizeof(data)); ok(ret, "HttpSendRequest failed %u\n", GetLastError()); test_status_code(req.request, 200);
SetEvent(complete_event); close_request(&req);}
static void test_accept_encoding(int port){ HINTERNET ses, con, req; char buf[1000]; BOOL ret;
ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); ok(ses != NULL, "InternetOpen failed\n");
con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); ok(con != NULL, "InternetConnect failed\n");
req = HttpOpenRequestA(con, "GET", "/echo_request", "HTTP/1.0", NULL, NULL, 0, 0); ok(req != NULL, "HttpOpenRequest failed\n");
ret = HttpAddRequestHeadersA(req, "Accept-Encoding: gzip\r\n", ~0u, HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDREQ_FLAG_ADD); ok(ret, "HttpAddRequestHeaders failed\n");
ret = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(ret, "HttpSendRequestA failed\n");
test_status_code(req, 200); receive_simple_request(req, buf, sizeof(buf)); ok(strstr(buf, "Accept-Encoding: gzip") != NULL, "Accept-Encoding header not found in %s\n", buf);
InternetCloseHandle(req);
req = HttpOpenRequestA(con, "GET", "/echo_request", "HTTP/1.0", NULL, NULL, 0, 0); ok(req != NULL, "HttpOpenRequest failed\n");
ret = HttpSendRequestA(req, "Accept-Encoding: gzip", ~0u, NULL, 0); ok(ret, "HttpSendRequestA failed\n");
test_status_code(req, 200); receive_simple_request(req, buf, sizeof(buf)); ok(strstr(buf, "Accept-Encoding: gzip") != NULL, "Accept-Encoding header not found in %s\n", buf);
InternetCloseHandle(req); InternetCloseHandle(con); InternetCloseHandle(ses);}
static void test_basic_auth_credentials_reuse(int port){ HINTERNET ses, con, req; DWORD status, size; BOOL ret; char buffer[0x40];
ses = InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0 ); ok( ses != NULL, "InternetOpenA failed\n" );
con = InternetConnectA( ses, "localhost", port, "user", "pwd", INTERNET_SERVICE_HTTP, 0, 0 ); ok( con != NULL, "InternetConnectA failed %u\n", GetLastError() );
req = HttpOpenRequestA( con, "HEAD", "/upload.txt", NULL, NULL, NULL, 0, 0 ); ok( req != NULL, "HttpOpenRequestA failed %u\n", GetLastError() );
ret = HttpSendRequestA( req, NULL, 0, NULL, 0 ); ok( ret, "HttpSendRequestA failed %u\n", GetLastError() );
size = sizeof(buffer); SetLastError(0xdeadbeef); ret = InternetQueryOptionA(req, INTERNET_OPTION_USERNAME, buffer, &size); ok(ret, "unexpected failure %u\n", GetLastError()); ok(!strcmp(buffer, "user"), "got %s\n", buffer); ok(size == 4, "got %u\n", size);
size = sizeof(buffer); SetLastError(0xdeadbeef); ret = InternetQueryOptionA(req, INTERNET_OPTION_PASSWORD, buffer, &size); ok(ret, "unexpected failure %u\n", GetLastError()); ok(!strcmp(buffer, "pwd"), "got %s\n", buffer); ok(size == 3, "got %u\n", size);
status = 0xdeadbeef; size = sizeof(status); ret = HttpQueryInfoA( req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL ); ok( ret, "HttpQueryInfoA failed %u\n", GetLastError() ); ok( status == 200, "got %u\n", status );
InternetCloseHandle( req ); InternetCloseHandle( con ); InternetCloseHandle( ses );
ses = InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0 ); ok( ses != NULL, "InternetOpenA failed\n" );
con = InternetConnectA( ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0 ); ok( con != NULL, "InternetConnectA failed %u\n", GetLastError() );
req = HttpOpenRequestA( con, "PUT", "/upload2.txt", NULL, NULL, NULL, 0, 0 ); ok( req != NULL, "HttpOpenRequestA failed %u\n", GetLastError() );
ret = HttpSendRequestA( req, NULL, 0, NULL, 0 ); ok( ret, "HttpSendRequestA failed %u\n", GetLastError() );
size = sizeof(buffer); SetLastError(0xdeadbeef); ret = InternetQueryOptionA(req, INTERNET_OPTION_USERNAME, buffer, &size); ok(ret, "unexpected failure %u\n", GetLastError()); ok(!strcmp(buffer, "user"), "got %s\n", buffer); ok(size == 4, "got %u\n", size);
size = sizeof(buffer); SetLastError(0xdeadbeef); ret = InternetQueryOptionA(req, INTERNET_OPTION_PASSWORD, buffer, &size); ok(ret, "unexpected failure %u\n", GetLastError()); ok(!strcmp(buffer, "pwd"), "got %s\n", buffer); ok(size == 3, "got %u\n", size);
status = 0xdeadbeef; size = sizeof(status); ret = HttpQueryInfoA( req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL ); ok( ret, "HttpQueryInfoA failed %u\n", GetLastError() ); ok( status == 200, "got %u\n", status );
InternetCloseHandle( req ); InternetCloseHandle( con ); InternetCloseHandle( ses );}
static void test_basic_auth_credentials_end_session(int port){ HINTERNET ses, con, req; DWORD status, size; BOOL ret; char buffer[0x40];
ses = InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0 ); ok( ses != NULL, "InternetOpenA failed\n" );
con = InternetConnectA( ses, "localhost", port, "user", "pwd", INTERNET_SERVICE_HTTP, 0, 0 ); ok( con != NULL, "InternetConnectA failed %u\n", GetLastError() );
req = HttpOpenRequestA( con, "HEAD", "/upload.txt", NULL, NULL, NULL, 0, 0 ); ok( req != NULL, "HttpOpenRequestA failed %u\n", GetLastError() );
ret = HttpSendRequestA( req, NULL, 0, NULL, 0 ); ok( ret, "HttpSendRequestA failed %u\n", GetLastError() );
size = sizeof(buffer); SetLastError(0xdeadbeef); ret = InternetQueryOptionA(req, INTERNET_OPTION_USERNAME, buffer, &size); ok(ret, "unexpected failure %u\n", GetLastError()); ok(!strcmp(buffer, "user"), "got %s\n", buffer); ok(size == 4, "got %u\n", size);
size = sizeof(buffer); SetLastError(0xdeadbeef); ret = InternetQueryOptionA(req, INTERNET_OPTION_PASSWORD, buffer, &size); ok(ret, "unexpected failure %u\n", GetLastError()); ok(!strcmp(buffer, "pwd"), "got %s\n", buffer); ok(size == 3, "got %u\n", size);
status = 0xdeadbeef; size = sizeof(status); ret = HttpQueryInfoA( req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL ); ok( ret, "HttpQueryInfoA failed %u\n", GetLastError() ); ok( status == HTTP_STATUS_OK, "got %u\n", status );
InternetCloseHandle( req ); InternetCloseHandle( con ); InternetCloseHandle( ses );
ses = InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0 ); ok( ses != NULL, "InternetOpenA failed\n" );
/* Clear the cached credentials */ ret = InternetSetOptionA(ses, INTERNET_OPTION_END_BROWSER_SESSION, NULL, 0); ok(ret, "unexpected failure %u\n", GetLastError());
con = InternetConnectA( ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0 ); ok( con != NULL, "InternetConnectA failed %u\n", GetLastError() );
req = HttpOpenRequestA( con, "PUT", "/upload2.txt", NULL, NULL, NULL, 0, 0 ); ok( req != NULL, "HttpOpenRequestA failed %u\n", GetLastError() );
ret = HttpSendRequestA( req, NULL, 0, NULL, 0 ); ok( ret, "HttpSendRequestA failed %u\n", GetLastError() );
size = sizeof(buffer); SetLastError(0xdeadbeef); ret = InternetQueryOptionA(req, INTERNET_OPTION_USERNAME, buffer, &size); ok(ret, "unexpected failure %u\n", GetLastError()); ok(!strcmp(buffer, ""), "got %s\n", buffer); ok(size == 0, "got %u\n", size);
size = sizeof(buffer); SetLastError(0xdeadbeef); ret = InternetQueryOptionA(req, INTERNET_OPTION_PASSWORD, buffer, &size); ok(ret, "unexpected failure %u\n", GetLastError()); ok(!strcmp(buffer, ""), "got %s\n", buffer); ok(size == 0, "got %u\n", size);
status = 0xdeadbeef; size = sizeof(status); ret = HttpQueryInfoA( req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL ); ok( ret, "HttpQueryInfoA failed %u\n", GetLastError() ); ok( status == HTTP_STATUS_BAD_REQUEST, "got %u\n", status );
InternetCloseHandle( req ); InternetCloseHandle( con ); InternetCloseHandle( ses );}
static void test_basic_auth_credentials_different(int port){ HINTERNET ses, con, req; DWORD status, size; BOOL ret; char buffer[0x40];
ses = InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0 ); ok( ses != NULL, "InternetOpenA failed\n" );
con = InternetConnectA( ses, "localhost", port, "user", "pwd", INTERNET_SERVICE_HTTP, 0, 0 ); ok( con != NULL, "InternetConnectA failed %u\n", GetLastError() );
req = HttpOpenRequestA( con, "HEAD", "/upload.txt", NULL, NULL, NULL, 0, 0 ); ok( req != NULL, "HttpOpenRequestA failed %u\n", GetLastError() );
ret = HttpSendRequestA( req, NULL, 0, NULL, 0 ); ok( ret, "HttpSendRequestA failed %u\n", GetLastError() );
size = sizeof(buffer); SetLastError(0xdeadbeef); ret = InternetQueryOptionA(req, INTERNET_OPTION_USERNAME, buffer, &size); ok(ret, "unexpected failure %u\n", GetLastError()); ok(!strcmp(buffer, "user"), "got %s\n", buffer); ok(size == 4, "got %u\n", size);
size = sizeof(buffer); SetLastError(0xdeadbeef); ret = InternetQueryOptionA(req, INTERNET_OPTION_PASSWORD, buffer, &size); ok(ret, "unexpected failure %u\n", GetLastError()); ok(!strcmp(buffer, "pwd"), "got %s\n", buffer); ok(size == 3, "got %u\n", size);
status = 0xdeadbeef; size = sizeof(status); ret = HttpQueryInfoA( req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL ); ok( ret, "HttpQueryInfoA failed %u\n", GetLastError() ); ok( status == 200, "got %u\n", status );
InternetCloseHandle( req ); InternetCloseHandle( con ); InternetCloseHandle( ses );
ses = InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0 ); ok( ses != NULL, "InternetOpenA failed\n" );
con = InternetConnectA( ses, "localhost", port, "user1", "pwd1", INTERNET_SERVICE_HTTP, 0, 0 ); ok( con != NULL, "InternetConnectA failed %u\n", GetLastError() );
req = HttpOpenRequestA( con, "HEAD", "/upload3.txt", NULL, NULL, NULL, 0, 0 ); ok( req != NULL, "HttpOpenRequestA failed %u\n", GetLastError() );
ret = HttpSendRequestA( req, NULL, 0, NULL, 0 ); ok( ret, "HttpSendRequestA failed %u\n", GetLastError() );
size = sizeof(buffer); SetLastError(0xdeadbeef); ret = InternetQueryOptionA(req, INTERNET_OPTION_USERNAME, buffer, &size); ok(ret, "unexpected failure %u\n", GetLastError()); ok(!strcmp(buffer, "user1"), "got %s\n", buffer); ok(size == 5, "got %u\n", size);
size = sizeof(buffer); SetLastError(0xdeadbeef); ret = InternetQueryOptionA(req, INTERNET_OPTION_PASSWORD, buffer, &size); ok(ret, "unexpected failure %u\n", GetLastError()); ok(!strcmp(buffer, "pwd1"), "got %s\n", buffer); ok(size == 4, "got %u\n", size);
status = 0xdeadbeef; size = sizeof(status); ret = HttpQueryInfoA( req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL ); ok( ret, "HttpQueryInfoA failed %u\n", GetLastError() ); ok( status == 200, "got %u\n", status );
InternetCloseHandle( req ); InternetCloseHandle( con ); InternetCloseHandle( ses );}
/* * Manually set the Authorization for both calls. */static void test_basic_auth_credentials_manual(int port){ HINTERNET ses, con, req; DWORD status, size; BOOL ret;
ses = InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0 ); ok( ses != NULL, "InternetOpenA failed\n" );
/* Clear the cached credentials */ ret = InternetSetOptionA(ses, INTERNET_OPTION_END_BROWSER_SESSION, NULL, 0); ok(ret, "unexpected failure %u\n", GetLastError());
con = InternetConnectA( ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0 ); ok( con != NULL, "InternetConnectA failed %u\n", GetLastError() );
req = HttpOpenRequestA( con, "HEAD", "/upload.txt", NULL, NULL, NULL, 0, 0 ); ok( req != NULL, "HttpOpenRequestA failed %u\n", GetLastError() );
/* Set Authorization Header */ ret = HttpAddRequestHeadersA(req, "Authorization: Basic dXNlcjpwd2Q=\r\n", ~0u, HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDREQ_FLAG_ADD); ok(ret, "HttpAddRequestHeaders Failed\n");
ret = HttpSendRequestA( req, NULL, 0, NULL, 0 ); ok( ret, "HttpSendRequestA failed %u\n", GetLastError() );
status = 0xdeadbeef; size = sizeof(status); ret = HttpQueryInfoA( req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL ); ok( ret, "HttpQueryInfoA failed %u\n", GetLastError() ); ok( status == 200, "got %u\n", status );
InternetCloseHandle( req ); InternetCloseHandle( con ); InternetCloseHandle( ses );
/* Show manual headers are cached. */ ses = InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0 ); ok( ses != NULL, "InternetOpenA failed\n" );
con = InternetConnectA( ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0 ); ok( con != NULL, "InternetConnectA failed %u\n", GetLastError() );
req = HttpOpenRequestA( con, "HEAD", "/upload.txt", NULL, NULL, NULL, 0, 0 ); ok( req != NULL, "HttpOpenRequestA failed %u\n", GetLastError() );
ret = HttpSendRequestA( req, NULL, 0, NULL, 0 ); ok( ret, "HttpSendRequestA failed %u\n", GetLastError() );
status = 0xdeadbeef; size = sizeof(status); ret = HttpQueryInfoA( req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL ); ok( ret, "HttpQueryInfoA failed %u\n", GetLastError() ); ok( status == 401, "got %u\n", status );
InternetCloseHandle( req ); InternetCloseHandle( con ); InternetCloseHandle( ses );
ses = InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0 ); ok( ses != NULL, "InternetOpenA failed\n" );
con = InternetConnectA( ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0 ); ok( con != NULL, "InternetConnectA failed %u\n", GetLastError() );
req = HttpOpenRequestA( con, "HEAD", "/upload4.txt", NULL, NULL, NULL, 0, 0 ); ok( req != NULL, "HttpOpenRequestA failed %u\n", GetLastError() );
/* Set Authorization Header */ ret = HttpAddRequestHeadersA(req, "Authorization: Bearer dXNlcjE6cHdkMQ==\r\n", ~0u, HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDREQ_FLAG_ADD); ok(ret, "HttpAddRequestHeaders Failed\n");
ret = HttpSendRequestA( req, NULL, 0, NULL, 0 ); ok( ret, "HttpSendRequestA failed %u\n", GetLastError() );
status = 0xdeadbeef; size = sizeof(status); ret = HttpQueryInfoA( req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL ); ok( ret, "HttpQueryInfoA failed %u\n", GetLastError() ); ok( status == 200, "got %u\n", status );
InternetCloseHandle( req ); InternetCloseHandle( con ); InternetCloseHandle( ses );}
/* * Manually set the Authorization for the bearer call, which shows the cached is used. */static void test_basic_auth_credentials_cached_manual(int port){ HINTERNET ses, con, req; DWORD status, size; BOOL ret;
ses = InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0 ); ok( ses != NULL, "InternetOpenA failed\n" );
/* Clear the cached credentials */ ret = InternetSetOptionA(ses, INTERNET_OPTION_END_BROWSER_SESSION, NULL, 0); ok(ret, "unexpected failure %u\n", GetLastError());
con = InternetConnectA( ses, "localhost", port, "user", "pwd", INTERNET_SERVICE_HTTP, 0, 0 ); ok( con != NULL, "InternetConnectA failed %u\n", GetLastError() );
req = HttpOpenRequestA( con, "HEAD", "/upload.txt", NULL, NULL, NULL, 0, 0 ); ok( req != NULL, "HttpOpenRequestA failed %u\n", GetLastError() );
ret = HttpSendRequestA( req, NULL, 0, NULL, 0 ); ok( ret, "HttpSendRequestA failed %u\n", GetLastError() );
status = 0xdeadbeef; size = sizeof(status); ret = HttpQueryInfoA( req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL ); ok( ret, "HttpQueryInfoA failed %u\n", GetLastError() ); ok( status == 200, "got %u\n", status );
InternetCloseHandle( req ); InternetCloseHandle( con ); InternetCloseHandle( ses );
ses = InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0 ); ok( ses != NULL, "InternetOpenA failed\n" );
con = InternetConnectA( ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0 ); ok( con != NULL, "InternetConnectA failed %u\n", GetLastError() );
req = HttpOpenRequestA( con, "HEAD", "/upload4.txt", NULL, NULL, NULL, 0, 0 ); ok( req != NULL, "HttpOpenRequestA failed %u\n", GetLastError() );
/* Setting an Authorization Header doesn't override the cached one. */ ret = HttpAddRequestHeadersA(req, "Authorization: Bearer dXNlcjE6cHdkMQ==\r\n", ~0u, HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDREQ_FLAG_ADD); ok(ret, "HttpAddRequestHeaders Failed\n");
ret = HttpSendRequestA( req, NULL, 0, NULL, 0 ); ok( ret, "HttpSendRequestA failed %u\n", GetLastError() );
status = 0xdeadbeef; size = sizeof(status); ret = HttpQueryInfoA( req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL ); ok( ret, "HttpQueryInfoA failed %u\n", GetLastError() ); ok( status == 201, "got %u\n", status );
InternetCloseHandle( req ); InternetCloseHandle( con ); InternetCloseHandle( ses );}
static void test_async_read(int port){ HINTERNET ses, con, req; INTERNET_BUFFERSA ib; char buffer[0x100]; DWORD pending_reads; DWORD res, count, bytes; BOOL ret;
reset_events();
/* test asynchronous InternetReadFileEx */ ses = InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_ASYNC ); ok( ses != NULL, "InternetOpenA failed\n" ); pInternetSetStatusCallbackA( ses, &callback );
SET_EXPECT( INTERNET_STATUS_HANDLE_CREATED ); con = InternetConnectA( ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0xdeadbeef ); ok( con != NULL, "InternetConnectA failed %u\n", GetLastError() ); CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED );
SET_EXPECT( INTERNET_STATUS_HANDLE_CREATED ); req = HttpOpenRequestA( con, "GET", "/async_read", NULL, NULL, NULL, INTERNET_FLAG_RELOAD, 0xdeadbeef ); ok( req != NULL, "HttpOpenRequestA failed %u\n", GetLastError() ); CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED );
SET_OPTIONAL( INTERNET_STATUS_COOKIE_SENT ); SET_OPTIONAL( INTERNET_STATUS_DETECTING_PROXY ); SET_EXPECT( INTERNET_STATUS_CONNECTING_TO_SERVER ); SET_EXPECT( INTERNET_STATUS_CONNECTED_TO_SERVER ); SET_EXPECT( INTERNET_STATUS_SENDING_REQUEST ); SET_EXPECT( INTERNET_STATUS_REQUEST_SENT ); SET_EXPECT( INTERNET_STATUS_RECEIVING_RESPONSE ); SET_EXPECT( INTERNET_STATUS_RESPONSE_RECEIVED ); SET_OPTIONAL( INTERNET_STATUS_CLOSING_CONNECTION ); SET_OPTIONAL( INTERNET_STATUS_CONNECTION_CLOSED ); SET_EXPECT( INTERNET_STATUS_REQUEST_COMPLETE );
SetLastError( 0xdeadbeef ); ret = HttpSendRequestA( req, NULL, 0, NULL, 0 ); ok( !ret, "HttpSendRequestA unexpectedly succeeded\n" ); ok( GetLastError() == ERROR_IO_PENDING, "expected ERROR_IO_PENDING, got %u\n", GetLastError() ); WaitForSingleObject( complete_event, INFINITE ); ok( req_error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %u\n", req_error );
CLEAR_NOTIFIED( INTERNET_STATUS_COOKIE_SENT ); CLEAR_NOTIFIED( INTERNET_STATUS_DETECTING_PROXY ); CHECK_NOTIFIED( INTERNET_STATUS_CONNECTING_TO_SERVER ); CHECK_NOTIFIED( INTERNET_STATUS_CONNECTED_TO_SERVER ); CHECK_NOTIFIED( INTERNET_STATUS_SENDING_REQUEST ); CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_SENT ); CHECK_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE ); CHECK_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED ); CLEAR_NOTIFIED( INTERNET_STATUS_CLOSING_CONNECTION ); CLEAR_NOTIFIED( INTERNET_STATUS_CONNECTION_CLOSED ); CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_COMPLETE );
pending_reads = 0; memset( &ib, 0, sizeof(ib) ); memset( buffer, 0, sizeof(buffer) ); ib.dwStructSize = sizeof(ib); for (count = 0; count < sizeof(buffer); count += ib.dwBufferLength) { ib.lpvBuffer = buffer + count; ib.dwBufferLength = min(16, sizeof(buffer) - count);
SET_EXPECT( INTERNET_STATUS_RECEIVING_RESPONSE ); SET_EXPECT( INTERNET_STATUS_RESPONSE_RECEIVED );
ret = InternetReadFileExA( req, &ib, 0, 0xdeadbeef ); if (!count) /* the first part should arrive immediately */ ok( ret, "InternetReadFileExA failed %u\n", GetLastError() ); ros_skip_flaky if (!ret) { ok( GetLastError() == ERROR_IO_PENDING, "expected ERROR_IO_PENDING, got %u\n", GetLastError() ); ros_skip_flaky CHECK_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE ); SET_EXPECT( INTERNET_STATUS_REQUEST_COMPLETE ); if (!pending_reads++) { res = WaitForSingleObject( complete_event, 0 ); ok( res == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %u\n", res ); SetEvent( conn_wait_event ); } res = WaitForSingleObject( complete_event, INFINITE ); ok( res == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %u\n", res ); ok( req_error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %u\n", req_error ); todo_wine_if( pending_reads > 1 ) ok( ib.dwBufferLength != 0, "expected ib.dwBufferLength != 0\n" ); CHECK_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED ); CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_COMPLETE ); }
CLEAR_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE ); CLEAR_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED ); if (!ib.dwBufferLength) break; }
ok( pending_reads == 1, "expected 1 pending read, got %u\n", pending_reads ); ok( !strcmp(buffer, page1), "unexpected buffer content\n" ); close_async_handle( ses, 2 ); ResetEvent( conn_wait_event );
/* test asynchronous InternetReadFile */ ses = InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_ASYNC ); ok( ses != NULL, "InternetOpenA failed\n" ); pInternetSetStatusCallbackA( ses, &callback );
SET_EXPECT( INTERNET_STATUS_HANDLE_CREATED ); con = InternetConnectA( ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0xdeadbeef ); ok( con != NULL, "InternetConnectA failed %u\n", GetLastError() ); CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED );
SET_EXPECT( INTERNET_STATUS_HANDLE_CREATED ); req = HttpOpenRequestA( con, "GET", "/async_read", NULL, NULL, NULL, INTERNET_FLAG_RELOAD, 0xdeadbeef ); ok( req != NULL, "HttpOpenRequestA failed %u\n", GetLastError() ); CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED );
SET_OPTIONAL( INTERNET_STATUS_COOKIE_SENT ); SET_OPTIONAL( INTERNET_STATUS_DETECTING_PROXY ); SET_EXPECT( INTERNET_STATUS_CONNECTING_TO_SERVER ); SET_EXPECT( INTERNET_STATUS_CONNECTED_TO_SERVER ); SET_EXPECT( INTERNET_STATUS_SENDING_REQUEST ); SET_EXPECT( INTERNET_STATUS_REQUEST_SENT ); SET_EXPECT( INTERNET_STATUS_RECEIVING_RESPONSE ); SET_EXPECT( INTERNET_STATUS_RESPONSE_RECEIVED ); SET_OPTIONAL( INTERNET_STATUS_CLOSING_CONNECTION ); SET_OPTIONAL( INTERNET_STATUS_CONNECTION_CLOSED ); SET_EXPECT( INTERNET_STATUS_REQUEST_COMPLETE );
SetLastError( 0xdeadbeef ); ret = HttpSendRequestA( req, NULL, 0, NULL, 0 ); ok( !ret, "HttpSendRequestA unexpectedly succeeded\n" ); ok( GetLastError() == ERROR_IO_PENDING, "expected ERROR_IO_PENDING, got %u\n", GetLastError() ); WaitForSingleObject( complete_event, INFINITE ); ok( req_error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %u\n", req_error );
CLEAR_NOTIFIED( INTERNET_STATUS_COOKIE_SENT ); CLEAR_NOTIFIED( INTERNET_STATUS_DETECTING_PROXY ); CHECK_NOTIFIED( INTERNET_STATUS_CONNECTING_TO_SERVER ); CHECK_NOTIFIED( INTERNET_STATUS_CONNECTED_TO_SERVER ); CHECK_NOTIFIED( INTERNET_STATUS_SENDING_REQUEST ); CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_SENT ); CHECK_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE ); CHECK_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED ); CLEAR_NOTIFIED( INTERNET_STATUS_CLOSING_CONNECTION ); CLEAR_NOTIFIED( INTERNET_STATUS_CONNECTION_CLOSED ); CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_COMPLETE );
pending_reads = 0; memset( buffer, 0, sizeof(buffer) ); for (count = 0; count < sizeof(buffer); count += bytes) { SET_EXPECT( INTERNET_STATUS_RECEIVING_RESPONSE ); SET_EXPECT( INTERNET_STATUS_RESPONSE_RECEIVED );
bytes = 0xdeadbeef; ret = InternetReadFile( req, buffer + count, min(16, sizeof(buffer) - count), &bytes ); if (!count) /* the first part should arrive immediately */ ok( ret, "InternetReadFile failed %u\n", GetLastError() ); if (!ret) { ok( GetLastError() == ERROR_IO_PENDING, "expected ERROR_IO_PENDING, got %u\n", GetLastError() ); ok( bytes == 0, "expected 0, got %u\n", bytes ); ros_skip_flaky CHECK_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE ); SET_EXPECT( INTERNET_STATUS_REQUEST_COMPLETE ); if (!pending_reads++) { res = WaitForSingleObject( complete_event, 0 ); ok( res == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %u\n", res ); SetEvent( conn_wait_event ); } res = WaitForSingleObject( complete_event, INFINITE ); ok( res == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %u\n", res ); ok( req_error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %u\n", req_error ); ros_skip_flaky { todo_wine_if( pending_reads > 1 ) ok( bytes != 0, "expected bytes != 0\n" ); } ros_skip_flaky CHECK_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED ); ros_skip_flaky CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_COMPLETE ); }
CLEAR_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE ); CLEAR_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED ); if (!bytes) break; }
ros_skip_flaky ok( pending_reads == 1, "expected 1 pending read, got %u\n", pending_reads ); ok( !strcmp(buffer, page1), "unexpected buffer content\n" ); close_async_handle( ses, 2 );}
static void server_send_string(const char *msg){ send(server_socket, msg, strlen(msg), 0);}
static size_t server_read_data(char *buf, size_t buf_size){ return recv(server_socket, buf, buf_size, 0);}
#define server_read_request(a) _server_read_request(__LINE__,a)static void _server_read_request(unsigned line, const char *expected_request){ char buf[4000], *p; size_t size;
size = server_read_data(buf, sizeof(buf) - 1); buf[size] = 0; p = strstr(buf, "\r\n"); if(p) *p = 0; ok_(__FILE__,line)(p && !strcmp(buf, expected_request), "unexpected request %s\n", buf);}
static BOOL skip_receive_notification_tests;static DWORD received_response_size;
static void WINAPI readex_callback(HINTERNET handle, DWORD_PTR context, DWORD status, void *info, DWORD info_size){ switch(status) { case INTERNET_STATUS_RECEIVING_RESPONSE: if(!skip_receive_notification_tests) callback(handle, context, status, info, info_size); break; case INTERNET_STATUS_RESPONSE_RECEIVED: if(!skip_receive_notification_tests) callback(handle, context, status, info, info_size); received_response_size = *(DWORD*)info; break; case INTERNET_STATUS_REQUEST_SENT: callback(handle, context, status, info, info_size); SetEvent(request_sent_event); break; default: callback(handle, context, status, info, info_size); }}
static void send_socket_request(test_request_t *req, BOOL new_connection){ BOOL ret;
SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT); SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY); if(new_connection) { SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER); SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER); } SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST); SET_EXPECT(INTERNET_STATUS_REQUEST_SENT); if(!skip_receive_notification_tests) SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
SetLastError(0xdeadbeef); ret = HttpSendRequestA(req->request, NULL, 0, NULL, 0); ok(!ret, "HttpSendRequestA unexpectedly succeeded\n"); ok(GetLastError() == ERROR_IO_PENDING, "expected ERROR_IO_PENDING, got %u\n", GetLastError());
if(new_connection) WaitForSingleObject(server_req_rec_event, INFINITE); WaitForSingleObject(request_sent_event, INFINITE);
CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT); CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY); if(new_connection) { CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER); CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER); } CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST); CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);}
static void open_socket_request(int port, test_request_t *req, const char *verb){ /* We're connecting to new socket */ if(!verb) reset_events();
req->session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_ASYNC); ok(req->session != NULL, "InternetOpenA failed\n"); pInternetSetStatusCallbackA(req->session, readex_callback);
SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED); req->connection = InternetConnectA(req->session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0xdeadbeef); ok(req->connection != NULL, "InternetConnectA failed %u\n", GetLastError()); CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED );
SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED); req->request = HttpOpenRequestA(req->connection, "GET", verb ? verb : "/socket", NULL, NULL, NULL, INTERNET_FLAG_RELOAD, 0xdeadbeef); ok(req->request != NULL, "HttpOpenRequestA failed %u\n", GetLastError()); CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED );
send_socket_request(req, !verb);}
static void open_read_test_request(int port, test_request_t *req, const char *response){ if(!skip_receive_notification_tests) SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
open_socket_request(port, req, NULL);
if(!skip_receive_notification_tests) { SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED); received_response_size = 0xdeadbeef; } SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
server_send_string(response); WaitForSingleObject(complete_event, INFINITE);
if(!skip_receive_notification_tests) { CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE); CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED); todo_wine ok(received_response_size == strlen(response), "received_response_size = %u\n", received_response_size); } CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE); ok(req_error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %u\n", req_error);}
#define readex_expect_sync_data_len(a,b,c,d,e,f,g) _readex_expect_sync_data_len(__LINE__,a,b,c,d,e,f,g)static void _readex_expect_sync_data_len(unsigned line, HINTERNET req, DWORD flags, INTERNET_BUFFERSW *buf, DWORD buf_size, const char *exdata, DWORD len, DWORD expect_receive){ BOOL ret;
if(!skip_receive_notification_tests && expect_receive) { SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE); SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED); received_response_size = 0xdeadbeef; }
memset(buf->lpvBuffer, 0xff, buf_size); buf->dwBufferLength = buf_size; ret = InternetReadFileExW(req, buf, flags, 0xdeadbeef); ok_(__FILE__,line)(ret, "InternetReadFileExW failed: %u\n", GetLastError()); ok_(__FILE__,line)(buf->dwBufferLength == len, "dwBufferLength = %u, expected %u\n", buf->dwBufferLength, len); if(len && exdata) ok_(__FILE__,line)(!memcmp(buf->lpvBuffer, exdata, len), "Unexpected data\n");
if(!skip_receive_notification_tests && expect_receive) { CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE); CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED); ok_(__FILE__,line)(received_response_size == len, "received_response_size = %u\n", received_response_size); }}
#define readex_expect_sync_data(a,b,c,d,e,f) _readex_expect_sync_data(__LINE__,a,b,c,d,e,f)static void _readex_expect_sync_data(unsigned line, HINTERNET req, DWORD flags, INTERNET_BUFFERSW *buf, DWORD buf_size, const char *exdata, DWORD expect_receive){ _readex_expect_sync_data_len(line, req, flags, buf, buf_size, exdata, strlen(exdata), expect_receive);}
#define read_expect_sync_data_len(a,b,c,d,e) _read_expect_sync_data_len(__LINE__,a,b,c,d,e)static void _read_expect_sync_data_len(unsigned line, HINTERNET req, void *buf, DWORD buf_size, const char *exdata, DWORD len){ DWORD ret_size = 0xdeadbeef; BOOL ret;
SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE); SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED); SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE); received_response_size = 0xdeadbeef;
memset(buf, 0xff, buf_size); ret = InternetReadFile(req, buf, buf_size, &ret_size); ok_(__FILE__,line)(ret, "InternetReadFileExW failed: %u\n", GetLastError()); ok_(__FILE__,line)(ret_size == len, "dwBufferLength = %u, expected %u\n", ret_size, len); if(len && exdata) ok_(__FILE__,line)(!memcmp(buf, exdata, len), "Unexpected data\n");
CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE); CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED); CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE); ok_(__FILE__,line)(received_response_size == len, "received_response_size = %u\n", received_response_size); ok_(__FILE__,line)(!req_error, "req_error = %u\n", req_error);}
#define read_expect_sync_data(a,b,c,d) _read_expect_sync_data(__LINE__,a,b,c,d)static void _read_expect_sync_data(unsigned line, HINTERNET req, void *buf, DWORD buf_size, const char *exdata){ _read_expect_sync_data_len(line, req, buf, buf_size, exdata, strlen(exdata));}
static void close_connection(void){ char c; SetEvent(conn_wait_event); recv(server_socket, &c, 1, 0);}
#define send_response_and_wait(a,b,c,d,e,f,g,h) _send_response_and_wait(__LINE__,a,b,c,d,e,f,g,h)static void _send_response_and_wait(unsigned line, const char *response, BOOL do_close_connection, void *buf, DWORD *ret_size, const char *exdata, DWORD expected_size, DWORD expected_req_error, DWORD expected_receive_size){ if(!skip_receive_notification_tests) SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED); SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
if(response) server_send_string(response);
if(do_close_connection) close_connection();
WaitForSingleObject(complete_event, INFINITE);
if(!skip_receive_notification_tests) CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED); CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE); if(!skip_receive_notification_tests && expected_receive_size != -1) todo_wine_if(received_response_size != expected_receive_size) /* FIXME! remove when wine is fixed */ ok_(__FILE__,line)(received_response_size == expected_receive_size, "received_response_size = %u\n", received_response_size); ok_(__FILE__,line)(req_error == expected_req_error, "req_error = %u, expected %u\n", req_error, expected_req_error);
/* If IRF_NO_WAIT is used, buffer is not changed. */ ok_(__FILE__,line)(*ret_size == expected_size, "dwBufferLength = %u\n", *ret_size); if(exdata) ok_(__FILE__,line)(!memcmp(buf, exdata, strlen(exdata)), "unexpected buffer data\n"); else if(buf) ok_(__FILE__,line)(!*(DWORD*)buf, "buffer data changed\n");}
#define send_response_ex_and_wait(a,b,c,d,e,f) _send_response_ex_and_wait(__LINE__,a,b,c,d,e,f)static void _send_response_ex_and_wait(unsigned line, const char *response, BOOL close_connection, INTERNET_BUFFERSW *buf, const char *exdata, DWORD expected_req_error, DWORD expected_receive_size){ _send_response_and_wait(line, response, close_connection, buf->lpvBuffer, &buf->dwBufferLength, exdata, exdata ? strlen(exdata) : buf->dwBufferLength, expected_req_error, expected_receive_size);}
static void send_response_len_and_wait(unsigned len, BOOL close_connection, INTERNET_BUFFERSW *buf){ char *response;
response = HeapAlloc(GetProcessHeap(), 0, len+1); memset(response, 'x', len); response[len] = 0; send_response_ex_and_wait(response, close_connection, buf, NULL, 0, -1); HeapFree(GetProcessHeap(), 0, response);}
#define readex_expect_async(a,b,c,d,e) _readex_expect_async(__LINE__,a,b,c,d,e)static void _readex_expect_async(unsigned line, HINTERNET req, DWORD flags, INTERNET_BUFFERSW *buf, DWORD buf_size, const char *exdata){ unsigned len = 0; BOOL ret;
if(!skip_receive_notification_tests) SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
memset(buf->lpvBuffer, 0, max(buf_size, sizeof(DWORD))); buf->dwBufferLength = buf_size; ret = InternetReadFileExW(req, buf, flags, 0xdeadbeef); ok_(__FILE__,line)(!ret && GetLastError() == ERROR_IO_PENDING, "InternetReadFileExW returned %x (%u)\n", ret, GetLastError()); ok_(__FILE__,line)(buf->dwBufferLength == buf_size, "dwBufferLength = %u, expected %u\n", buf->dwBufferLength, buf_size); if(exdata) { len = strlen(exdata); ok_(__FILE__,line)(!memcmp(buf->lpvBuffer, exdata, len), "unexpected buffer data\n"); }else { ok_(__FILE__,line)(!*(DWORD*)buf->lpvBuffer, "buffer data changed\n"); }
if(!skip_receive_notification_tests) CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);}
static void read_expect_async(HINTERNET req, void *buf, DWORD buf_size, DWORD *ret_size, const char *exdata){ unsigned len = 0; const char *p; BOOL ret;
SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
*ret_size = 0xdeadbeef; memset(buf, 0, buf_size); ret = InternetReadFile(req, buf, buf_size, ret_size); ok(!ret && GetLastError() == ERROR_IO_PENDING, "InternetReadFileExW returned %x (%u)\n", ret, GetLastError()); ok(*ret_size == 0, "dwBufferLength = %u\n", *ret_size); if(exdata) { len = strlen(exdata); ok(!memcmp(buf, exdata, len), "unexpected buffer data\n"); } for(p = (const char*)buf + len; p < (const char*)buf + buf_size; p++) { if(*p) ok(0, "buffer data changed\n"); }
CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);}
#define expect_data_available(a,b) _expect_data_available(__LINE__,a,b)static DWORD _expect_data_available(unsigned line, HINTERNET req, int exsize){ DWORD size = 0; BOOL res;
res = InternetQueryDataAvailable(req, &size, 0, 0); ok_(__FILE__,line)(res, "InternetQueryDataAvailable failed: %u\n", GetLastError()); if(exsize != -1) ok_(__FILE__,line)(size == exsize, "size = %u, expected %u\n", size, exsize);
return size;}
#define async_query_data_available(a,b) _async_query_data_available(__LINE__,a,b)static void _async_query_data_available(unsigned line, HINTERNET req, DWORD *size){ BOOL res;
if(!skip_receive_notification_tests) SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
*size = 0xdeadbeef; res = InternetQueryDataAvailable(req, size, 0, 0); ok_(__FILE__,line)(!res && GetLastError() == ERROR_IO_PENDING, "InternetQueryDataAvailable returned: %x(%u)\n", res, GetLastError()); ok_(__FILE__,line)(!*size, "size = %u\n", *size);
if(!skip_receive_notification_tests) CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);}
static void test_http_read(int port){ INTERNET_BUFFERSW ib; test_request_t req; DWORD read_size; char buf[24000]; DWORD avail, i;
if(!is_ie7plus) return;
memset(&ib, 0, sizeof(ib)); ib.dwStructSize = sizeof(ib); ib.lpvBuffer = buf;
trace("Testing InternetReadFileExW with IRF_ASYNC flag...\n");
open_read_test_request(port, &req, "HTTP/1.1 200 OK\r\n" "Server: winetest\r\n" "\r\n" "xx");
readex_expect_async(req.request, IRF_ASYNC, &ib, 4, "xx");
send_response_ex_and_wait("yy1234567890", FALSE, &ib, "xxyy", 0, 2); readex_expect_sync_data(req.request, IRF_ASYNC, &ib, 4, "1234", 4); readex_expect_sync_data(req.request, IRF_ASYNC, &ib, 5, "56789", 5);
readex_expect_async(req.request, IRF_ASYNC, &ib, sizeof(buf), "0"); send_response_ex_and_wait("123", TRUE, &ib, "0123", 0, 4);
close_async_handle(req.session, 2);
trace("Testing InternetReadFileExW with no flags...\n");
open_read_test_request(port, &req, "HTTP/1.1 200 OK\r\n" "Server: winetest\r\n" "\r\n" "xx");
readex_expect_async(req.request, 0, &ib, 4, "xx");
send_response_ex_and_wait("yy1234567890", FALSE, &ib, "xxyy", 0, 2); readex_expect_sync_data(req.request, 0, &ib, 4, "1234", 4); readex_expect_sync_data(req.request, 0, &ib, 5, "56789", 5);
readex_expect_async(req.request, 0, &ib, sizeof(buf), "0"); send_response_ex_and_wait("123", TRUE, &ib, "0123", 0, 4);
close_async_handle(req.session, 2);
trace("Testing InternetReadFile...\n");
open_read_test_request(port, &req, "HTTP/1.1 200 OK\r\n" "Server: winetest\r\n" "\r\n" "xx");
read_expect_async(req.request, buf, 4, &read_size, "xx");
send_response_and_wait("yy1234567890", FALSE, buf, &read_size, "xxyy", 4, 0, 2); read_expect_sync_data(req.request, buf, 4, "1234"); read_expect_sync_data(req.request, buf, 5, "56789");
read_expect_async(req.request, buf, sizeof(buf), &read_size, "0"); send_response_and_wait("123", TRUE, buf, &read_size, "0123", 4, 0, 4);
close_async_handle(req.session, 2);
trace("Testing InternetReadFileExW with IRF_NO_WAIT flag...\n");
open_read_test_request(port, &req, "HTTP/1.1 200 OK\r\n" "Server: winetest\r\n" "\r\n" "xx");
SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE);
readex_expect_sync_data(req.request, IRF_NO_WAIT, &ib, sizeof(buf), "xx", 0);
if(notified[INTERNET_STATUS_RECEIVING_RESPONSE]) { win_skip("Skipping receive notification tests on too old Windows.\n"); skip_receive_notification_tests = TRUE; } CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
readex_expect_async(req.request, IRF_NO_WAIT, &ib, sizeof(buf), NULL); send_response_ex_and_wait("1234567890", FALSE, &ib, NULL, 0, 10); readex_expect_sync_data(req.request, IRF_NO_WAIT, &ib, 5, "12345", 0); readex_expect_sync_data(req.request, IRF_NO_WAIT, &ib, sizeof(buf), "67890", 0);
readex_expect_async(req.request, IRF_NO_WAIT, &ib, sizeof(buf), NULL); send_response_ex_and_wait("12345", TRUE, &ib, NULL, 0, 5);
readex_expect_sync_data(req.request, IRF_NO_WAIT, &ib, sizeof(buf), "12345", 0); readex_expect_sync_data(req.request, IRF_NO_WAIT, &ib, sizeof(buf), "", TRUE);
close_async_handle(req.session, 2);
open_read_test_request(port, &req, "HTTP/1.1 200 OK\r\n" "Server: winetest\r\n" "Transfer-Encoding: chunked\r\n" "\r\n" "9\r\n123456789"); readex_expect_sync_data(req.request, IRF_NO_WAIT, &ib, sizeof(buf), "123456789", 0); readex_expect_async(req.request, IRF_NO_WAIT, &ib, sizeof(buf), NULL);
send_response_ex_and_wait("\r\n1\r\na\r\n1\r\nb\r", FALSE, &ib, NULL, 0, 13); readex_expect_sync_data(req.request, IRF_NO_WAIT, &ib, sizeof(buf), "ab", 0); readex_expect_async(req.request, IRF_NO_WAIT, &ib, sizeof(buf), NULL);
send_response_ex_and_wait("\n3\r\nab", FALSE, &ib, NULL, 0, 6); readex_expect_sync_data(req.request, IRF_NO_WAIT, &ib, sizeof(buf), "ab", 0); readex_expect_async(req.request, IRF_NO_WAIT, &ib, sizeof(buf), NULL);
send_response_ex_and_wait("c", FALSE, &ib, NULL, 0, 1); readex_expect_sync_data(req.request, IRF_NO_WAIT, &ib, sizeof(buf), "c", 0); readex_expect_async(req.request, IRF_NO_WAIT, &ib, sizeof(buf), NULL);
send_response_ex_and_wait("\r\n1\r\nx\r\n0\r\n\r\n", TRUE, &ib, NULL, 0, 13); readex_expect_sync_data(req.request, IRF_NO_WAIT, &ib, sizeof(buf), "x", 0); readex_expect_sync_data(req.request, IRF_NO_WAIT, &ib, sizeof(buf), "", 0);
close_async_handle(req.session, 2);
open_read_test_request(port, &req, "HTTP/1.1 200 OK\r\n" "Server: winetest\r\n" "Transfer-Encoding: chunked\r\n" "\r\n" "3\r\n123\r\n"); readex_expect_sync_data(req.request, IRF_NO_WAIT, &ib, sizeof(buf), "123", 0); readex_expect_async(req.request, IRF_NO_WAIT, &ib, sizeof(buf), NULL);
send_response_ex_and_wait("0\r\n\r\n", TRUE, &ib, NULL, 0, 5); readex_expect_sync_data(req.request, IRF_NO_WAIT, &ib, sizeof(buf), "", 0);
close_async_handle(req.session, 2);
open_read_test_request(port, &req, "HTTP/1.1 200 OK\r\n" "Server: winetest\r\n" "Connection: close\r\n" "\r\n"); readex_expect_async(req.request, IRF_NO_WAIT, &ib, sizeof(buf), NULL); send_response_ex_and_wait("123", TRUE, &ib, NULL, 0, 3); readex_expect_sync_data(req.request, IRF_NO_WAIT, &ib, sizeof(buf), "123", 0);
SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION); SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED); close_async_handle(req.session, 2); CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION); CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
trace("Testing InternetQueryDataAvailable...\n");
open_read_test_request(port, &req, "HTTP/1.1 200 OK\r\n" "Server: winetest\r\n" "\r\n" "123"); expect_data_available(req.request, 3); readex_expect_sync_data(req.request, IRF_NO_WAIT, &ib, sizeof(buf), "123", 0); readex_expect_async(req.request, IRF_NO_WAIT, &ib, sizeof(buf), NULL);
send_response_len_and_wait(20000, TRUE, &ib); avail = expect_data_available(req.request, -1); ok(avail <= 20000, "avail = %u\n", avail);
SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION); SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED); close_async_handle(req.session, 2); todo_wine CHECK_NOT_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION); todo_wine CHECK_NOT_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
open_read_test_request(port, &req, "HTTP/1.1 200 OK\r\n" "Server: winetest\r\n" "Connection: close\r\n" "\r\n" "123");
expect_data_available(req.request, 3); readex_expect_sync_data(req.request, 0, &ib, 3, "123", 0);
async_query_data_available(req.request, &read_size); send_response_and_wait("1234567890", FALSE, NULL, &read_size, NULL, 10, 10, 10);
readex_expect_sync_data(req.request, 0, &ib, 9, "123456789", 0); expect_data_available(req.request, 1); readex_expect_sync_data(req.request, 0, &ib, 1, "0", 0);
async_query_data_available(req.request, &read_size); send_response_and_wait("1234567890", FALSE, NULL, &read_size, NULL, 10, 10, 10); expect_data_available(req.request, 10); for(i = 0; i < 10; i++) server_send_string("x"); expect_data_available(req.request, 10);
readex_expect_async(req.request, IRF_ASYNC, &ib, 21, "1234567890"); send_response_ex_and_wait("X", FALSE, &ib, "1234567890xxxxxxxxxxX", 0, 11); async_query_data_available(req.request, &read_size);
SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION); SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED); send_response_and_wait(NULL, TRUE, NULL, &read_size, NULL, 0, 0, 0); CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION); CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
close_async_handle(req.session, 2);
skip_receive_notification_tests = FALSE;}
static void test_connection_break(int port){ INTERNET_BUFFERSW ib; test_request_t req; char buf[24000];
if(!is_ie7plus) return;
memset(&ib, 0, sizeof(ib)); ib.dwStructSize = sizeof(ib); ib.lpvBuffer = buf;
trace("Testing InternetReadFileExW on broken connection...\n");
open_read_test_request(port, &req, "HTTP/1.1 200 OK\r\n" "Server: winetest\r\n" "Content-Length: 10000\r\n" "\r\n" "xx");
/* close connection and make sure that it's closed on handle release. */ close_connection(); SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION); SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED); close_async_handle(req.session, 2); CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION); CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);}
static void test_long_url(int port){ char long_path[INTERNET_MAX_PATH_LENGTH*2] = "/echo_request?"; char buf[sizeof(long_path)*2], url[sizeof(buf)]; test_request_t req; DWORD size, len; BOOL ret;
if(!is_ie7plus) return;
memset(long_path+strlen(long_path), 'x', sizeof(long_path)-strlen(long_path)); long_path[sizeof(long_path)-1] = 0; open_simple_request(&req, "localhost", port, NULL, long_path);
ret = HttpSendRequestA(req.request, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed: %u\n", GetLastError()); test_status_code(req.request, 200);
receive_simple_request(req.request, buf, sizeof(buf)); ok(strstr(buf, long_path) != NULL, "long pathnot found in %s\n", buf);
sprintf(url, "http://localhost:%u%s", port, long_path);
size = sizeof(buf); ret = InternetQueryOptionA(req.request, INTERNET_OPTION_URL, buf, &size); ok(ret, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError()); len = strlen(url); ok(size == len, "size = %u, expected %u\n", size, len); ok(!strcmp(buf, url), "Wrong URL %s, expected %s\n", buf, url);
close_request(&req);}
static void test_persistent_connection(int port){ INTERNET_BUFFERSW ib; test_request_t req; char buf[24000];
if(!is_ie7plus) return;
memset(&ib, 0, sizeof(ib)); ib.dwStructSize = sizeof(ib); ib.lpvBuffer = buf;
skip_receive_notification_tests = TRUE;
trace("Testing persistent connection...\n");
open_read_test_request(port, &req, "HTTP/1.1 200 OK\r\n" "Server: winetest\r\n" "Content-Length: 2\r\n" "\r\n" "xx"); readex_expect_sync_data(req.request, IRF_ASYNC, &ib, 4, "xx", 0); close_async_handle(req.session, 2);
open_socket_request(port, &req, "/test_simple_chunked"); server_read_request("GET /test_simple_chunked HTTP/1.1");
SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE); server_send_string("HTTP/1.1 200 OK\r\n" "Server: winetest\r\n" "Transfer-Encoding: chunked\r\n" "\r\n" "2\r\nab\r\n"); WaitForSingleObject(complete_event, INFINITE); CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE); ok(req_error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %u\n", req_error);
readex_expect_sync_data(req.request, IRF_NO_WAIT, &ib, sizeof(buf), "ab", 0); readex_expect_async(req.request, IRF_ASYNC, &ib, sizeof(buf), NULL); send_response_ex_and_wait("3\r\nabc\r\n0\r\n\r\n", FALSE, &ib, "abc", 0, 13); close_async_handle(req.session, 2);
open_socket_request(port, &req, "/chunked"); server_read_request("GET /chunked HTTP/1.1");
SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE); server_send_string("HTTP/1.1 200 OK\r\n" "Server: winetest\r\n" "Transfer-Encoding: chunked\r\n" "\r\n" "2\r\nab\r\n"); WaitForSingleObject(complete_event, INFINITE); CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE); ok(req_error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %u\n", req_error);
readex_expect_sync_data(req.request, IRF_NO_WAIT, &ib, 3, "ab", 0); readex_expect_async(req.request, IRF_ASYNC, &ib, 3, NULL); send_response_ex_and_wait("3\r\nabc\r\n", FALSE, &ib, "abc", 0, 13);
/* send another request on the same request handle, it must drain remaining last chunk marker */ server_send_string("0\r\n\r\n");
send_socket_request(&req, FALSE); server_read_request("GET /chunked HTTP/1.1");
ResetEvent(complete_event); SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE); server_send_string("HTTP/1.1 201 OK\r\n" "Server: winetest\r\n" "Content-Length: 0\r\n" "Connection: keep-alive\r\n" "\r\n"); WaitForSingleObject(complete_event, INFINITE); CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE); ok(req_error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %u\n", req_error);
test_status_code(req.request, 201); close_async_handle(req.session, 2);
/* the connection is still valid */ open_socket_request(port, &req, "/another_chunked"); server_read_request("GET /another_chunked HTTP/1.1");
SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE); server_send_string("HTTP/1.1 200 OK\r\n" "Server: winetest\r\n" "Transfer-Encoding: chunked\r\n" "\r\n" "2\r\nab\r\n"); WaitForSingleObject(complete_event, INFINITE); CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE); ok(req_error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %u\n", req_error);
readex_expect_sync_data(req.request, IRF_NO_WAIT, &ib, sizeof(buf), "ab", 0); readex_expect_async(req.request, IRF_ASYNC, &ib, sizeof(buf), NULL);
/* we're missing trailing '\n'; the connection can't be drained without blocking, * so it will be closed */ send_response_ex_and_wait("3\r\nabc\r\n0\r\n\r", FALSE, &ib, "abc", 0, 13);
SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION); SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED); close_async_handle(req.session, 2); CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION); CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
close_connection(); skip_receive_notification_tests = FALSE;}
static void test_redirect(int port){ char buf[4000], expect_url[INTERNET_MAX_URL_LENGTH]; INTERNET_BUFFERSW ib; test_request_t req;
if(!is_ie7plus) return;
skip_receive_notification_tests = TRUE;
memset(&ib, 0, sizeof(ib)); ib.dwStructSize = sizeof(ib); ib.lpvBuffer = buf;
trace("Testing redirection...\n");
open_socket_request(port, &req, NULL);
SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT); SET_EXPECT(INTERNET_STATUS_REDIRECT); SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST); SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
server_send_string("HTTP/1.1 302 Found\r\n" "Server: winetest\r\n" "Location: test_redirection\r\n" "Connection: keep-alive\r\n" "Content-Length: 0\r\n" "\r\n");
server_read_request("GET /test_redirection HTTP/1.1");
CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
sprintf(expect_url, "http://localhost:%u/test_redirection", port); test_request_url(req.request, expect_url);
SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
server_send_string("HTTP/1.1 200 OK\r\n" "Server: winetest\r\n" "Content-Length: 3\r\n" "\r\n" "xxx");
WaitForSingleObject(complete_event, INFINITE);
CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT); CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT); CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT); CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE); ok(req_error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %u\n", req_error);
test_status_code(req.request, 200);
close_connection(); close_async_handle(req.session, 2);
trace("Test redirect to non-http URL...\n");
open_socket_request(port, &req, NULL);
SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
server_send_string("HTTP/1.1 302 Found\r\n" "Server: winetest\r\n" "Location: test:non:http/url\r\n" "Connection: keep-alive\r\n" "Content-Length: 0\r\n" "\r\n");
WaitForSingleObject(complete_event, INFINITE);
CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE); ok(req_error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %u\n", req_error);
sprintf(expect_url, "http://localhost:%u/socket", port); test_request_url(req.request, expect_url); test_status_code(req.request, 302);
close_connection(); close_async_handle(req.session, 2);
trace("Test redirect to http URL with no host name...\n");
open_socket_request(port, &req, NULL);
SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
server_send_string("HTTP/1.1 302 Found\r\n" "Server: winetest\r\n" "Location: http:///nohost\r\n" "Connection: keep-alive\r\n" "Content-Length: 0\r\n" "\r\n");
WaitForSingleObject(complete_event, INFINITE);
CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE); ok(req_error == ERROR_INTERNET_INVALID_URL, "expected ERROR_INTERNET_INVALID_URL, got %u\n", req_error);
sprintf(expect_url, "http://localhost:%u/socket", port); test_request_url(req.request, expect_url); test_status_code(req.request, 302);
close_connection(); close_async_handle(req.session, 2);
skip_receive_notification_tests = FALSE;}
static void test_remove_dot_segments(int port){ test_request_t req; BOOL ret;
open_simple_request(&req, "localhost", port, NULL, "/A/../B/./C/../../test_remove_dot_segments");
ret = HttpSendRequestA(req.request, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed: %u\n", GetLastError()); test_status_code(req.request, 200);
close_request(&req);}
struct large_test{ DWORD64 content_length; BOOL ret;};
static void test_large_content(int port){ struct large_test tests[] = { { 0, TRUE }, { UINT_MAX-1, TRUE }, { UINT_MAX, TRUE }, { (DWORD64)UINT_MAX+1, FALSE }, { ~0, FALSE }, }; test_request_t req; DWORD sizelen, len; DWORD read_size; DWORD64 len64; char buf[16]; BOOL ret; size_t i;
open_simple_request(&req, "localhost", port, "HEAD", "/test_large_content");
for (i = 0; i < ARRAY_SIZE(tests); i++) { content_length = tests[i].content_length; ret = HttpSendRequestA(req.request, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
len = ~0; sizelen = sizeof(len); SetLastError(0xdeadbeef); ret = HttpQueryInfoA(req.request, HTTP_QUERY_FLAG_NUMBER|HTTP_QUERY_CONTENT_LENGTH, &len, &sizelen, 0); if (tests[i].ret) { ok(ret, "HttpQueryInfo should have succeeded\n"); ok(GetLastError() == ERROR_SUCCESS || broken(GetLastError() == 0xdeadbeef), /* xp, 2k8, vista */ "expected ERROR_SUCCESS, got %x\n", GetLastError()); ok(len == (DWORD)tests[i].content_length, "expected %u, got %u\n", (DWORD)tests[i].content_length, len); } else { ok(!ret, "HttpQueryInfo should have failed\n"); ok(GetLastError() == ERROR_HTTP_INVALID_HEADER, "expected ERROR_HTTP_INVALID_HEADER, got %x\n", GetLastError()); ok(len == ~0, "expected ~0, got %u\n", len); } ok(sizelen == sizeof(DWORD), "sizelen %u\n", sizelen); }
/* test argument size */ len64 = ~0; sizelen = sizeof(len64); SetLastError(0xdeadbeef); ret = HttpQueryInfoA(req.request, HTTP_QUERY_FLAG_NUMBER|HTTP_QUERY_CONTENT_LENGTH, &len64, &len, 0); ok(!ret, "HttpQueryInfo should have failed\n"); ok(GetLastError() == ERROR_HTTP_INVALID_HEADER, "expected ERROR_HTTP_INVALID_HEADER, got %x\n", GetLastError()); ok(sizelen == sizeof(DWORD64), "sizelen %u\n", sizelen); ok(len64 == ~0, "len64 %x%08x\n", (DWORD)(len64 >> 32), (DWORD)len64);
close_request(&req);
/* test internal use of HttpQueryInfo on large size */ open_read_test_request(port, &req, "HTTP/1.1 200 OK\r\n" "Server: winetest\r\n" "Content-Length: 4294967296\r\n" "\r\n" "xx"); read_expect_async(req.request, buf, 4, &read_size, "xx"); send_response_and_wait("yy1234567890", FALSE, buf, &read_size, "xxyy", 4, 0, 2); read_expect_sync_data(req.request, buf, 10, "1234567890");
SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION); SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED); close_async_handle(req.session, 2); CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION); CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED); close_connection();}
static void test_http_connection(void){ struct server_info si; HANDLE hThread; DWORD id = 0, r;
si.hEvent = CreateEventW(NULL, 0, 0, NULL); si.port = 7531;
hThread = CreateThread(NULL, 0, server_thread, &si, 0, &id); ok( hThread != NULL, "create thread failed\n");
r = WaitForSingleObject(si.hEvent, 10000); ok (r == WAIT_OBJECT_0, "failed to start wininet test server\n"); if (r != WAIT_OBJECT_0) { CloseHandle(hThread); return; }
test_basic_request(si.port, "GET", "/test1"); test_proxy_indirect(si.port); test_proxy_direct(si.port); test_header_handling_order(si.port); test_basic_request(si.port, "POST", "/test5"); test_basic_request(si.port, "RPC_IN_DATA", "/test5"); test_basic_request(si.port, "RPC_OUT_DATA", "/test5"); test_basic_request(si.port, "GET", "/test6"); test_basic_request(si.port, "GET", "/testF"); test_connection_header(si.port); test_header_override(si.port); test_cookie_header(si.port); test_basic_authentication(si.port); test_invalid_response_headers(si.port); test_response_without_headers(si.port); test_HttpQueryInfo(si.port); test_HttpSendRequestW(si.port); test_options(si.port); test_no_content(si.port); test_conn_close(si.port); test_no_cache(si.port); test_cache_read_gzipped(si.port); test_http_status(si.port); test_premature_disconnect(si.port); test_connection_closing(si.port); test_cache_control_verb(si.port); test_successive_HttpSendRequest(si.port); test_head_request(si.port); test_request_content_length(si.port); test_accept_encoding(si.port); test_basic_auth_credentials_reuse(si.port); test_basic_auth_credentials_end_session(si.port); test_basic_auth_credentials_different(si.port); test_basic_auth_credentials_manual(si.port); test_basic_auth_credentials_cached_manual(si.port); test_async_read(si.port); test_http_read(si.port); test_connection_break(si.port); test_long_url(si.port);#ifdef __REACTOS__if (!winetest_interactive){ skip("Skipping test_redirect and test_persistent_connection due to hang. See ROSTESTS-294.\n");}else{#endif test_redirect(si.port); test_persistent_connection(si.port);#ifdef __REACTOS__}#endif test_remove_dot_segments(si.port); test_large_content(si.port);
/* send the basic request again to shutdown the server thread */ test_basic_request(si.port, "GET", "/quit");
r = WaitForSingleObject(hThread, 3000); ok( r == WAIT_OBJECT_0, "thread wait failed\n"); CloseHandle(hThread);}
static void release_cert_info(INTERNET_CERTIFICATE_INFOA *info){ LocalFree(info->lpszSubjectInfo); LocalFree(info->lpszIssuerInfo); LocalFree(info->lpszProtocolName); LocalFree(info->lpszSignatureAlgName); LocalFree(info->lpszEncryptionAlgName);}
typedef struct { const char *ex_subject; const char *ex_issuer;} cert_struct_test_t;
static const cert_struct_test_t test_winehq_org_cert = { "US\r\n" "55114\r\n" "Minnesota\r\n" "Saint Paul\r\n" "Ste 120\r\n" "700 Raymond Ave\r\n" "CodeWeavers\r\n" "IT\r\n" "*.winehq.org",
"US\r\n" "VA\r\n" "Herndon\r\n" "Network Solutions L.L.C.\r\n" "Network Solutions OV Server CA 2"};
static const cert_struct_test_t test_winehq_com_cert = { "US\r\n" "Minnesota\r\n" "Saint Paul\r\n" "WineHQ\r\n" "IT\r\n" "test.winehq.com\r\n" "webmaster@winehq.org",
"US\r\n" "Minnesota\r\n" "Saint Paul\r\n" "WineHQ\r\n" "IT\r\n" "test.winehq.com\r\n" "webmaster@winehq.org"};
static const char *cert_string_fmt = "Subject:\r\n%s\r\n" "Issuer:\r\n%s\r\n" "Effective Date:\t%s %s\r\n" "Expiration Date:\t%s %s\r\n" "Security Protocol:\t%s\r\n" "Signature Type:\t%s\r\n" "Encryption Type:\t%s\r\n" "Privacy Strength:\t%s (%u bits)";
static void test_cert_struct_string(HINTERNET req, const INTERNET_CERTIFICATE_INFOA *info){ SYSTEMTIME start, expiry; char expiry_date[32]; char expiry_time[32]; char start_date[32]; char start_time[32]; char expect[512]; char actual[512]; DWORD size; BOOL res;
size = sizeof(actual); SetLastError(0xdeadbeef); memset(actual, 0x55, sizeof(actual)); res = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_CERTIFICATE, actual, &size); ok(res, "InternetQueryOption failed: %u\n", GetLastError());
FileTimeToSystemTime(&info->ftStart, &start); FileTimeToSystemTime(&info->ftExpiry, &expiry);
GetDateFormatA(LOCALE_USER_DEFAULT, 0, &start, NULL, start_date, sizeof(start_date)); GetTimeFormatA(LOCALE_USER_DEFAULT, 0, &start, NULL, start_time, sizeof(start_time)); GetDateFormatA(LOCALE_USER_DEFAULT, 0, &expiry, NULL, expiry_date, sizeof(expiry_date)); GetTimeFormatA(LOCALE_USER_DEFAULT, 0, &expiry, NULL, expiry_time, sizeof(expiry_time));
snprintf(expect, sizeof(expect), cert_string_fmt, info->lpszSubjectInfo, info->lpszIssuerInfo, start_date, start_time, expiry_date, expiry_time, info->lpszSignatureAlgName, info->lpszEncryptionAlgName, info->lpszProtocolName, info->dwKeySize >= 128 ? "High" : "Low", info->dwKeySize); ok(size == strlen(actual), "size = %u\n", size); ok(!strcmp(actual, expect), "expected:\n%s\nactual:\n%s\n", expect, actual);
--size; SetLastError(0xdeadbeef); memset(actual, 0x55, sizeof(actual)); res = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_CERTIFICATE, actual, &size); ok(!res && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetQueryOption failed: %d\n", GetLastError()); ok(size == 1, "unexpected size: %u\n", size); ok(actual[0] == 0x55, "unexpected byte: %02x\n", actual[0]);}
static void test_cert_struct(HINTERNET req, const cert_struct_test_t *test){ INTERNET_CERTIFICATE_INFOA info; DWORD size; BOOL res;
memset(&info, 0x5, sizeof(info));
size = sizeof(info); res = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, &info, &size); if (!res) { win_skip("Querying INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT failed, skipping tests\n"); return; }
ok(res, "InternetQueryOption failed: %u\n", GetLastError()); ok(size == sizeof(info), "size = %u\n", size);
ok(!strcmp(info.lpszSubjectInfo, test->ex_subject), "lpszSubjectInfo = %s\n", info.lpszSubjectInfo); ok(!strcmp(info.lpszIssuerInfo, test->ex_issuer), "lpszIssuerInfo = %s\n", info.lpszIssuerInfo); ok(!info.lpszSignatureAlgName, "lpszSignatureAlgName = %s\n", info.lpszSignatureAlgName); ok(!info.lpszEncryptionAlgName, "lpszEncryptionAlgName = %s\n", info.lpszEncryptionAlgName); ok(!info.lpszProtocolName, "lpszProtocolName = %s\n", info.lpszProtocolName); ok(info.dwKeySize >= 128 && info.dwKeySize <= 256, "dwKeySize = %u\n", info.dwKeySize);
if (is_lang_english()) test_cert_struct_string(req, &info); else skip("Skipping tests that are English-only\n"); release_cert_info(&info);}
#define test_security_info(a,b,c) _test_security_info(__LINE__,a,b,c)static void _test_security_info(unsigned line, const char *urlc, DWORD error, DWORD ex_flags){ char url[INTERNET_MAX_URL_LENGTH]; const CERT_CHAIN_CONTEXT *chain; DWORD flags; BOOL res;
if(!pInternetGetSecurityInfoByURLA) { win_skip("pInternetGetSecurityInfoByURLA not available\n"); return; }
strcpy(url, urlc); chain = (void*)0xdeadbeef; flags = 0xdeadbeef; res = pInternetGetSecurityInfoByURLA(url, &chain, &flags); if(error == ERROR_SUCCESS) { ok_(__FILE__,line)(res, "InternetGetSecurityInfoByURLA failed: %u\n", GetLastError()); ok_(__FILE__,line)(chain != NULL, "chain = NULL\n"); ok_(__FILE__,line)(flags == ex_flags, "flags = %x\n", flags); CertFreeCertificateChain(chain);
SetLastError(0xdeadbeef); res = pInternetGetSecurityInfoByURLA(url, NULL, NULL); ok_(__FILE__,line)(!res && GetLastError() == ERROR_INVALID_PARAMETER, "InternetGetSecurityInfoByURLA returned: %x(%u)\n", res, GetLastError());
res = pInternetGetSecurityInfoByURLA(url, &chain, NULL); ok_(__FILE__,line)(res, "InternetGetSecurityInfoByURLA failed: %u\n", GetLastError()); CertFreeCertificateChain(chain);
res = pInternetGetSecurityInfoByURLA(url, NULL, &flags); ok_(__FILE__,line)(res, "InternetGetSecurityInfoByURLA failed: %u\n", GetLastError()); }else { ok_(__FILE__,line)(!res && GetLastError() == error, "InternetGetSecurityInfoByURLA returned: %x(%u), expected %u\n", res, GetLastError(), error); }}
#define test_secflags_option(a,b,c) _test_secflags_option(__LINE__,a,b,c)static void _test_secflags_option(unsigned line, HINTERNET req, DWORD ex_flags, DWORD opt_flags){ DWORD flags, size; BOOL res;
flags = 0xdeadbeef; size = sizeof(flags); res = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_FLAGS, &flags, &size); ok_(__FILE__,line)(res, "InternetQueryOptionW(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError()); ok_(__FILE__,line)((flags & ~opt_flags) == ex_flags, "INTERNET_OPTION_SECURITY_FLAGS flags = %x, expected %x\n", flags, ex_flags);
/* Option 98 is undocumented and seems to be the same as INTERNET_OPTION_SECURITY_FLAGS */ flags = 0xdeadbeef; size = sizeof(flags); res = InternetQueryOptionW(req, 98, &flags, &size); ok_(__FILE__,line)(res, "InternetQueryOptionW(98) failed: %u\n", GetLastError()); ok_(__FILE__,line)((flags & ~opt_flags) == ex_flags, "INTERNET_OPTION_SECURITY_FLAGS(98) flags = %x, expected %x\n", flags, ex_flags);}
#define set_secflags(a,b,c) _set_secflags(__LINE__,a,b,c)static void _set_secflags(unsigned line, HINTERNET req, BOOL use_undoc, DWORD flags){ BOOL res;
res = InternetSetOptionW(req, use_undoc ? 99 : INTERNET_OPTION_SECURITY_FLAGS, &flags, sizeof(flags)); ok_(__FILE__,line)(res, "InternetSetOption(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());}
static void test_security_flags(void){ INTERNET_CERTIFICATE_INFOA *cert; HINTERNET ses, conn, req; DWORD size, flags; char buf[512]; BOOL res;
if (!https_support) { win_skip("Can't make https connections, skipping security flags test\n"); return; }
trace("Testing security flags...\n"); reset_events();
ses = InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC); ok(ses != NULL, "InternetOpen failed\n");
pInternetSetStatusCallbackA(ses, &callback);
SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED); conn = InternetConnectA(ses, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, INTERNET_FLAG_SECURE, 0xdeadbeef); ok(conn != NULL, "InternetConnect failed with error %u\n", GetLastError()); CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED); req = HttpOpenRequestA(conn, "GET", "/tests/hello.html", NULL, NULL, NULL, INTERNET_FLAG_SECURE|INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE, 0xdeadbeef); ok(req != NULL, "HttpOpenRequest failed\n"); CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
flags = 0xdeadbeef; size = sizeof(flags); res = InternetQueryOptionW(req, 98, &flags, &size); if(!res && GetLastError() == ERROR_INVALID_PARAMETER) { win_skip("Incomplete security flags support, skipping\n");
close_async_handle(ses, 2); return; }
test_secflags_option(req, 0, 0); test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND, 0);
set_secflags(req, TRUE, SECURITY_FLAG_IGNORE_REVOCATION); test_secflags_option(req, SECURITY_FLAG_IGNORE_REVOCATION, 0);
set_secflags(req, TRUE, SECURITY_FLAG_IGNORE_CERT_CN_INVALID); test_secflags_option(req, SECURITY_FLAG_IGNORE_REVOCATION|SECURITY_FLAG_IGNORE_CERT_CN_INVALID, 0);
set_secflags(req, FALSE, SECURITY_FLAG_IGNORE_UNKNOWN_CA); test_secflags_option(req, SECURITY_FLAG_IGNORE_UNKNOWN_CA|SECURITY_FLAG_IGNORE_REVOCATION|SECURITY_FLAG_IGNORE_CERT_CN_INVALID, 0);
flags = SECURITY_FLAG_IGNORE_CERT_CN_INVALID|SECURITY_FLAG_SECURE; res = InternetSetOptionW(req, 99, &flags, sizeof(flags)); ok(!res && GetLastError() == ERROR_INTERNET_OPTION_NOT_SETTABLE, "InternetSetOption(99) failed: %u\n", GetLastError());
SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME); SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED); SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER); SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER); SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION); /* IE11 calls it, it probably reconnects. */ SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED); /* IE11 */ SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER); /* IE11 */ SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER); /* IE11 */ SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST); SET_EXPECT(INTERNET_STATUS_REQUEST_SENT); SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE); SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED); SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE); SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY); SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
res = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
WaitForSingleObject(complete_event, INFINITE); ok(req_error == ERROR_SUCCESS, "req_error = %d\n", req_error);
CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME); CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED); CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER, 2); CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER, 2); CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION); CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED); CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST); CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT); CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE); CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED); CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE); CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY); CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
test_request_flags(req, 0); test_secflags_option(req, SECURITY_FLAG_SECURE|SECURITY_FLAG_IGNORE_UNKNOWN_CA |SECURITY_FLAG_IGNORE_REVOCATION|SECURITY_FLAG_IGNORE_CERT_CN_INVALID|SECURITY_FLAG_STRENGTH_STRONG, 0);
res = InternetReadFile(req, buf, sizeof(buf), &size); ok(res, "InternetReadFile failed: %u\n", GetLastError()); ok(size, "size = 0\n");
/* Collect all existing persistent connections */ res = InternetSetOptionA(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0); ok(res, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED); req = HttpOpenRequestA(conn, "GET", "/tests/hello.html", NULL, NULL, NULL, INTERNET_FLAG_SECURE|INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE, 0xdeadbeef); ok(req != NULL, "HttpOpenRequest failed\n"); CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
flags = INTERNET_ERROR_MASK_COMBINED_SEC_CERT|INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY; res = InternetSetOptionA(req, INTERNET_OPTION_ERROR_MASK, (void*)&flags, sizeof(flags)); ok(res, "InternetQueryOption(INTERNET_OPTION_ERROR_MASK failed: %u\n", GetLastError());
SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER); SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER); SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION); /* IE11 calls it, it probably reconnects. */ SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED); /* IE11 */ SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER); /* IE11 */ SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER); /* IE11 */ SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION); SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED); SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE); SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT); SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
res = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
WaitForSingleObject(complete_event, INFINITE); ok(req_error == ERROR_INTERNET_SEC_CERT_ERRORS, "req_error = %d\n", req_error);
size = 0; res = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, NULL, &size); ok(res || GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetQueryOption failed: %d\n", GetLastError()); ok(size == sizeof(INTERNET_CERTIFICATE_INFOA), "size = %u\n", size); cert = HeapAlloc(GetProcessHeap(), 0, size); cert->lpszSubjectInfo = NULL; cert->lpszIssuerInfo = NULL; cert->lpszSignatureAlgName = (char *)0xdeadbeef; cert->lpszEncryptionAlgName = (char *)0xdeadbeef; cert->lpszProtocolName = (char *)0xdeadbeef; cert->dwKeySize = 0xdeadbeef; res = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, cert, &size); ok(res, "InternetQueryOption failed: %u\n", GetLastError()); if (res) { ok(cert->lpszSubjectInfo && strlen(cert->lpszSubjectInfo) > 1, "expected a non-empty subject name\n"); ok(cert->lpszIssuerInfo && strlen(cert->lpszIssuerInfo) > 1, "expected a non-empty issuer name\n"); ok(!cert->lpszSignatureAlgName, "unexpected signature algorithm name\n"); ok(!cert->lpszEncryptionAlgName, "unexpected encryption algorithm name\n"); ok(!cert->lpszProtocolName, "unexpected protocol name\n"); ok(cert->dwKeySize != 0xdeadbeef, "unexpected key size\n");
LocalFree(cert->lpszSubjectInfo); LocalFree(cert->lpszIssuerInfo); } HeapFree(GetProcessHeap(), 0, cert);
SetLastError(0xdeadbeef); res = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE, NULL, NULL); ok(!res && GetLastError() == ERROR_INVALID_PARAMETER, "InternetQueryOption failed: %d\n", GetLastError());
size = 0; SetLastError(0xdeadbeef); res = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE, NULL, &size); ok(!res && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetQueryOption failed: %d\n", GetLastError()); ok(size == 1, "unexpected size: %u\n", size);
size = 42; SetLastError(0xdeadbeef); memset(buf, 0x55, sizeof(buf)); res = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE, buf, &size); ok(!res && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetQueryOption failed: %d\n", GetLastError()); ok(size == 1, "unexpected size: %u\n", size); ok(buf[0] == 0x55, "unexpected byte: %02x\n", buf[0]);
size = sizeof(buf); SetLastError(0xdeadbeef); res = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE, buf, &size); ok(res && GetLastError() == ERROR_SUCCESS, "InternetQueryOption failed: %d\n", GetLastError()); ok(size < sizeof(buf), "unexpected size: %u\n", size);
ros_skip_flaky CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER, 2); CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER, 2); CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION, 2); CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED, 2); CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE); CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT); CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
if(req_error != ERROR_INTERNET_SEC_CERT_ERRORS) { win_skip("Unexpected cert errors %u, skipping security flags tests\n", req_error);
close_async_handle(ses, 3); return; }
size = sizeof(buf); res = HttpQueryInfoA(req, HTTP_QUERY_CONTENT_ENCODING, buf, &size, 0); ok(!res && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "HttpQueryInfoA(HTTP_QUERY_CONTENT_ENCODING) failed: %u\n", GetLastError());
test_request_flags(req, 8); /* IE11 finds both rev failure and invalid CA. Previous versions required rev failure to be ignored before invalid CA was reported. */ test_secflags_option(req, _SECURITY_FLAG_CERT_INVALID_CA, _SECURITY_FLAG_CERT_REV_FAILED);
set_secflags(req, FALSE, SECURITY_FLAG_IGNORE_REVOCATION); test_secflags_option(req, _SECURITY_FLAG_CERT_INVALID_CA|SECURITY_FLAG_IGNORE_REVOCATION, _SECURITY_FLAG_CERT_REV_FAILED);
SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER); SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER); SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION); SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED); SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE); SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT); SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
res = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
WaitForSingleObject(complete_event, INFINITE); ok(req_error == ERROR_INTERNET_INVALID_CA || req_error == ERROR_INTERNET_SEC_CERT_ERRORS, "req_error = %d\n", req_error);
CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER); CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER); CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION); CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED); CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE); CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT); CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
test_request_flags(req, INTERNET_REQFLAG_NO_HEADERS); test_secflags_option(req, SECURITY_FLAG_IGNORE_REVOCATION|_SECURITY_FLAG_CERT_INVALID_CA, 0); test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND, 0);
set_secflags(req, FALSE, SECURITY_FLAG_IGNORE_UNKNOWN_CA); test_secflags_option(req, _SECURITY_FLAG_CERT_INVALID_CA |SECURITY_FLAG_IGNORE_REVOCATION|SECURITY_FLAG_IGNORE_UNKNOWN_CA, 0); test_http_version(req);
SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER); SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER); SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION); /* IE11 calls it, it probably reconnects. */ SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED); /* IE11 */ SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER); /* IE11 */ SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER); /* IE11 */ SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST); SET_EXPECT(INTERNET_STATUS_REQUEST_SENT); SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE); SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED); SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE); SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT); SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
res = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
WaitForSingleObject(complete_event, INFINITE); ok(req_error == ERROR_SUCCESS, "req_error = %d\n", req_error);
CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER, 2); CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER, 2); CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION); CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED); CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST); CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT); CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE); CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED); CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE); CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT); CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
test_request_flags(req, 0); test_secflags_option(req, SECURITY_FLAG_SECURE|SECURITY_FLAG_IGNORE_UNKNOWN_CA|SECURITY_FLAG_IGNORE_REVOCATION |SECURITY_FLAG_STRENGTH_STRONG|_SECURITY_FLAG_CERT_INVALID_CA, 0);
test_cert_struct(req, &test_winehq_com_cert); test_security_info("https://test.winehq.com/data/some_file.html?q", 0, _SECURITY_FLAG_CERT_INVALID_CA);
res = InternetReadFile(req, buf, sizeof(buf), &size); ok(res, "InternetReadFile failed: %u\n", GetLastError()); ok(size, "size = 0\n");
close_async_handle(ses, 3);
/* Collect all existing persistent connections */ res = InternetSetOptionA(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0); ok(res, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
/* Make another request, without setting security flags */
ses = InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC); ok(ses != NULL, "InternetOpen failed\n");
pInternetSetStatusCallbackA(ses, &callback);
SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED); conn = InternetConnectA(ses, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, INTERNET_FLAG_SECURE, 0xdeadbeef); ok(conn != NULL, "InternetConnect failed with error %u\n", GetLastError()); CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED); req = HttpOpenRequestA(conn, "GET", "/tests/hello.html", NULL, NULL, NULL, INTERNET_FLAG_SECURE|INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE, 0xdeadbeef); ok(req != NULL, "HttpOpenRequest failed\n"); CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
test_secflags_option(req, SECURITY_FLAG_SECURE|SECURITY_FLAG_IGNORE_UNKNOWN_CA|SECURITY_FLAG_STRENGTH_STRONG |SECURITY_FLAG_IGNORE_REVOCATION|_SECURITY_FLAG_CERT_INVALID_CA, 0); test_http_version(req);
SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER); SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER); SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION); /* IE11 calls it, it probably reconnects. */ SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED); /* IE11 */ SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER); /* IE11 */ SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER); /* IE11 */ SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST); SET_EXPECT(INTERNET_STATUS_REQUEST_SENT); SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE); SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED); SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE); SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
res = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
WaitForSingleObject(complete_event, INFINITE); ok(req_error == ERROR_SUCCESS, "req_error = %d\n", req_error);
CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER, 2); CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER, 2); CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION); CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED); CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST); CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT); CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE); CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED); CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE); CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
test_request_flags(req, 0); test_secflags_option(req, SECURITY_FLAG_SECURE|SECURITY_FLAG_IGNORE_UNKNOWN_CA|SECURITY_FLAG_STRENGTH_STRONG |SECURITY_FLAG_IGNORE_REVOCATION|_SECURITY_FLAG_CERT_INVALID_CA, 0);
res = InternetReadFile(req, buf, sizeof(buf), &size); ok(res, "InternetReadFile failed: %u\n", GetLastError()); ok(size, "size = 0\n");
close_async_handle(ses, 2);
test_security_info("http://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND, 0); test_security_info("file:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND, 0); test_security_info("xxx:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND, 0);}
static void test_secure_connection(void){ static const WCHAR gizmo5[] = {'G','i','z','m','o','5',0}; static const WCHAR testsite[] = {'t','e','s','t','.','w','i','n','e','h','q','.','o','r','g',0}; static const WCHAR get[] = {'G','E','T',0}; static const WCHAR testpage[] = {'/','t','e','s','t','s','/','h','e','l','l','o','.','h','t','m','l',0}; HINTERNET ses, con, req; DWORD size, size2, flags, err; INTERNET_CERTIFICATE_INFOA *certificate_structA = NULL; INTERNET_CERTIFICATE_INFOW *certificate_structW = NULL; char certstr1[512], certstr2[512]; BOOL ret;
ses = InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); ok(ses != NULL, "InternetOpen failed\n");
con = InternetConnectA(ses, "test.winehq.org", INTERNET_DEFAULT_HTTPS_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); ok(con != NULL, "InternetConnect failed\n");
req = HttpOpenRequestA(con, "GET", "/tests/hello.html", NULL, NULL, NULL, INTERNET_FLAG_SECURE, 0); ok(req != NULL, "HttpOpenRequest failed\n");
ret = HttpSendRequestA(req, NULL, 0, NULL, 0); err = GetLastError(); ok(ret || broken(err == ERROR_INTERNET_CANNOT_CONNECT) || broken(err == ERROR_INTERNET_SECURITY_CHANNEL_ERROR), "HttpSendRequest failed: %u\n", err); if (!ret) { win_skip("Cannot connect to https.\n"); if (err == ERROR_INTERNET_SECURITY_CHANNEL_ERROR) https_support = FALSE; goto done; }
size = sizeof(flags); ret = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_FLAGS, &flags, &size); ok(ret, "InternetQueryOption failed: %d\n", GetLastError()); ok(flags & SECURITY_FLAG_SECURE, "expected secure flag to be set\n");
test_cert_struct(req, &test_winehq_org_cert);
/* Querying the same option through InternetQueryOptionW still results in * ASCII strings being returned. */ size = 0; ret = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, NULL, &size); ok(ret || GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetQueryOption failed: %d\n", GetLastError()); ok(size == sizeof(INTERNET_CERTIFICATE_INFOW), "size = %d\n", size); certificate_structW = HeapAlloc(GetProcessHeap(), 0, size); ret = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, certificate_structW, &size); certificate_structA = (INTERNET_CERTIFICATE_INFOA *)certificate_structW; ok(ret, "InternetQueryOption failed: %d\n", GetLastError()); if (ret) { ok(certificate_structA->lpszSubjectInfo && strlen(certificate_structA->lpszSubjectInfo) > 1, "expected a non-empty subject name\n"); ok(certificate_structA->lpszIssuerInfo && strlen(certificate_structA->lpszIssuerInfo) > 1, "expected a non-empty issuer name\n"); ok(!certificate_structA->lpszSignatureAlgName, "unexpected signature algorithm name\n"); ok(!certificate_structA->lpszEncryptionAlgName, "unexpected encryption algorithm name\n"); ok(!certificate_structA->lpszProtocolName, "unexpected protocol name\n"); ok(certificate_structA->dwKeySize, "expected a non-zero key size\n"); release_cert_info(certificate_structA); } HeapFree(GetProcessHeap(), 0, certificate_structW);
SetLastError(0xdeadbeef); size = sizeof(certstr1); ret = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE, certstr1, &size); ok(ret && GetLastError() == ERROR_SUCCESS, "InternetQueryOption failed: %d\n", GetLastError());
SetLastError(0xdeadbeef); size2 = sizeof(certstr2); ret = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_CERTIFICATE, certstr2, &size2); ok(ret && GetLastError() == ERROR_SUCCESS, "InternetQueryOption failed: %d\n", GetLastError());
ok(size == size2, "expected same size\n"); ok(!strcmp(certstr1, certstr2), "expected same string\n");
InternetCloseHandle(req); InternetCloseHandle(con); InternetCloseHandle(ses);
/* Repeating the tests with the W functions has the same result: */ ses = InternetOpenW(gizmo5, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); ok(ses != NULL, "InternetOpen failed\n");
con = InternetConnectW(ses, testsite, INTERNET_DEFAULT_HTTPS_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); ok(con != NULL, "InternetConnect failed\n");
req = HttpOpenRequestW(con, get, testpage, NULL, NULL, NULL, INTERNET_FLAG_SECURE|INTERNET_FLAG_RELOAD, 0); ok(req != NULL, "HttpOpenRequest failed\n");
ret = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed: %d\n", GetLastError());
size = sizeof(flags); ret = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_FLAGS, &flags, &size); ok(ret, "InternetQueryOption failed: %d\n", GetLastError()); ok(flags & SECURITY_FLAG_SECURE, "expected secure flag to be set, got %x\n", flags);
ret = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, NULL, &size); ok(ret || GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetQueryOption failed: %d\n", GetLastError()); ok(size == sizeof(INTERNET_CERTIFICATE_INFOA), "size = %d\n", size); certificate_structA = HeapAlloc(GetProcessHeap(), 0, size); ret = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, certificate_structA, &size); ok(ret, "InternetQueryOption failed: %d\n", GetLastError()); if (ret) { ok(certificate_structA->lpszSubjectInfo && strlen(certificate_structA->lpszSubjectInfo) > 1, "expected a non-empty subject name\n"); ok(certificate_structA->lpszIssuerInfo && strlen(certificate_structA->lpszIssuerInfo) > 1, "expected a non-empty issuer name\n"); ok(!certificate_structA->lpszSignatureAlgName, "unexpected signature algorithm name\n"); ok(!certificate_structA->lpszEncryptionAlgName, "unexpected encryption algorithm name\n"); ok(!certificate_structA->lpszProtocolName, "unexpected protocol name\n"); ok(certificate_structA->dwKeySize, "expected a non-zero key size\n"); release_cert_info(certificate_structA); } HeapFree(GetProcessHeap(), 0, certificate_structA);
/* Again, querying the same option through InternetQueryOptionW still * results in ASCII strings being returned. */ size = 0; ret = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, NULL, &size); ok(ret || GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetQueryOption failed: %d\n", GetLastError()); ok(size == sizeof(INTERNET_CERTIFICATE_INFOW), "size = %d\n", size); certificate_structW = HeapAlloc(GetProcessHeap(), 0, size); ret = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, certificate_structW, &size); certificate_structA = (INTERNET_CERTIFICATE_INFOA *)certificate_structW; ok(ret, "InternetQueryOption failed: %d\n", GetLastError()); if (ret) { ok(certificate_structA->lpszSubjectInfo && strlen(certificate_structA->lpszSubjectInfo) > 1, "expected a non-empty subject name\n"); ok(certificate_structA->lpszIssuerInfo && strlen(certificate_structA->lpszIssuerInfo) > 1, "expected a non-empty issuer name\n"); ok(!certificate_structA->lpszSignatureAlgName, "unexpected signature algorithm name\n"); ok(!certificate_structA->lpszEncryptionAlgName, "unexpected encryption algorithm name\n"); ok(!certificate_structA->lpszProtocolName, "unexpected protocol name\n"); ok(certificate_structA->dwKeySize, "expected a non-zero key size\n"); release_cert_info(certificate_structA); } HeapFree(GetProcessHeap(), 0, certificate_structW);
done: InternetCloseHandle(req); InternetCloseHandle(con); InternetCloseHandle(ses);}
static void test_user_agent_header(void){ HINTERNET ses, con, req; DWORD size, err; char buffer[64]; BOOL ret;
ses = InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); ok(ses != NULL, "InternetOpen failed\n");
con = InternetConnectA(ses, "test.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); ok(con != NULL, "InternetConnect failed\n");
req = HttpOpenRequestA(con, "GET", "/tests/hello.html", "HTTP/1.0", NULL, NULL, 0, 0); ok(req != NULL, "HttpOpenRequest failed\n");
size = sizeof(buffer); ret = HttpQueryInfoA(req, HTTP_QUERY_USER_AGENT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL); err = GetLastError(); ok(!ret, "HttpQueryInfo succeeded\n"); ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err);
ret = HttpAddRequestHeadersA(req, "User-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW); ok(ret, "HttpAddRequestHeaders succeeded\n");
size = sizeof(buffer); ret = HttpQueryInfoA(req, HTTP_QUERY_USER_AGENT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL); err = GetLastError(); ok(ret, "HttpQueryInfo failed\n");
InternetCloseHandle(req);
req = HttpOpenRequestA(con, "GET", "/", "HTTP/1.0", NULL, NULL, 0, 0); ok(req != NULL, "HttpOpenRequest failed\n");
size = sizeof(buffer); ret = HttpQueryInfoA(req, HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL); err = GetLastError(); ok(!ret, "HttpQueryInfo succeeded\n"); ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err);
ret = HttpAddRequestHeadersA(req, "Accept: audio/*, image/*, text/*\r\nUser-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW); ok(ret, "HttpAddRequestHeaders failed\n");
buffer[0] = 0; size = sizeof(buffer); ret = HttpQueryInfoA(req, HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL); ok(ret, "HttpQueryInfo failed: %u\n", GetLastError()); ok(!strcmp(buffer, "audio/*, image/*, text/*"), "got '%s' expected 'audio/*, image/*, text/*'\n", buffer);
InternetCloseHandle(req); InternetCloseHandle(con); InternetCloseHandle(ses);}
static void test_bogus_accept_types_array(void){ HINTERNET ses, con, req; static const char *types[] = { (const char *)6240, "*/*", "%p", "", (const char *)0xffffffff, "*/*", NULL }; DWORD size, error; char buffer[32]; BOOL ret;
ses = InternetOpenA("MERONG(0.9/;p)", INTERNET_OPEN_TYPE_DIRECT, "", "", 0); con = InternetConnectA(ses, "www.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); req = HttpOpenRequestA(con, "POST", "/post/post_action.php", "HTTP/1.0", "", types, INTERNET_FLAG_FORMS_SUBMIT, 0);
ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
buffer[0] = 0; size = sizeof(buffer); SetLastError(0xdeadbeef); ret = HttpQueryInfoA(req, HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL); error = GetLastError(); ok(!ret || broken(ret), "HttpQueryInfo succeeded\n"); if (!ret) ok(error == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", error); ok(broken(!strcmp(buffer, ", */*, %p, , , */*")) /* IE6 */ || broken(!strcmp(buffer, "*/*, %p, */*")) /* IE7/8 */ || !strcmp(buffer, ""), "got '%s' expected ''\n", buffer);
InternetCloseHandle(req); InternetCloseHandle(con); InternetCloseHandle(ses);}
struct context{ HANDLE event; HINTERNET req;};
static void WINAPI cb(HINTERNET handle, DWORD_PTR context, DWORD status, LPVOID info, DWORD size){ INTERNET_ASYNC_RESULT *result = info; struct context *ctx = (struct context *)context;
if(winetest_debug > 1) trace("%p 0x%08lx %u %p 0x%08x\n", handle, context, status, info, size);
switch(status) { case INTERNET_STATUS_REQUEST_COMPLETE: trace("request handle: 0x%08lx\n", result->dwResult); ctx->req = (HINTERNET)result->dwResult; SetEvent(ctx->event); break; case INTERNET_STATUS_HANDLE_CLOSING: { DWORD type = INTERNET_HANDLE_TYPE_CONNECT_HTTP, size = sizeof(type);
if (InternetQueryOptionA(handle, INTERNET_OPTION_HANDLE_TYPE, &type, &size)) ok(type != INTERNET_HANDLE_TYPE_CONNECT_HTTP, "unexpected callback\n"); SetEvent(ctx->event); break; } case INTERNET_STATUS_NAME_RESOLVED: case INTERNET_STATUS_CONNECTING_TO_SERVER: case INTERNET_STATUS_CONNECTED_TO_SERVER: { char *str = info; ok(str[0] && str[1], "Got string: %s\n", str); ok(size == strlen(str)+1, "unexpected size %u\n", size); } }}
static void test_open_url_async(void){ BOOL ret; HINTERNET ses, req; DWORD size, error; struct context ctx; ULONG type;
/* Collect all existing persistent connections */ ret = InternetSetOptionA(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0); ok(ret, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
/* * Some versions of IE6 fail those tests. They pass some notification data as UNICODE string, while * other versions never do. They also hang of following tests. We disable it for everything older * than IE7. */ if(!is_ie7plus) return;
ctx.req = NULL; ctx.event = CreateEventA(NULL, TRUE, FALSE, "Z:_home_hans_jaman-installer.exe_ev1");
ses = InternetOpenA("AdvancedInstaller", 0, NULL, NULL, INTERNET_FLAG_ASYNC); ok(ses != NULL, "InternetOpen failed\n");
SetLastError(0xdeadbeef); ret = InternetSetOptionA(NULL, INTERNET_OPTION_CALLBACK, &cb, sizeof(DWORD_PTR)); error = GetLastError(); ok(!ret, "InternetSetOptionA succeeded\n"); ok(error == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "got %u expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE\n", error);
ret = InternetSetOptionA(ses, INTERNET_OPTION_CALLBACK, &cb, sizeof(DWORD_PTR)); error = GetLastError(); ok(!ret, "InternetSetOptionA failed\n"); ok(error == ERROR_INTERNET_OPTION_NOT_SETTABLE, "got %u expected ERROR_INTERNET_OPTION_NOT_SETTABLE\n", error);
pInternetSetStatusCallbackW(ses, cb); ResetEvent(ctx.event);
req = InternetOpenUrlA(ses, "http://test.winehq.org", NULL, 0, 0, (DWORD_PTR)&ctx); ok(!req && GetLastError() == ERROR_IO_PENDING, "InternetOpenUrl failed\n");
WaitForSingleObject(ctx.event, INFINITE);
type = 0; size = sizeof(type); ret = InternetQueryOptionA(ctx.req, INTERNET_OPTION_HANDLE_TYPE, &type, &size); ok(ret, "InternetQueryOption failed: %u\n", GetLastError()); ok(type == INTERNET_HANDLE_TYPE_HTTP_REQUEST, "expected INTERNET_HANDLE_TYPE_HTTP_REQUEST, got %u\n", type);
size = 0; ret = HttpQueryInfoA(ctx.req, HTTP_QUERY_RAW_HEADERS_CRLF, NULL, &size, NULL); ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "HttpQueryInfo failed\n"); ok(size > 0, "expected size > 0\n");
ResetEvent(ctx.event); InternetCloseHandle(ctx.req); WaitForSingleObject(ctx.event, INFINITE);
InternetCloseHandle(ses); CloseHandle(ctx.event);}
enum api{ internet_connect = 1, http_open_request, http_send_request_ex, internet_writefile, http_end_request, internet_close_handle};
struct notification{ enum api function; /* api responsible for notification */ unsigned int status; /* status received */ BOOL async; /* delivered from another thread? */ BOOL todo; BOOL optional;};
struct info{ enum api function; const struct notification *test; unsigned int count; unsigned int index; HANDLE wait; DWORD thread; unsigned int line; DWORD expect_result; BOOL is_aborted;};
static CRITICAL_SECTION notification_cs;
static void CALLBACK check_notification( HINTERNET handle, DWORD_PTR context, DWORD status, LPVOID buffer, DWORD buflen ){ BOOL status_ok, function_ok; struct info *info = (struct info *)context; unsigned int i;
EnterCriticalSection( ¬ification_cs );
if(info->is_aborted) { LeaveCriticalSection(¬ification_cs); return; }
if (status == INTERNET_STATUS_HANDLE_CREATED) { DWORD size = sizeof(struct info *); HttpQueryInfoA( handle, INTERNET_OPTION_CONTEXT_VALUE, &info, &size, 0 ); }else if(status == INTERNET_STATUS_REQUEST_COMPLETE) { INTERNET_ASYNC_RESULT *ar = (INTERNET_ASYNC_RESULT*)buffer;
ok(buflen == sizeof(*ar), "unexpected buflen = %d\n", buflen); if(info->expect_result == ERROR_SUCCESS) { ok(ar->dwResult == 1, "ar->dwResult = %ld, expected 1\n", ar->dwResult); }else { ok(!ar->dwResult, "ar->dwResult = %ld, expected 1\n", ar->dwResult); ok(ar->dwError == info->expect_result, "ar->dwError = %d, expected %d\n", ar->dwError, info->expect_result); } }
i = info->index; if (i >= info->count) { LeaveCriticalSection( ¬ification_cs ); return; }
while (info->test[i].status != status && (info->test[i].optional || info->test[i].todo) && i < info->count - 1 && info->test[i].function == info->test[i + 1].function) { i++; }
status_ok = (info->test[i].status == status); function_ok = (info->test[i].function == info->function);
if (!info->test[i].todo) { ok( status_ok, "%u: expected status %u got %u\n", info->line, info->test[i].status, status ); ok( function_ok, "%u: expected function %u got %u\n", info->line, info->test[i].function, info->function );
if (info->test[i].async) ok(info->thread != GetCurrentThreadId(), "%u: expected thread %u got %u\n", info->line, info->thread, GetCurrentThreadId()); } else { todo_wine ok( status_ok, "%u: expected status %u got %u\n", info->line, info->test[i].status, status ); if (status_ok) todo_wine ok( function_ok, "%u: expected function %u got %u\n", info->line, info->test[i].function, info->function ); } if (i == info->count - 1 || info->test[i].function != info->test[i + 1].function) SetEvent( info->wait ); info->index = i+1;
LeaveCriticalSection( ¬ification_cs );}
static void setup_test( struct info *info, enum api function, unsigned int line, DWORD expect_result ){ info->function = function; info->line = line; info->expect_result = expect_result;}
struct notification_data{ const struct notification *test; const unsigned int count; const char *method; const char *host; const char *path; const char *data; BOOL expect_conn_failure;};
static const struct notification async_send_request_ex_test[] ={ { internet_connect, INTERNET_STATUS_HANDLE_CREATED, FALSE }, { http_open_request, INTERNET_STATUS_HANDLE_CREATED, FALSE }, { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, TRUE, FALSE, TRUE }, { http_send_request_ex, INTERNET_STATUS_COOKIE_SENT, TRUE, FALSE, TRUE }, { http_send_request_ex, INTERNET_STATUS_RESOLVING_NAME, TRUE, FALSE, TRUE }, { http_send_request_ex, INTERNET_STATUS_NAME_RESOLVED, TRUE, FALSE, TRUE }, { http_send_request_ex, INTERNET_STATUS_CONNECTING_TO_SERVER, TRUE }, { http_send_request_ex, INTERNET_STATUS_CONNECTED_TO_SERVER, TRUE }, { http_send_request_ex, INTERNET_STATUS_SENDING_REQUEST, TRUE }, { http_send_request_ex, INTERNET_STATUS_REQUEST_SENT, TRUE }, { http_send_request_ex, INTERNET_STATUS_REQUEST_COMPLETE, TRUE }, { internet_writefile, INTERNET_STATUS_SENDING_REQUEST, FALSE }, { internet_writefile, INTERNET_STATUS_REQUEST_SENT, FALSE }, { http_end_request, INTERNET_STATUS_RECEIVING_RESPONSE, TRUE }, { http_end_request, INTERNET_STATUS_RESPONSE_RECEIVED, TRUE }, { http_end_request, INTERNET_STATUS_REQUEST_COMPLETE, TRUE }, { internet_close_handle, INTERNET_STATUS_CLOSING_CONNECTION, FALSE, FALSE, TRUE }, { internet_close_handle, INTERNET_STATUS_CONNECTION_CLOSED, FALSE, FALSE, TRUE }, { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, FALSE, }, { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, FALSE, }};
static const struct notification async_send_request_ex_test2[] ={ { internet_connect, INTERNET_STATUS_HANDLE_CREATED, FALSE }, { http_open_request, INTERNET_STATUS_HANDLE_CREATED, FALSE }, { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, TRUE, FALSE, TRUE }, { http_send_request_ex, INTERNET_STATUS_COOKIE_SENT, TRUE, FALSE, TRUE }, { http_send_request_ex, INTERNET_STATUS_RESOLVING_NAME, TRUE, FALSE, TRUE }, { http_send_request_ex, INTERNET_STATUS_NAME_RESOLVED, TRUE, FALSE, TRUE }, { http_send_request_ex, INTERNET_STATUS_CONNECTING_TO_SERVER, TRUE, TRUE }, { http_send_request_ex, INTERNET_STATUS_CONNECTED_TO_SERVER, TRUE, TRUE }, { http_send_request_ex, INTERNET_STATUS_SENDING_REQUEST, TRUE }, { http_send_request_ex, INTERNET_STATUS_REQUEST_SENT, TRUE }, { http_send_request_ex, INTERNET_STATUS_REQUEST_COMPLETE, TRUE }, { http_end_request, INTERNET_STATUS_RECEIVING_RESPONSE, TRUE }, { http_end_request, INTERNET_STATUS_RESPONSE_RECEIVED, TRUE }, { http_end_request, INTERNET_STATUS_REQUEST_COMPLETE, TRUE }, { internet_close_handle, INTERNET_STATUS_CLOSING_CONNECTION, FALSE, FALSE, TRUE }, { internet_close_handle, INTERNET_STATUS_CONNECTION_CLOSED, FALSE, FALSE, TRUE }, { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, FALSE, }, { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, FALSE, }};
static const struct notification async_send_request_ex_resolve_failure_test[] ={ { internet_connect, INTERNET_STATUS_HANDLE_CREATED, FALSE }, { http_open_request, INTERNET_STATUS_HANDLE_CREATED, FALSE }, { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, TRUE, FALSE, TRUE }, { http_send_request_ex, INTERNET_STATUS_RESOLVING_NAME, TRUE }, { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, TRUE, FALSE, TRUE }, { http_send_request_ex, INTERNET_STATUS_REQUEST_COMPLETE, TRUE }, { http_end_request, INTERNET_STATUS_REQUEST_COMPLETE, TRUE }, { internet_close_handle, INTERNET_STATUS_CLOSING_CONNECTION, FALSE, FALSE, TRUE }, { internet_close_handle, INTERNET_STATUS_CONNECTION_CLOSED, FALSE, FALSE, TRUE }, { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, FALSE, }, { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, FALSE, }};
static const struct notification async_send_request_ex_chunked_test[] ={ { internet_connect, INTERNET_STATUS_HANDLE_CREATED }, { http_open_request, INTERNET_STATUS_HANDLE_CREATED }, { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, TRUE, FALSE, TRUE }, { http_send_request_ex, INTERNET_STATUS_COOKIE_SENT, TRUE, FALSE, TRUE }, { http_send_request_ex, INTERNET_STATUS_RESOLVING_NAME, TRUE, FALSE, TRUE }, { http_send_request_ex, INTERNET_STATUS_NAME_RESOLVED, TRUE, FALSE, TRUE }, { http_send_request_ex, INTERNET_STATUS_CONNECTING_TO_SERVER, TRUE }, { http_send_request_ex, INTERNET_STATUS_CONNECTED_TO_SERVER, TRUE }, { http_send_request_ex, INTERNET_STATUS_SENDING_REQUEST, TRUE }, { http_send_request_ex, INTERNET_STATUS_REQUEST_SENT, TRUE }, { http_send_request_ex, INTERNET_STATUS_REQUEST_COMPLETE, TRUE }, { http_end_request, INTERNET_STATUS_RECEIVING_RESPONSE, TRUE }, { http_end_request, INTERNET_STATUS_RESPONSE_RECEIVED, TRUE }, { http_end_request, INTERNET_STATUS_REQUEST_COMPLETE, TRUE }, { internet_close_handle, INTERNET_STATUS_CLOSING_CONNECTION }, { internet_close_handle, INTERNET_STATUS_CONNECTION_CLOSED }, { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING }, { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING }};
static const struct notification_data notification_data[] = { { async_send_request_ex_chunked_test, ARRAY_SIZE(async_send_request_ex_chunked_test), "GET", "test.winehq.org", "tests/data.php" }, { async_send_request_ex_test, ARRAY_SIZE(async_send_request_ex_test), "POST", "test.winehq.org", "tests/post.php", "Public ID=codeweavers" }, { async_send_request_ex_test2, ARRAY_SIZE(async_send_request_ex_test2), "POST", "test.winehq.org", "tests/post.php" }, { async_send_request_ex_resolve_failure_test, ARRAY_SIZE(async_send_request_ex_resolve_failure_test), "GET", "brokenhost", "index.html", NULL, TRUE }};
static void test_async_HttpSendRequestEx(const struct notification_data *nd){ BOOL ret; HINTERNET ses, req, con; struct info info; DWORD size, written, error; INTERNET_BUFFERSA b; static const char *accept[2] = {"*/*", NULL}; char buffer[32];
trace("Async HttpSendRequestEx test (%s %s)\n", nd->method, nd->host);
InitializeCriticalSection( ¬ification_cs );
info.test = nd->test; info.count = nd->count; info.index = 0; info.wait = CreateEventW( NULL, FALSE, FALSE, NULL ); info.thread = GetCurrentThreadId(); info.is_aborted = FALSE;
ses = InternetOpenA( "winetest", 0, NULL, NULL, INTERNET_FLAG_ASYNC ); ok( ses != NULL, "InternetOpen failed\n" );
pInternetSetStatusCallbackA( ses, check_notification );
setup_test( &info, internet_connect, __LINE__, ERROR_SUCCESS ); con = InternetConnectA( ses, nd->host, 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, (DWORD_PTR)&info ); ok( con != NULL, "InternetConnect failed %u\n", GetLastError() );
WaitForSingleObject( info.wait, 10000 );
setup_test( &info, http_open_request, __LINE__, ERROR_SUCCESS ); req = HttpOpenRequestA( con, nd->method, nd->path, NULL, NULL, accept, 0, (DWORD_PTR)&info ); ok( req != NULL, "HttpOpenRequest failed %u\n", GetLastError() );
WaitForSingleObject( info.wait, 10000 );
if(nd->data) { memset( &b, 0, sizeof(INTERNET_BUFFERSA) ); b.dwStructSize = sizeof(INTERNET_BUFFERSA); b.lpcszHeader = "Content-Type: application/x-www-form-urlencoded"; b.dwHeadersLength = strlen( b.lpcszHeader ); b.dwBufferTotal = nd->data ? strlen( nd->data ) : 0; }
setup_test( &info, http_send_request_ex, __LINE__, nd->expect_conn_failure ? ERROR_INTERNET_NAME_NOT_RESOLVED : ERROR_SUCCESS ); ret = HttpSendRequestExA( req, nd->data ? &b : NULL, NULL, 0x28, 0 ); ok( !ret && GetLastError() == ERROR_IO_PENDING, "HttpSendRequestExA failed %d %u\n", ret, GetLastError() );
error = WaitForSingleObject( info.wait, 10000 ); if(error != WAIT_OBJECT_0) { skip("WaitForSingleObject returned %d, assuming DNS problem\n", error); info.is_aborted = TRUE; goto abort; }
size = sizeof(buffer); SetLastError( 0xdeadbeef ); ret = HttpQueryInfoA( req, HTTP_QUERY_CONTENT_ENCODING, buffer, &size, 0 ); error = GetLastError(); ok( !ret, "HttpQueryInfoA failed %u\n", GetLastError() ); if(nd->expect_conn_failure) { ok(error == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND got %u\n", error ); }else { todo_wine ok(error == ERROR_INTERNET_INCORRECT_HANDLE_STATE, "expected ERROR_INTERNET_INCORRECT_HANDLE_STATE got %u\n", error ); }
if (nd->data) { written = 0; size = strlen( nd->data ); setup_test( &info, internet_writefile, __LINE__, ERROR_SUCCESS ); ret = InternetWriteFile( req, nd->data, size, &written ); ok( ret, "InternetWriteFile failed %u\n", GetLastError() ); ok( written == size, "expected %u got %u\n", written, size );
WaitForSingleObject( info.wait, 10000 );
SetLastError( 0xdeadbeef ); ret = HttpEndRequestA( req, (void *)nd->data, 0x28, 0 ); error = GetLastError(); ok( !ret, "HttpEndRequestA succeeded\n" ); ok( error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", error ); }
SetLastError( 0xdeadbeef ); setup_test( &info, http_end_request, __LINE__, nd->expect_conn_failure ? ERROR_INTERNET_OPERATION_CANCELLED : ERROR_SUCCESS); ret = HttpEndRequestA( req, NULL, 0x28, 0 ); error = GetLastError(); ok( !ret, "HttpEndRequestA succeeded\n" ); ok( error == ERROR_IO_PENDING, "expected ERROR_IO_PENDING got %u\n", error );
WaitForSingleObject( info.wait, 10000 );
setup_test( &info, internet_close_handle, __LINE__, ERROR_SUCCESS ); abort: InternetCloseHandle( req ); InternetCloseHandle( con ); InternetCloseHandle( ses );
WaitForSingleObject( info.wait, 10000 ); Sleep(100); CloseHandle( info.wait ); DeleteCriticalSection( ¬ification_cs );}
static HINTERNET closetest_session, closetest_req, closetest_conn;static BOOL closetest_closed;
static void WINAPI closetest_callback(HINTERNET hInternet, DWORD_PTR dwContext, DWORD dwInternetStatus, LPVOID lpvStatusInformation, DWORD dwStatusInformationLength){ DWORD len, type; BOOL res;
if(winetest_debug > 1) trace("closetest_callback %p: %d\n", hInternet, dwInternetStatus);
ok(hInternet == closetest_session || hInternet == closetest_conn || hInternet == closetest_req, "Unexpected hInternet %p\n", hInternet); if(!closetest_closed) return;
len = sizeof(type); res = InternetQueryOptionA(closetest_req, INTERNET_OPTION_HANDLE_TYPE, &type, &len); ok(!res && GetLastError() == ERROR_INVALID_HANDLE, "InternetQueryOptionA(%p INTERNET_OPTION_HANDLE_TYPE) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n", closetest_req, res, GetLastError());}
static void test_InternetCloseHandle(void){ DWORD len, flags; BOOL res;
closetest_session = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC); ok(closetest_session != NULL,"InternetOpen failed with error %u\n", GetLastError());
pInternetSetStatusCallbackA(closetest_session, closetest_callback);
closetest_conn = InternetConnectA(closetest_session, "source.winehq.org", INTERNET_INVALID_PORT_NUMBER, NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef); ok(closetest_conn != NULL,"InternetConnect failed with error %u\n", GetLastError());
closetest_req = HttpOpenRequestA(closetest_conn, "GET", "winegecko.php", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE, 0xdeadbead);
res = HttpSendRequestA(closetest_req, NULL, -1, NULL, 0); ok(!res && (GetLastError() == ERROR_IO_PENDING), "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
test_request_flags(closetest_req, INTERNET_REQFLAG_NO_HEADERS);
res = InternetCloseHandle(closetest_session); ok(res, "InternetCloseHandle failed: %u\n", GetLastError()); closetest_closed = TRUE; trace("Closed session handle\n");
res = InternetCloseHandle(closetest_conn); ok(!res && GetLastError() == ERROR_INVALID_HANDLE, "InternetCloseConnection(conn) failed: %x %u\n", res, GetLastError());
res = InternetCloseHandle(closetest_req); ok(!res && GetLastError() == ERROR_INVALID_HANDLE, "InternetCloseConnection(req) failed: %x %u\n", res, GetLastError());
len = sizeof(flags); res = InternetQueryOptionA(closetest_req, INTERNET_OPTION_REQUEST_FLAGS, &flags, &len); ok(!res && GetLastError() == ERROR_INVALID_HANDLE, "InternetQueryOptionA(%p INTERNET_OPTION_REQUEST_FLAGS) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n", closetest_req, res, GetLastError());}
static void test_connection_failure(void){ test_request_t req; DWORD error; BOOL ret;
open_simple_request(&req, "localhost", 1, NULL, "/");
SetLastError(0xdeadbeef); ret = HttpSendRequestA(req.request, NULL, 0, NULL, 0); error = GetLastError(); ok(!ret, "unexpected success\n"); ok(error == ERROR_INTERNET_CANNOT_CONNECT, "wrong error %u\n", error);
close_request(&req);}
static void test_default_service_port(void){ HINTERNET session, connect, request; DWORD size, error; char buffer[128]; BOOL ret;
if(!is_ie7plus) return;
session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); ok(session != NULL, "InternetOpen failed\n");
connect = InternetConnectA(session, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); ok(connect != NULL, "InternetConnect failed\n");
request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, NULL, INTERNET_FLAG_SECURE, 0); ok(request != NULL, "HttpOpenRequest failed\n");
SetLastError(0xdeadbeef); ret = HttpSendRequestA(request, NULL, 0, NULL, 0); error = GetLastError(); ok(!ret, "HttpSendRequest succeeded\n"); ok(error == ERROR_INTERNET_SECURITY_CHANNEL_ERROR || error == ERROR_INTERNET_CANNOT_CONNECT, "got %u\n", error);
size = sizeof(buffer); memset(buffer, 0, sizeof(buffer)); ret = HttpQueryInfoA(request, HTTP_QUERY_HOST | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL); ok(ret, "HttpQueryInfo failed with error %u\n", GetLastError()); ok(!strcmp(buffer, "test.winehq.org:80"), "Expected test.winehg.org:80, got '%s'\n", buffer);
InternetCloseHandle(request); InternetCloseHandle(connect);
connect = InternetConnectA(session, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER, NULL, NULL, INTERNET_SERVICE_HTTP, INTERNET_FLAG_SECURE, 0); ok(connect != NULL, "InternetConnect failed\n");
request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, NULL, INTERNET_FLAG_SECURE, 0); ok(request != NULL, "HttpOpenRequest failed\n");
ret = HttpSendRequestA(request, NULL, 0, NULL, 0); if (!ret && GetLastError() == ERROR_INTERNET_SECURITY_CHANNEL_ERROR) { win_skip("Can't make https connection\n"); goto done; } ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
size = sizeof(buffer); memset(buffer, 0, sizeof(buffer)); ret = HttpQueryInfoA(request, HTTP_QUERY_HOST | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL); ok(ret, "HttpQueryInfo failed with error %u\n", GetLastError()); ok(!strcmp(buffer, "test.winehq.org"), "Expected test.winehg.org, got '%s'\n", buffer);
InternetCloseHandle(request); InternetCloseHandle(connect);
connect = InternetConnectA(session, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER, NULL, NULL, INTERNET_SERVICE_HTTP, INTERNET_FLAG_SECURE, 0); ok(connect != NULL, "InternetConnect failed\n");
request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, NULL, 0, 0); ok(request != NULL, "HttpOpenRequest failed\n");
ret = HttpSendRequestA(request, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
size = sizeof(buffer); memset(buffer, 0, sizeof(buffer)); ret = HttpQueryInfoA(request, HTTP_QUERY_HOST | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL); ok(ret, "HttpQueryInfo failed with error %u\n", GetLastError()); ok(!strcmp(buffer, "test.winehq.org:443"), "Expected test.winehg.org:443, got '%s'\n", buffer);
done: InternetCloseHandle(request); InternetCloseHandle(connect); InternetCloseHandle(session);}
static void init_status_tests(void){ memset(expect, 0, sizeof(expect)); memset(optional, 0, sizeof(optional)); memset(wine_allow, 0, sizeof(wine_allow)); memset(notified, 0, sizeof(notified)); memset(status_string, 0, sizeof(status_string));
#define STATUS_STRING(status) status_string[status] = #status STATUS_STRING(INTERNET_STATUS_RESOLVING_NAME); STATUS_STRING(INTERNET_STATUS_NAME_RESOLVED); STATUS_STRING(INTERNET_STATUS_CONNECTING_TO_SERVER); STATUS_STRING(INTERNET_STATUS_CONNECTED_TO_SERVER); STATUS_STRING(INTERNET_STATUS_SENDING_REQUEST); STATUS_STRING(INTERNET_STATUS_REQUEST_SENT); STATUS_STRING(INTERNET_STATUS_RECEIVING_RESPONSE); STATUS_STRING(INTERNET_STATUS_RESPONSE_RECEIVED); STATUS_STRING(INTERNET_STATUS_CTL_RESPONSE_RECEIVED); STATUS_STRING(INTERNET_STATUS_PREFETCH); STATUS_STRING(INTERNET_STATUS_CLOSING_CONNECTION); STATUS_STRING(INTERNET_STATUS_CONNECTION_CLOSED); STATUS_STRING(INTERNET_STATUS_HANDLE_CREATED); STATUS_STRING(INTERNET_STATUS_HANDLE_CLOSING); STATUS_STRING(INTERNET_STATUS_DETECTING_PROXY); STATUS_STRING(INTERNET_STATUS_REQUEST_COMPLETE); STATUS_STRING(INTERNET_STATUS_REDIRECT); STATUS_STRING(INTERNET_STATUS_INTERMEDIATE_RESPONSE); STATUS_STRING(INTERNET_STATUS_USER_INPUT_REQUIRED); STATUS_STRING(INTERNET_STATUS_STATE_CHANGE); STATUS_STRING(INTERNET_STATUS_COOKIE_SENT); STATUS_STRING(INTERNET_STATUS_COOKIE_RECEIVED); STATUS_STRING(INTERNET_STATUS_PRIVACY_IMPACTED); STATUS_STRING(INTERNET_STATUS_P3P_HEADER); STATUS_STRING(INTERNET_STATUS_P3P_POLICYREF); STATUS_STRING(INTERNET_STATUS_COOKIE_HISTORY);#undef STATUS_STRING}
static void WINAPI header_cb( HINTERNET handle, DWORD_PTR ctx, DWORD status, LPVOID info, DWORD len ){ BOOL ret; DWORD index, size; char buf[256];
if (status == INTERNET_STATUS_SENDING_REQUEST) { ret = HttpAddRequestHeadersA( handle, "winetest: winetest", ~0u, HTTP_ADDREQ_FLAG_ADD ); ok( ret, "HttpAddRequestHeadersA failed %u\n", GetLastError() ); SetEvent( (HANDLE)ctx ); } else if (status == INTERNET_STATUS_REQUEST_SENT) { index = 0; size = sizeof(buf); ret = HttpQueryInfoA( handle, HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS, buf, &size, &index ); ok( ret, "HttpQueryInfoA failed %u\n", GetLastError() ); ok( strstr( buf, "winetest: winetest" ) != NULL, "header missing\n" ); SetEvent( (HANDLE)ctx ); }}
static void test_concurrent_header_access(void){ HINTERNET ses, con, req; DWORD err; BOOL ret; HANDLE wait = CreateEventW( NULL, FALSE, FALSE, NULL );
ses = InternetOpenA( "winetest", 0, NULL, NULL, INTERNET_FLAG_ASYNC ); ok( ses != NULL, "InternetOpenA failed\n" );
con = InternetConnectA( ses, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0 ); ok( con != NULL, "InternetConnectA failed %u\n", GetLastError() );
req = HttpOpenRequestA( con, NULL, "/", NULL, NULL, NULL, 0, (DWORD_PTR)wait ); ok( req != NULL, "HttpOpenRequestA failed %u\n", GetLastError() );
pInternetSetStatusCallbackA( req, header_cb );
SetLastError( 0xdeadbeef ); ret = HttpSendRequestA( req, NULL, 0, NULL, 0 ); err = GetLastError(); ok( !ret, "HttpSendRequestA succeeded\n" ); ok( err == ERROR_IO_PENDING, "got %u\n", ERROR_IO_PENDING );
WaitForSingleObject( wait, 5000 ); WaitForSingleObject( wait, 5000 );
InternetCloseHandle( req ); InternetCloseHandle( con ); InternetCloseHandle( ses ); CloseHandle( wait );}
static void test_cert_string(void){ HINTERNET ses, con, req; char actual[512]; DWORD size; BOOL res;
ses = InternetOpenA( "winetest", 0, NULL, NULL, 0 ); ok( ses != NULL, "InternetOpenA failed\n" );
con = InternetConnectA( ses, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0 ); ok( con != NULL, "InternetConnectA failed %u\n", GetLastError() );
req = HttpOpenRequestA( con, NULL, "/", NULL, NULL, NULL, 0, 0 ); ok( req != NULL, "HttpOpenRequestA failed %u\n", GetLastError() );
size = sizeof(actual); SetLastError( 0xdeadbeef ); memset( actual, 0x55, sizeof(actual) ); res = InternetQueryOptionA( req, INTERNET_OPTION_SECURITY_CERTIFICATE, actual, &size ); ok( !res && GetLastError() == ERROR_INTERNET_INVALID_OPERATION, "InternetQueryOption failed: %u\n", GetLastError() ); ok( size == 0, "unexpected size: %u\n", size ); ok( actual[0] == 0x55, "unexpected byte: %02x\n", actual[0] );
InternetCloseHandle( req ); InternetCloseHandle( con ); InternetCloseHandle( ses );}
START_TEST(http){ HMODULE hdll;
if (!winetest_interactive) { win_skip("Skipping wininet:http due to hang ROSTESTS-357\n"); return; }
hdll = GetModuleHandleA("wininet.dll");
if(!GetProcAddress(hdll, "InternetGetCookieExW")) { win_skip("Too old IE (older than 6.0)\n"); return; }
pInternetSetStatusCallbackA = (void*)GetProcAddress(hdll, "InternetSetStatusCallbackA"); pInternetSetStatusCallbackW = (void*)GetProcAddress(hdll, "InternetSetStatusCallbackW"); pInternetGetSecurityInfoByURLA = (void*)GetProcAddress(hdll, "InternetGetSecurityInfoByURLA");
if(!pInternetGetSecurityInfoByURLA) { is_ie7plus = FALSE; win_skip("IE6 found. It's too old for some tests.\n"); }
init_events(); init_status_tests(); test_InternetCloseHandle(); InternetReadFile_test(INTERNET_FLAG_ASYNC, &test_data[0]); InternetReadFile_test(INTERNET_FLAG_ASYNC, &test_data[1]); InternetReadFile_test(0, &test_data[1]); InternetReadFile_test(INTERNET_FLAG_ASYNC, &test_data[2]); test_secure_connection(); test_security_flags(); InternetReadFile_test(0, &test_data[2]); InternetReadFileExA_test(INTERNET_FLAG_ASYNC); test_open_url_async(); test_async_HttpSendRequestEx(¬ification_data[0]); test_async_HttpSendRequestEx(¬ification_data[1]); test_async_HttpSendRequestEx(¬ification_data[2]); test_async_HttpSendRequestEx(¬ification_data[3]); InternetOpenRequest_test(); test_http_cache(); InternetLockRequestFile_test(); InternetOpenUrlA_test(); HttpHeaders_test(); test_http_connection(); test_user_agent_header(); test_bogus_accept_types_array(); InternetReadFile_chunked_test(); HttpSendRequestEx_test(); InternetReadFile_test(INTERNET_FLAG_ASYNC, &test_data[3]); test_connection_failure(); test_default_service_port(); test_concurrent_header_access(); test_cert_string(); free_events();}