1
0

001-ipkg.patch 408 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642
  1. --- busybox-1.18.1.orig/Makefile
  2. +++ busybox-1.18.1/Makefile
  3. @@ -465,6 +465,7 @@
  4. libs-y := \
  5. archival/ \
  6. archival/libarchive/ \
  7. + archival/libipkg/ \
  8. console-tools/ \
  9. coreutils/ \
  10. coreutils/libcoreutils/ \
  11. --- busybox-1.18.1.orig/archival/Config.src
  12. +++ busybox-1.18.1/archival/Config.src
  13. @@ -202,6 +202,12 @@
  14. are actually slower than gzip at equivalent compression ratios
  15. and take up 3.2K of code.
  16. +config IPKG
  17. + bool "ipkg"
  18. + default n
  19. + help
  20. + ipkg is the itsy package management system.
  21. +
  22. config RPM2CPIO
  23. bool "rpm2cpio"
  24. default y
  25. --- busybox-1.18.1.orig/archival/Kbuild.src
  26. +++ busybox-1.18.1/archival/Kbuild.src
  27. @@ -22,6 +22,7 @@
  28. lib-$(CONFIG_LZOP) += lzop.o bbunzip.o
  29. lib-$(CONFIG_GZIP) += gzip.o bbunzip.o
  30. lib-$(CONFIG_BZIP2) += bzip2.o bbunzip.o
  31. +lib-$(CONFIG_IPKG) += ipkg.o
  32. lib-$(CONFIG_UNXZ) += bbunzip.o
  33. lib-$(CONFIG_UNLZMA) += bbunzip.o
  34. --- /dev/null
  35. +++ busybox-1.18.1/archival/ipkg.c
  36. @@ -0,0 +1,28 @@
  37. +/* ipkg.c - the itsy package management system
  38. +
  39. + Florina Boor
  40. +
  41. + Copyright (C) 2003 kernel concepts
  42. +
  43. + This program is free software; you can redistribute it and/or
  44. + modify it under the terms of the GNU General Public License as
  45. + published by the Free Software Foundation; either version 2, or (at
  46. + your option) any later version.
  47. +
  48. + This program is distributed in the hope that it will be useful, but
  49. + WITHOUT ANY WARRANTY; without even the implied warranty of
  50. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  51. + General Public License for more details.
  52. +
  53. + ipkg command line frontend using libipkg
  54. +
  55. +*/
  56. +
  57. +#include "libbb.h"
  58. +#include "libipkg/libipkg.h"
  59. +
  60. +int ipkg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  61. +int ipkg_main(int argc, char **argv)
  62. +{
  63. + return ipkg_op(argc, argv);
  64. +}
  65. --- /dev/null
  66. +++ busybox-1.18.1/archival/libipkg/Kbuild
  67. @@ -0,0 +1,60 @@
  68. +# Makefile for busybox
  69. +#
  70. +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
  71. +# Copyright (C) 2006 OpenWrt.org
  72. +#
  73. +# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
  74. +
  75. +LIBIPKG_CORE_OBJS:= \
  76. + args.o \
  77. + libipkg.o \
  78. + user.o \
  79. +
  80. +LIBIPKG_CMD_OBJS:= \
  81. + ipkg_cmd.o \
  82. + ipkg_configure.o \
  83. + ipkg_download.o \
  84. + ipkg_install.o \
  85. + ipkg_remove.o \
  86. + ipkg_upgrade.o \
  87. +
  88. +LIBIPKG_DB_OBJS:= \
  89. + hash_table.o \
  90. + ipkg_conf.o \
  91. + ipkg_utils.o \
  92. + pkg.o \
  93. + pkg_depends.o \
  94. + pkg_extract.o \
  95. + pkg_hash.o \
  96. + pkg_parse.o \
  97. + pkg_vec.o \
  98. +
  99. +LIBIPKG_LIST_OBJS:= \
  100. + conffile.o \
  101. + conffile_list.o \
  102. + nv_pair.o \
  103. + nv_pair_list.o \
  104. + pkg_dest.o \
  105. + pkg_dest_list.o \
  106. + pkg_src.o \
  107. + pkg_src_list.o \
  108. + str_list.o \
  109. + void_list.o \
  110. +
  111. +LIBIPKG_UTIL_OBJS:= \
  112. + file_util.o \
  113. + ipkg_message.o \
  114. + str_util.o \
  115. + xsystem.o \
  116. +
  117. +lib-y :=
  118. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CORE_OBJS)
  119. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CMD_OBJS)
  120. +lib-$(CONFIG_IPKG) += $(LIBIPKG_DB_OBJS)
  121. +lib-$(CONFIG_IPKG) += $(LIBIPKG_LIST_OBJS)
  122. +lib-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_OBJS)
  123. +
  124. +ifeq ($(strip $(IPKG_ARCH)),)
  125. +IPKG_ARCH:=$(TARGET_ARCH)
  126. +endif
  127. +CFLAGS += -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(IPKG_ARCH)\""
  128. --- /dev/null
  129. +++ busybox-1.18.1/archival/libipkg/args.c
  130. @@ -0,0 +1,242 @@
  131. +/* args.c - parse command-line args
  132. +
  133. + Carl D. Worth
  134. +
  135. + Copyright 2001 University of Southern California
  136. +
  137. + This program is free software; you can redistribute it and/or modify
  138. + it under the terms of the GNU General Public License as published by
  139. + the Free Software Foundation; either version 2, or (at your option)
  140. + any later version.
  141. +
  142. + This program is distributed in the hope that it will be useful,
  143. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  144. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  145. + GNU General Public License for more details.
  146. + */
  147. +
  148. +#include <getopt.h>
  149. +#include <stdlib.h>
  150. +#include <string.h>
  151. +#include <unistd.h>
  152. +
  153. +#include "ipkg.h"
  154. +#include "ipkg_message.h"
  155. +
  156. +#include "args.h"
  157. +#include "sprintf_alloc.h"
  158. +
  159. +#include "libbb.h"
  160. +
  161. +
  162. +static void print_version(void);
  163. +
  164. +enum long_args_opt
  165. +{
  166. + ARGS_OPT_FORCE_DEFAULTS = 129,
  167. + ARGS_OPT_FORCE_DEPENDS,
  168. + ARGS_OPT_FORCE_OVERWRITE,
  169. + ARGS_OPT_FORCE_DOWNGRADE,
  170. + ARGS_OPT_FORCE_REINSTALL,
  171. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
  172. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
  173. + ARGS_OPT_FORCE_SPACE,
  174. + ARGS_OPT_NOACTION,
  175. + ARGS_OPT_NODEPS,
  176. + ARGS_OPT_VERBOSE_WGET,
  177. + ARGS_OPT_VERBOSITY,
  178. + ARGS_OPT_MULTIPLE_PROVIDERS
  179. +};
  180. +
  181. +int args_init(args_t *args)
  182. +{
  183. + const char *conf_file_dir;
  184. +
  185. + memset(args, 0, sizeof(args_t));
  186. +
  187. + args->dest = ARGS_DEFAULT_DEST;
  188. +
  189. + conf_file_dir = getenv("IPKG_CONF_DIR");
  190. + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
  191. + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
  192. + }
  193. + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
  194. + ARGS_DEFAULT_CONF_FILE_NAME);
  195. +
  196. + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
  197. + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
  198. + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
  199. + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
  200. + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
  201. + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
  202. + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
  203. + args->noaction = ARGS_DEFAULT_NOACTION;
  204. + args->nodeps = ARGS_DEFAULT_NODEPS;
  205. + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
  206. + args->verbosity = ARGS_DEFAULT_VERBOSITY;
  207. + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
  208. + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
  209. + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
  210. + args->multiple_providers = 0;
  211. + args->nocheckfordirorfile = 0;
  212. + args->noreadfeedsfile = 0;
  213. +
  214. + return 1;
  215. +}
  216. +
  217. +void args_deinit(args_t *args)
  218. +{
  219. + free(args->conf_file);
  220. + args->conf_file = NULL;
  221. +}
  222. +
  223. +int args_parse(args_t *args, int argc, char *argv[])
  224. +{
  225. + int c;
  226. + int option_index = 0;
  227. + int parse_err = 0;
  228. + static struct option long_options[] = {
  229. + {"query-all", 0, 0, 'A'},
  230. + {"conf-file", 1, 0, 'f'},
  231. + {"conf", 1, 0, 'f'},
  232. + {"dest", 1, 0, 'd'},
  233. + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  234. + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  235. + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  236. + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  237. + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  238. + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  239. + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  240. + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  241. + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  242. + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  243. + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
  244. + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
  245. + {"recursive", 0, 0,
  246. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  247. + {"force-removal-of-dependent-packages", 0, 0,
  248. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  249. + {"force_removal_of_dependent_packages", 0, 0,
  250. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  251. + {"force-removal-of-essential-packages", 0, 0,
  252. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  253. + {"force_removal_of_essential_packages", 0, 0,
  254. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  255. + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  256. + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  257. + {"noaction", 0, 0, ARGS_OPT_NOACTION},
  258. + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
  259. + {"offline", 1, 0, 'o'},
  260. + {"offline-root", 1, 0, 'o'},
  261. + {"test", 0, 0, ARGS_OPT_NOACTION},
  262. + {"tmp-dir", 1, 0, 't'},
  263. + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  264. + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  265. + {"verbosity", 2, 0, 'V'},
  266. + {"version", 0, 0, 'v'},
  267. + {0, 0, 0, 0}
  268. + };
  269. +
  270. + while (1) {
  271. + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
  272. + if (c == -1)
  273. + break;
  274. +
  275. + switch (c) {
  276. + case 'A':
  277. + args->query_all = 1;
  278. + break;
  279. + case 'd':
  280. + args->dest = optarg;
  281. + break;
  282. + case 'f':
  283. + free(args->conf_file);
  284. + args->conf_file = strdup(optarg);
  285. + break;
  286. + case 'o':
  287. + args->offline_root = optarg;
  288. + break;
  289. + case 'n':
  290. + args->noaction = 1;
  291. + break;
  292. + case 't':
  293. + args->tmp_dir = strdup(optarg);
  294. + break;
  295. + case 'v':
  296. + print_version();
  297. + exit(0);
  298. + case 'V':
  299. + case ARGS_OPT_VERBOSITY:
  300. + if (optarg)
  301. + args->verbosity = atoi(optarg);
  302. + else
  303. + args->verbosity += 1;
  304. + break;
  305. + case ARGS_OPT_FORCE_DEFAULTS:
  306. + args->force_defaults = 1;
  307. + break;
  308. + case ARGS_OPT_FORCE_DEPENDS:
  309. + args->force_depends = 1;
  310. + break;
  311. + case ARGS_OPT_FORCE_OVERWRITE:
  312. + args->force_overwrite = 1;
  313. + break;
  314. + case ARGS_OPT_FORCE_DOWNGRADE:
  315. + args->force_downgrade = 1;
  316. + break;
  317. + case ARGS_OPT_FORCE_REINSTALL:
  318. + args->force_reinstall = 1;
  319. + break;
  320. + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
  321. + args->force_removal_of_essential_packages = 1;
  322. + break;
  323. + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
  324. + args->force_removal_of_dependent_packages = 1;
  325. + break;
  326. + case ARGS_OPT_FORCE_SPACE:
  327. + args->force_space = 1;
  328. + break;
  329. + case ARGS_OPT_VERBOSE_WGET:
  330. + args->verbose_wget = 1;
  331. + break;
  332. + case ARGS_OPT_MULTIPLE_PROVIDERS:
  333. + args->multiple_providers = 1;
  334. + break;
  335. + case ARGS_OPT_NODEPS:
  336. + args->nodeps = 1;
  337. + break;
  338. + case ARGS_OPT_NOACTION:
  339. + args->noaction = 1;
  340. + break;
  341. + case ':':
  342. + parse_err++;
  343. + break;
  344. + case '?':
  345. + parse_err++;
  346. + break;
  347. + default:
  348. + bb_error_msg("Confusion: getopt_long returned %d\n", c);
  349. + }
  350. + }
  351. +
  352. + if (parse_err) {
  353. + return -parse_err;
  354. + } else {
  355. + return optind;
  356. + }
  357. +}
  358. +
  359. +void args_usage(const char *complaint)
  360. +{
  361. + if (complaint) {
  362. + bb_error_msg("%s\n", complaint);
  363. + }
  364. + print_version();
  365. + bb_show_usage();
  366. + exit(1);
  367. +}
  368. +
  369. +static void print_version(void)
  370. +{
  371. + bb_error_msg("version %s\n", IPKG_VERSION);
  372. +}
  373. --- /dev/null
  374. +++ busybox-1.18.1/archival/libipkg/args.h
  375. @@ -0,0 +1,72 @@
  376. +/* args.h - parse command-line args
  377. +
  378. + Carl D. Worth
  379. +
  380. + Copyright 2001 University of Southern California
  381. +
  382. + This program is free software; you can redistribute it and/or modify
  383. + it under the terms of the GNU General Public License as published by
  384. + the Free Software Foundation; either version 2, or (at your option)
  385. + any later version.
  386. +
  387. + This program is distributed in the hope that it will be useful,
  388. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  389. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  390. + GNU General Public License for more details.
  391. +*/
  392. +
  393. +#ifndef ARGS_H
  394. +#define ARGS_H
  395. +
  396. +struct args
  397. +{
  398. + char *conf_file;
  399. + char *dest;
  400. + char *tmp_dir;
  401. + int force_defaults;
  402. + int force_depends;
  403. + int force_overwrite;
  404. + int force_downgrade;
  405. + int force_reinstall;
  406. + int force_removal_of_essential_packages;
  407. + int force_removal_of_dependent_packages;
  408. + int force_space;
  409. + int noaction;
  410. + int nodeps;
  411. + int multiple_providers;
  412. + int query_all;
  413. + int verbose_wget;
  414. + int verbosity;
  415. + int nocheckfordirorfile;
  416. + int noreadfeedsfile;
  417. + char *offline_root;
  418. + char *offline_root_pre_script_cmd;
  419. + char *offline_root_post_script_cmd;
  420. +};
  421. +typedef struct args args_t;
  422. +
  423. +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
  424. +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
  425. +#define ARGS_DEFAULT_DEST NULL
  426. +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
  427. +#define ARGS_DEFAULT_FORCE_DEPENDS 0
  428. +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
  429. +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
  430. +#define ARGS_DEFAULT_FORCE_REINSTALL 0
  431. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
  432. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
  433. +#define ARGS_DEFAULT_FORCE_SPACE 0
  434. +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
  435. +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
  436. +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
  437. +#define ARGS_DEFAULT_NOACTION 0
  438. +#define ARGS_DEFAULT_NODEPS 0
  439. +#define ARGS_DEFAULT_VERBOSE_WGET 0
  440. +#define ARGS_DEFAULT_VERBOSITY 1
  441. +
  442. +int args_init(args_t *args);
  443. +void args_deinit(args_t *args);
  444. +int args_parse(args_t *args, int argc, char *argv[]);
  445. +void args_usage(const char *complaint);
  446. +
  447. +#endif
  448. --- /dev/null
  449. +++ busybox-1.18.1/archival/libipkg/conffile.c
  450. @@ -0,0 +1,65 @@
  451. +/* conffile.c - the itsy package management system
  452. +
  453. + Carl D. Worth
  454. +
  455. + Copyright (C) 2001 University of Southern California
  456. +
  457. + This program is free software; you can redistribute it and/or
  458. + modify it under the terms of the GNU General Public License as
  459. + published by the Free Software Foundation; either version 2, or (at
  460. + your option) any later version.
  461. +
  462. + This program is distributed in the hope that it will be useful, but
  463. + WITHOUT ANY WARRANTY; without even the implied warranty of
  464. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  465. + General Public License for more details.
  466. +*/
  467. +
  468. +#include <string.h>
  469. +#include <stdlib.h>
  470. +
  471. +#include "libbb.h"
  472. +#include "ipkg.h"
  473. +#include "ipkg_message.h"
  474. +
  475. +#include "conffile.h"
  476. +#include "file_util.h"
  477. +#include "sprintf_alloc.h"
  478. +
  479. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum)
  480. +{
  481. + return nv_pair_init(conffile, file_name, (char *)md5sum);
  482. +}
  483. +
  484. +void conffile_deinit(conffile_t *conffile)
  485. +{
  486. + nv_pair_deinit(conffile);
  487. +}
  488. +
  489. +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
  490. +{
  491. + uint8_t *md5sum;
  492. + char *filename = conffile->name;
  493. + char *root_filename;
  494. + int ret;
  495. +
  496. + if (conffile->value == NULL) {
  497. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
  498. + return 1;
  499. + }
  500. +
  501. + root_filename = root_filename_alloc(conf, filename);
  502. +
  503. + md5sum = file_md5sum_alloc(root_filename);
  504. +
  505. + ret = strcmp((char *)md5sum, conffile->value);
  506. + if (ret) {
  507. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
  508. + conffile->name, md5sum, conffile->value);
  509. + }
  510. +
  511. + free(root_filename);
  512. + free(md5sum);
  513. +
  514. + return ret;
  515. +}
  516. --- /dev/null
  517. +++ busybox-1.18.1/archival/libipkg/conffile.h
  518. @@ -0,0 +1,30 @@
  519. +/* conffile.h - the itsy package management system
  520. +
  521. + Carl D. Worth
  522. +
  523. + Copyright (C) 2001 University of Southern California
  524. +
  525. + This program is free software; you can redistribute it and/or
  526. + modify it under the terms of the GNU General Public License as
  527. + published by the Free Software Foundation; either version 2, or (at
  528. + your option) any later version.
  529. +
  530. + This program is distributed in the hope that it will be useful, but
  531. + WITHOUT ANY WARRANTY; without even the implied warranty of
  532. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  533. + General Public License for more details.
  534. +*/
  535. +
  536. +#ifndef CONFFILE_H
  537. +#define CONFFILE_H
  538. +
  539. +#include "nv_pair.h"
  540. +
  541. +typedef struct nv_pair conffile_t;
  542. +
  543. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum);
  544. +void conffile_deinit(conffile_t *conffile);
  545. +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
  546. +
  547. +#endif
  548. +
  549. --- /dev/null
  550. +++ busybox-1.18.1/archival/libipkg/conffile_list.c
  551. @@ -0,0 +1,47 @@
  552. +/* conffile_list.c - the itsy package management system
  553. +
  554. + Carl D. Worth
  555. +
  556. + Copyright (C) 2001 University of Southern California
  557. +
  558. + This program is free software; you can redistribute it and/or
  559. + modify it under the terms of the GNU General Public License as
  560. + published by the Free Software Foundation; either version 2, or (at
  561. + your option) any later version.
  562. +
  563. + This program is distributed in the hope that it will be useful, but
  564. + WITHOUT ANY WARRANTY; without even the implied warranty of
  565. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  566. + General Public License for more details.
  567. +*/
  568. +
  569. +#include "ipkg.h"
  570. +
  571. +#include "conffile_list.h"
  572. +
  573. +int conffile_list_init(conffile_list_t *list)
  574. +{
  575. + return nv_pair_list_init(list);
  576. +}
  577. +
  578. +void conffile_list_deinit(conffile_list_t *list)
  579. +{
  580. + nv_pair_list_deinit(list);
  581. +}
  582. +
  583. +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
  584. + const char *md5sum)
  585. +{
  586. + return nv_pair_list_append(list, file_name, md5sum);
  587. +}
  588. +
  589. +int conffile_list_push(conffile_list_t *list, conffile_t *data)
  590. +{
  591. + return nv_pair_list_push(list, data);
  592. +}
  593. +
  594. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
  595. +{
  596. + return nv_pair_list_pop(list);
  597. +}
  598. +
  599. --- /dev/null
  600. +++ busybox-1.18.1/archival/libipkg/conffile_list.h
  601. @@ -0,0 +1,36 @@
  602. +/* conffile_list.h - the itsy package management system
  603. +
  604. + Carl D. Worth
  605. +
  606. + Copyright (C) 2001 University of Southern California
  607. +
  608. + This program is free software; you can redistribute it and/or
  609. + modify it under the terms of the GNU General Public License as
  610. + published by the Free Software Foundation; either version 2, or (at
  611. + your option) any later version.
  612. +
  613. + This program is distributed in the hope that it will be useful, but
  614. + WITHOUT ANY WARRANTY; without even the implied warranty of
  615. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  616. + General Public License for more details.
  617. +*/
  618. +
  619. +#ifndef CONFFILE_LIST_H
  620. +#define CONFFILE_LIST_H
  621. +
  622. +#include "conffile.h"
  623. +#include "nv_pair_list.h"
  624. +
  625. +typedef struct nv_pair_list_elt conffile_list_elt_t;
  626. +typedef struct nv_pair_list conffile_list_t;
  627. +
  628. +int conffile_list_init(conffile_list_t *list);
  629. +void conffile_list_deinit(conffile_list_t *list);
  630. +
  631. +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
  632. + const char *root_dir);
  633. +int conffile_list_push(conffile_list_t *list, conffile_t *data);
  634. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
  635. +
  636. +#endif
  637. +
  638. --- /dev/null
  639. +++ busybox-1.18.1/archival/libipkg/file_util.c
  640. @@ -0,0 +1,186 @@
  641. +/* file_util.c - convenience routines for common stat operations
  642. +
  643. + Carl D. Worth
  644. +
  645. + Copyright (C) 2001 University of Southern California
  646. +
  647. + This program is free software; you can redistribute it and/or
  648. + modify it under the terms of the GNU General Public License as
  649. + published by the Free Software Foundation; either version 2, or (at
  650. + your option) any later version.
  651. +
  652. + This program is distributed in the hope that it will be useful, but
  653. + WITHOUT ANY WARRANTY; without even the implied warranty of
  654. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  655. + General Public License for more details.
  656. +*/
  657. +
  658. +#include "ipkg.h"
  659. +#include <sys/types.h>
  660. +#include <sys/stat.h>
  661. +
  662. +#include "sprintf_alloc.h"
  663. +#include "file_util.h"
  664. +#include "libbb.h"
  665. +#undef strlen
  666. +
  667. +int file_exists(const char *file_name)
  668. +{
  669. + int err;
  670. + struct stat stat_buf;
  671. +
  672. + err = stat(file_name, &stat_buf);
  673. + if (err == 0) {
  674. + return 1;
  675. + } else {
  676. + return 0;
  677. + }
  678. +}
  679. +
  680. +int file_is_dir(const char *file_name)
  681. +{
  682. + int err;
  683. + struct stat stat_buf;
  684. +
  685. + err = stat(file_name, &stat_buf);
  686. + if (err) {
  687. + return 0;
  688. + }
  689. +
  690. + return S_ISDIR(stat_buf.st_mode);
  691. +}
  692. +
  693. +/* read a single line from a file, stopping at a newline or EOF.
  694. + If a newline is read, it will appear in the resulting string.
  695. + Return value is a malloc'ed char * which should be freed at
  696. + some point by the caller.
  697. +
  698. + Return value is NULL if the file is at EOF when called.
  699. +*/
  700. +#define FILE_READ_LINE_BUF_SIZE 1024
  701. +char *file_read_line_alloc(FILE *file)
  702. +{
  703. + char buf[FILE_READ_LINE_BUF_SIZE];
  704. + int buf_len;
  705. + char *line = NULL;
  706. + int line_size = 0;
  707. +
  708. + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
  709. + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
  710. + buf_len = strlen(buf);
  711. + if (line) {
  712. + line_size += buf_len;
  713. + line = realloc(line, line_size);
  714. + if (line == NULL) {
  715. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  716. + break;
  717. + }
  718. + strcat(line, buf);
  719. + } else {
  720. + line_size = buf_len + 1;
  721. + line = strdup(buf);
  722. + }
  723. + if (buf[buf_len - 1] == '\n') {
  724. + break;
  725. + }
  726. + }
  727. +
  728. + return line;
  729. +}
  730. +
  731. +int file_move(const char *src, const char *dest)
  732. +{
  733. + int err;
  734. +
  735. + err = rename(src, dest);
  736. +
  737. + if (err && errno == EXDEV) {
  738. + err = file_copy(src, dest);
  739. + unlink(src);
  740. + } else if (err) {
  741. + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
  742. + __FUNCTION__, src, dest, strerror(errno));
  743. + }
  744. +
  745. + return err;
  746. +}
  747. +
  748. +/* I put these here to keep libbb dependencies from creeping all over
  749. + the ipkg code */
  750. +int file_copy(const char *src, const char *dest)
  751. +{
  752. + int err;
  753. +
  754. + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
  755. + if (err) {
  756. + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
  757. + __FUNCTION__, src, dest);
  758. + }
  759. +
  760. + return err;
  761. +}
  762. +
  763. +int file_mkdir_hier(char *path, long mode)
  764. +{
  765. + return bb_make_directory(path, mode, FILEUTILS_RECUR);
  766. +}
  767. +
  768. +static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
  769. + unsigned hash_length)
  770. +{
  771. + /* xzalloc zero-terminates */
  772. + char *hex_value = xzalloc((hash_length * 2) + 1);
  773. + bin2hex(hex_value, (char*)hash_value, hash_length);
  774. + return (unsigned char *)hex_value;
  775. +}
  776. +
  777. +static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
  778. +{
  779. + int src_fd, hash_len, count;
  780. + union _ctx_ {
  781. + sha1_ctx_t sha1;
  782. + md5_ctx_t md5;
  783. + } context;
  784. + uint8_t *hash_value = NULL;
  785. + RESERVE_CONFIG_UBUFFER(in_buf, 4096);
  786. + void FAST_FUNC (*update)(void*, const void*, size_t);
  787. + void FAST_FUNC (*final)(void*, void*);
  788. +
  789. + src_fd = open_or_warn_stdin(filename);
  790. + if (src_fd < 0) {
  791. + return NULL;
  792. + }
  793. +
  794. + /* figure specific hash algorithims */
  795. + if (ENABLE_MD5SUM && hash_algo == HASH_MD5) {
  796. + md5_begin(&context.md5);
  797. + update = (void*)md5_hash;
  798. + final = (void*)md5_end;
  799. + hash_len = 16;
  800. + } else {
  801. + bb_error_msg_and_die("algorithm not supported");
  802. + }
  803. +
  804. + while ((count = safe_read(src_fd, in_buf, 4096)) > 0) {
  805. + update(&context, in_buf, count);
  806. + }
  807. +
  808. + if (count == 0) {
  809. + final(&context, in_buf);
  810. + hash_value = hash_bin_to_hex(in_buf, hash_len);
  811. + }
  812. +
  813. + RELEASE_CONFIG_BUFFER(in_buf);
  814. +
  815. + if (src_fd != STDIN_FILENO) {
  816. + close(src_fd);
  817. + }
  818. +
  819. + return hash_value;
  820. +}
  821. +
  822. +uint8_t *file_md5sum_alloc(const char *file_name)
  823. +{
  824. + return hash_file(file_name, HASH_MD5);
  825. +}
  826. +
  827. --- /dev/null
  828. +++ busybox-1.18.1/archival/libipkg/file_util.h
  829. @@ -0,0 +1,29 @@
  830. +/* file_util.h - convenience routines for common file operations
  831. +
  832. + Carl D. Worth
  833. +
  834. + Copyright (C) 2001 University of Southern California
  835. +
  836. + This program is free software; you can redistribute it and/or
  837. + modify it under the terms of the GNU General Public License as
  838. + published by the Free Software Foundation; either version 2, or (at
  839. + your option) any later version.
  840. +
  841. + This program is distributed in the hope that it will be useful, but
  842. + WITHOUT ANY WARRANTY; without even the implied warranty of
  843. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  844. + General Public License for more details.
  845. +*/
  846. +
  847. +#ifndef FILE_UTIL_H
  848. +#define FILE_UTIL_H
  849. +
  850. +int file_exists(const char *file_name);
  851. +int file_is_dir(const char *file_name);
  852. +char *file_read_line_alloc(FILE *file);
  853. +int file_move(const char *src, const char *dest);
  854. +int file_copy(const char *src, const char *dest);
  855. +int file_mkdir_hier(char *path, long mode);
  856. +uint8_t *file_md5sum_alloc(const char *file_name);
  857. +
  858. +#endif
  859. --- /dev/null
  860. +++ busybox-1.18.1/archival/libipkg/hash_table.c
  861. @@ -0,0 +1,155 @@
  862. +/* hash.c - hash tables for ipkg
  863. +
  864. + Steven M. Ayer, Jamey Hicks
  865. +
  866. + Copyright (C) 2002 Compaq Computer Corporation
  867. +
  868. + This program is free software; you can redistribute it and/or
  869. + modify it under the terms of the GNU General Public License as
  870. + published by the Free Software Foundation; either version 2, or (at
  871. + your option) any later version.
  872. +
  873. + This program is distributed in the hope that it will be useful, but
  874. + WITHOUT ANY WARRANTY; without even the implied warranty of
  875. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  876. + General Public License for more details.
  877. +*/
  878. +
  879. +#include <errno.h>
  880. +#include <stdio.h>
  881. +#include <stdlib.h>
  882. +#include <string.h>
  883. +#include "hash_table.h"
  884. +#include "ipkg_message.h"
  885. +
  886. +
  887. +static int hash_index(hash_table_t *hash, const char *pkg_name);
  888. +static int rotating(const char *key, int len, int prime);
  889. +
  890. +static int hash_index(hash_table_t *hash, const char *pkg_name)
  891. +{
  892. + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
  893. +}
  894. +
  895. +static int rotating(const char *key, int len, int prime)
  896. +{
  897. + unsigned int hash, i;
  898. + for (hash=len, i=0; i<len; ++i)
  899. + hash = (hash<<4)^(hash>>28)^key[i];
  900. + return (hash % prime);
  901. +}
  902. +
  903. +
  904. +/*
  905. + * this is an open table keyed by strings
  906. + */
  907. +int hash_table_init(const char *name, hash_table_t *hash, int len)
  908. +{
  909. + static int primes_table[] = {
  910. + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
  911. + 19471, 23143, 33961, 46499, 49727, 99529, 0
  912. + };
  913. + int *picker;
  914. +
  915. + if (hash->entries != NULL) {
  916. + /* we have been here already */
  917. + return 0;
  918. + }
  919. +
  920. + hash->name = name;
  921. + hash->entries = NULL;
  922. + hash->n_entries = 0;
  923. + hash->hash_entry_key = NULL;
  924. +
  925. + picker = primes_table;
  926. + while(*picker && (*picker++ < len));
  927. + if(!*picker)
  928. + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
  929. + --picker;
  930. +
  931. + hash->n_entries = *picker;
  932. + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
  933. + if (hash->entries == NULL) {
  934. + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
  935. + return ENOMEM;
  936. + }
  937. + return 0;
  938. +}
  939. +
  940. +void hash_table_deinit(hash_table_t *hash)
  941. +{
  942. + free(hash->entries);
  943. + hash->entries = NULL;
  944. + hash->n_entries = 0;
  945. +}
  946. +
  947. +void *hash_table_get(hash_table_t *hash, const char *key)
  948. +{
  949. + int ndx= hash_index(hash, key);
  950. + hash_entry_t *hash_entry = hash->entries + ndx;
  951. + while (hash_entry)
  952. + {
  953. + if (hash_entry->key)
  954. + {
  955. + if (strcmp(key, hash_entry->key) == 0) {
  956. + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
  957. + return hash_entry->data;
  958. + }
  959. + }
  960. + hash_entry = hash_entry->next;
  961. + }
  962. + return NULL;
  963. +}
  964. +
  965. +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
  966. +{
  967. + int ndx= hash_index(hash, key);
  968. + hash_entry_t *hash_entry = hash->entries + ndx;
  969. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
  970. + if (hash_entry->key) {
  971. + if (strcmp(hash_entry->key, key) == 0) {
  972. + /* alread in table, update the value */
  973. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
  974. + hash_entry->data = value;
  975. + return 0;
  976. + } else {
  977. + /*
  978. + * if this is a collision, we have to go to the end of the ll,
  979. + * then add a new entry
  980. + * before we can hook up the value
  981. + */
  982. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
  983. + while (hash_entry->next)
  984. + hash_entry = hash_entry->next;
  985. + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
  986. + if (!hash_entry->next) {
  987. + return -ENOMEM;
  988. + }
  989. + hash_entry = hash_entry->next;
  990. + hash_entry->next = NULL;
  991. + }
  992. + }
  993. + hash->n_elements++;
  994. + hash_entry->key = strdup(key);
  995. + hash_entry->data = value;
  996. +
  997. + return 0;
  998. +}
  999. +
  1000. +
  1001. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
  1002. +{
  1003. + int i;
  1004. + if (!hash || !f)
  1005. + return;
  1006. +
  1007. + for (i = 0; i < hash->n_entries; i++) {
  1008. + hash_entry_t *hash_entry = (hash->entries + i);
  1009. + do {
  1010. + if(hash_entry->key) {
  1011. + f(hash_entry->key, hash_entry->data, data);
  1012. + }
  1013. + } while((hash_entry = hash_entry->next));
  1014. + }
  1015. +}
  1016. +
  1017. --- /dev/null
  1018. +++ busybox-1.18.1/archival/libipkg/hash_table.h
  1019. @@ -0,0 +1,44 @@
  1020. +/* hash.h - hash tables for ipkg
  1021. +
  1022. + Steven M. Ayer, Jamey Hicks
  1023. +
  1024. + Copyright (C) 2002 Compaq Computer Corporation
  1025. +
  1026. + This program is free software; you can redistribute it and/or
  1027. + modify it under the terms of the GNU General Public License as
  1028. + published by the Free Software Foundation; either version 2, or (at
  1029. + your option) any later version.
  1030. +
  1031. + This program is distributed in the hope that it will be useful, but
  1032. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1033. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1034. + General Public License for more details.
  1035. +*/
  1036. +
  1037. +#ifndef _HASH_TABLE_H_
  1038. +#define _HASH_TABLE_H_
  1039. +
  1040. +typedef struct hash_entry hash_entry_t;
  1041. +typedef struct hash_table hash_table_t;
  1042. +
  1043. +struct hash_entry {
  1044. + const char * key;
  1045. + void * data;
  1046. + struct hash_entry * next;
  1047. +};
  1048. +
  1049. +struct hash_table {
  1050. + const char *name;
  1051. + hash_entry_t * entries;
  1052. + int n_entries; /* number of buckets */
  1053. + int n_elements;
  1054. + const char * (*hash_entry_key)(void * data);
  1055. +};
  1056. +
  1057. +int hash_table_init(const char *name, hash_table_t *hash, int len);
  1058. +void hash_table_deinit(hash_table_t *hash);
  1059. +void *hash_table_get(hash_table_t *hash, const char *key);
  1060. +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
  1061. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
  1062. +
  1063. +#endif /* _HASH_TABLE_H_ */
  1064. --- /dev/null
  1065. +++ busybox-1.18.1/archival/libipkg/ipkg.h
  1066. @@ -0,0 +1,68 @@
  1067. +/* ipkg.h - the itsy package management system
  1068. +
  1069. + Carl D. Worth
  1070. +
  1071. + Copyright (C) 2001 University of Southern California
  1072. +
  1073. + This program is free software; you can redistribute it and/or
  1074. + modify it under the terms of the GNU General Public License as
  1075. + published by the Free Software Foundation; either version 2, or (at
  1076. + your option) any later version.
  1077. +
  1078. + This program is distributed in the hope that it will be useful, but
  1079. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1080. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1081. + General Public License for more details.
  1082. +*/
  1083. +
  1084. +#ifndef IPKG_H
  1085. +#define IPKG_H
  1086. +
  1087. +#include "libbb.h"
  1088. +
  1089. +#include "ipkg_includes.h"
  1090. +#include "ipkg_conf.h"
  1091. +#include "ipkg_message.h"
  1092. +
  1093. +#define IPKG_PKG_EXTENSION ".ipk"
  1094. +#define DPKG_PKG_EXTENSION ".deb"
  1095. +
  1096. +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
  1097. +#define IPKG_PKG_VERSION_SEP_CHAR '_'
  1098. +
  1099. +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
  1100. +#define IPKG_LISTS_DIR_SUFFIX "lists"
  1101. +#define IPKG_INFO_DIR_SUFFIX "info"
  1102. +#define IPKG_STATUS_FILE_SUFFIX "status"
  1103. +
  1104. +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
  1105. +
  1106. +#define IPKG_LIST_DESCRIPTION_LENGTH 128
  1107. +
  1108. +#define IPKG_VERSION "1.00"
  1109. +
  1110. +
  1111. +enum ipkg_error {
  1112. + IPKG_SUCCESS = 0,
  1113. + IPKG_PKG_DEPS_UNSATISFIED,
  1114. + IPKG_PKG_IS_ESSENTIAL,
  1115. + IPKG_PKG_HAS_DEPENDENTS,
  1116. + IPKG_PKG_HAS_NO_CANDIDATE
  1117. +};
  1118. +typedef enum ipkg_error ipkg_error_t;
  1119. +
  1120. +extern int ipkg_state_changed;
  1121. +
  1122. +
  1123. +struct errlist {
  1124. + char * errmsg;
  1125. + struct errlist * next;
  1126. +} ;
  1127. +
  1128. +extern struct errlist* error_list;
  1129. +
  1130. +extern ipkg_conf_t *global_conf;
  1131. +
  1132. +typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
  1133. +
  1134. +#endif
  1135. --- /dev/null
  1136. +++ busybox-1.18.1/archival/libipkg/ipkg_cmd.c
  1137. @@ -0,0 +1,1366 @@
  1138. +/* ipkg_cmd.c - the itsy package management system
  1139. +
  1140. + Carl D. Worth
  1141. +
  1142. + Copyright (C) 2001 University of Southern California
  1143. +
  1144. + This program is free software; you can redistribute it and/or
  1145. + modify it under the terms of the GNU General Public License as
  1146. + published by the Free Software Foundation; either version 2, or (at
  1147. + your option) any later version.
  1148. +
  1149. + This program is distributed in the hope that it will be useful, but
  1150. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1151. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1152. + General Public License for more details.
  1153. +*/
  1154. +
  1155. +#include <string.h>
  1156. +
  1157. +#include "ipkg.h"
  1158. +#include <libgen.h>
  1159. +#include <glob.h>
  1160. +#include <errno.h>
  1161. +#include <stdlib.h>
  1162. +#include <unistd.h>
  1163. +#include <signal.h>
  1164. +#include <stdio.h>
  1165. +#include <dirent.h>
  1166. +
  1167. +#include "ipkg_conf.h"
  1168. +#include "ipkg_cmd.h"
  1169. +#include "ipkg_message.h"
  1170. +#include "pkg.h"
  1171. +#include "pkg_dest.h"
  1172. +#include "pkg_parse.h"
  1173. +#include "sprintf_alloc.h"
  1174. +#include "pkg.h"
  1175. +#include "file_util.h"
  1176. +#include "str_util.h"
  1177. +#include "archive.h"
  1178. +
  1179. +#include <fnmatch.h>
  1180. +
  1181. +
  1182. +#include "ipkg_download.h"
  1183. +#include "ipkg_install.h"
  1184. +#include "ipkg_upgrade.h"
  1185. +#include "ipkg_remove.h"
  1186. +#include "ipkg_configure.h"
  1187. +#include "ipkg_message.h"
  1188. +
  1189. +#include "libipkg.h"
  1190. +static void *p_userdata = NULL;
  1191. +
  1192. +static int ipkg_update_cmd(ipkg_conf_t *conf);
  1193. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1194. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1195. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1196. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1197. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf);
  1198. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1199. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1200. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1201. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1202. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1203. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1204. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1205. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1206. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1207. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1208. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1209. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1210. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1211. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1212. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1213. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1214. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1215. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf);
  1216. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1217. +
  1218. +/* XXX: CLEANUP: The usage strings should be incorporated into this
  1219. + array for easier maintenance */
  1220. +static ipkg_cmd_t cmds[] = {
  1221. + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
  1222. + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
  1223. + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
  1224. + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
  1225. + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
  1226. + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
  1227. + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
  1228. + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
  1229. + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
  1230. + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
  1231. + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
  1232. + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
  1233. + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
  1234. + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
  1235. + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
  1236. + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1237. + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1238. + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1239. + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1240. + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1241. + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1242. + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
  1243. + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
  1244. + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
  1245. + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
  1246. + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
  1247. + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
  1248. + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
  1249. + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
  1250. +};
  1251. +
  1252. +int ipkg_state_changed;
  1253. +static void write_status_files_if_changed(ipkg_conf_t *conf)
  1254. +{
  1255. + if (ipkg_state_changed && !conf->noaction) {
  1256. + ipkg_message(conf, IPKG_INFO,
  1257. + " writing status file\n");
  1258. + ipkg_conf_write_status_files(conf);
  1259. + pkg_write_changed_filelists(conf);
  1260. + } else {
  1261. + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
  1262. + }
  1263. +}
  1264. +
  1265. +
  1266. +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
  1267. +
  1268. +ipkg_cmd_t *ipkg_cmd_find(const char *name)
  1269. +{
  1270. + int i;
  1271. + ipkg_cmd_t *cmd;
  1272. +
  1273. + for (i=0; i < num_cmds; i++) {
  1274. + cmd = &cmds[i];
  1275. + if (strcmp(name, cmd->name) == 0) {
  1276. + return cmd;
  1277. + }
  1278. + }
  1279. +
  1280. + return NULL;
  1281. +}
  1282. +
  1283. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
  1284. +{
  1285. + int result;
  1286. + p_userdata = userdata;
  1287. +
  1288. +
  1289. + result = (cmd->fun)(conf, argc, argv);
  1290. + if ( result == 0 ) {
  1291. + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
  1292. + } else {
  1293. + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
  1294. +
  1295. + }
  1296. + if ( error_list ) {
  1297. + reverse_error_list(&error_list);
  1298. +
  1299. + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
  1300. + /* Here we print the errors collected and free the list */
  1301. + while (error_list != NULL) {
  1302. + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
  1303. + error_list = error_list->next;
  1304. +
  1305. + }
  1306. + free_error_list(&error_list);
  1307. +
  1308. + }
  1309. +
  1310. + p_userdata = NULL;
  1311. + return result;
  1312. +}
  1313. +
  1314. +static int ipkg_update_cmd(ipkg_conf_t *conf)
  1315. +{
  1316. + int err;
  1317. + int failures;
  1318. + char *lists_dir;
  1319. + pkg_src_list_elt_t *iter;
  1320. + pkg_src_t *src;
  1321. +
  1322. +
  1323. + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
  1324. +
  1325. + if (! file_is_dir(lists_dir)) {
  1326. + if (file_exists(lists_dir)) {
  1327. + ipkg_message(conf, IPKG_ERROR,
  1328. + "%s: ERROR: %s exists, but is not a directory\n",
  1329. + __FUNCTION__, lists_dir);
  1330. + free(lists_dir);
  1331. + return EINVAL;
  1332. + }
  1333. + err = file_mkdir_hier(lists_dir, 0755);
  1334. + if (err) {
  1335. + ipkg_message(conf, IPKG_ERROR,
  1336. + "%s: ERROR: failed to make directory %s: %s\n",
  1337. + __FUNCTION__, lists_dir, strerror(errno));
  1338. + free(lists_dir);
  1339. + return EINVAL;
  1340. + }
  1341. + }
  1342. +
  1343. + failures = 0;
  1344. + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
  1345. + char *url, *list_file_name;
  1346. +
  1347. + src = iter->data;
  1348. +
  1349. + if (src->extra_data) /* debian style? */
  1350. + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
  1351. + src->gzip ? "Packages.gz" : "Packages");
  1352. + else
  1353. + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
  1354. +
  1355. + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
  1356. + if (src->gzip) {
  1357. + char *tmp;
  1358. + char *tmp_file_name;
  1359. + FILE *in, *out;
  1360. +
  1361. + tmp = strdup ("/tmp/ipkg.XXXXXX");
  1362. +
  1363. + if (mkdtemp (tmp) == NULL) {
  1364. + perror ("mkdtemp");
  1365. + failures++;
  1366. + continue;
  1367. + }
  1368. +
  1369. + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
  1370. + err = ipkg_download(conf, url, tmp_file_name);
  1371. + if (err == 0) {
  1372. + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
  1373. + in = fopen (tmp_file_name, "r");
  1374. + out = fopen (list_file_name, "w");
  1375. + if (in && out) {
  1376. + inflate_unzip_result res;
  1377. + inflate_unzip (&res, 0x8000, fileno(in), fileno(out));
  1378. + } else
  1379. + err = 1;
  1380. + if (in)
  1381. + fclose (in);
  1382. + if (out)
  1383. + fclose (out);
  1384. + unlink (tmp_file_name);
  1385. + rmdir (tmp);
  1386. + free (tmp);
  1387. + }
  1388. + } else
  1389. + err = ipkg_download(conf, url, list_file_name);
  1390. + if (err) {
  1391. + failures++;
  1392. + } else {
  1393. + ipkg_message(conf, IPKG_NOTICE,
  1394. + "Updated list of available packages in %s\n",
  1395. + list_file_name);
  1396. + }
  1397. + free(url);
  1398. + free(list_file_name);
  1399. + }
  1400. + free(lists_dir);
  1401. +
  1402. +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
  1403. +#warning here
  1404. + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
  1405. + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
  1406. + * -Jamey 3/1/03
  1407. + */
  1408. + {
  1409. + int i;
  1410. + int changed = 0;
  1411. + pkg_vec_t *available = pkg_vec_alloc();
  1412. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1413. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
  1414. + for (i = 0; i < available->len; i++) {
  1415. + pkg_t *pkg = available->pkgs[i];
  1416. + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
  1417. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
  1418. + pkg->state_want = SW_UNKNOWN;
  1419. + changed = 1;
  1420. + }
  1421. + }
  1422. + pkg_vec_free(available);
  1423. + if (changed) {
  1424. + write_status_files_if_changed(conf);
  1425. + }
  1426. + }
  1427. +#endif
  1428. +
  1429. + return failures;
  1430. +}
  1431. +
  1432. +
  1433. +/* scan the args passed and cache the local filenames of the packages */
  1434. +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
  1435. +{
  1436. + int i;
  1437. + int err;
  1438. +
  1439. + /*
  1440. + * First scan through package names/urls
  1441. + * For any urls, download the packages and install in database.
  1442. + * For any files, install package info in database.
  1443. + */
  1444. + for (i = 0; i < argc; i ++) {
  1445. + char *filename = argv [i];
  1446. + //char *tmp = basename (tmp);
  1447. + //int tmplen = strlen (tmp);
  1448. +
  1449. + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
  1450. + // continue;
  1451. + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
  1452. + // continue;
  1453. +
  1454. + ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename );
  1455. +
  1456. + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
  1457. + if (err)
  1458. + return err;
  1459. + }
  1460. + return 0;
  1461. +}
  1462. +
  1463. +struct ipkg_intercept
  1464. +{
  1465. + char *oldpath;
  1466. + char *statedir;
  1467. +};
  1468. +
  1469. +typedef struct ipkg_intercept *ipkg_intercept_t;
  1470. +ipkg_intercept_t ipkg_prep_intercepts(void);
  1471. +
  1472. +ipkg_intercept_t ipkg_prep_intercepts(void)
  1473. +{
  1474. + ipkg_intercept_t ctx;
  1475. + char *newpath;
  1476. + int gen;
  1477. +
  1478. + ctx = malloc (sizeof (*ctx));
  1479. + ctx->oldpath = strdup (getenv ("PATH"));
  1480. +
  1481. + sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath);
  1482. + setenv ("PATH", newpath, 1);
  1483. + free (newpath);
  1484. +
  1485. + gen = 0;
  1486. + retry:
  1487. + sprintf_alloc (&ctx->statedir, "/tmp/ipkg-intercept-%d-%d", getpid (), gen);
  1488. + if (mkdir (ctx->statedir, 0770) < 0) {
  1489. + if (errno == EEXIST) {
  1490. + free (ctx->statedir);
  1491. + gen++;
  1492. + goto retry;
  1493. + }
  1494. + perror (ctx->statedir);
  1495. + return NULL;
  1496. + }
  1497. + setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1);
  1498. + return ctx;
  1499. +}
  1500. +
  1501. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx);
  1502. +
  1503. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx)
  1504. +{
  1505. + char *cmd;
  1506. + DIR *dir;
  1507. + int err = 0;
  1508. +
  1509. + setenv ("PATH", ctx->oldpath, 1);
  1510. + free (ctx->oldpath);
  1511. +
  1512. + dir = opendir (ctx->statedir);
  1513. + if (dir) {
  1514. + struct dirent *de;
  1515. + while (de = readdir (dir), de != NULL) {
  1516. + char *path;
  1517. +
  1518. + if (de->d_name[0] == '.')
  1519. + continue;
  1520. +
  1521. + sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name);
  1522. + if (access (path, X_OK) == 0) {
  1523. + if (system (path)) {
  1524. + err = errno;
  1525. + perror (de->d_name);
  1526. + }
  1527. + }
  1528. + free (path);
  1529. + }
  1530. + } else
  1531. + perror (ctx->statedir);
  1532. +
  1533. + sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
  1534. + system (cmd);
  1535. + free (cmd);
  1536. +
  1537. + free (ctx->statedir);
  1538. + free (ctx);
  1539. +
  1540. + return err;
  1541. +}
  1542. +
  1543. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
  1544. +{
  1545. + pkg_vec_t *all;
  1546. + int i;
  1547. + pkg_t *pkg;
  1548. + ipkg_intercept_t ic;
  1549. + int r, err = 0;
  1550. +
  1551. + ipkg_message(conf, IPKG_INFO,
  1552. + "Configuring unpacked packages\n");
  1553. + fflush( stdout );
  1554. +
  1555. + all = pkg_vec_alloc();
  1556. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  1557. +
  1558. + ic = ipkg_prep_intercepts();
  1559. +
  1560. + for(i = 0; i < all->len; i++) {
  1561. + pkg = all->pkgs[i];
  1562. +
  1563. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1564. + continue;
  1565. +
  1566. + if (pkg->state_status == SS_UNPACKED) {
  1567. + ipkg_message(conf, IPKG_NOTICE,
  1568. + "Configuring %s\n", pkg->name);
  1569. + fflush( stdout );
  1570. + r = ipkg_configure(conf, pkg);
  1571. + if (r == 0) {
  1572. + pkg->state_status = SS_INSTALLED;
  1573. + pkg->parent->state_status = SS_INSTALLED;
  1574. + pkg->state_flag &= ~SF_PREFER;
  1575. + } else {
  1576. + if (!err)
  1577. + err = r;
  1578. + }
  1579. + }
  1580. + }
  1581. +
  1582. + r = ipkg_finalize_intercepts (ic);
  1583. + if (r && !err)
  1584. + err = r;
  1585. +
  1586. + pkg_vec_free(all);
  1587. + return err;
  1588. +}
  1589. +
  1590. +static void sigint_handler(int sig)
  1591. +{
  1592. + signal(sig, SIG_DFL);
  1593. + ipkg_message(NULL, IPKG_NOTICE,
  1594. + "ipkg: interrupted. writing out status database\n");
  1595. + write_status_files_if_changed(global_conf);
  1596. + exit(128 + sig);
  1597. +}
  1598. +
  1599. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1600. +{
  1601. + int i;
  1602. + char *arg;
  1603. + int err=0;
  1604. +
  1605. + global_conf = conf;
  1606. + signal(SIGINT, sigint_handler);
  1607. +
  1608. + /*
  1609. + * Now scan through package names and install
  1610. + */
  1611. + for (i=0; i < argc; i++) {
  1612. + arg = argv[i];
  1613. +
  1614. + ipkg_message(conf, IPKG_DEBUG2, "Debug install_cmd: %s \n",arg );
  1615. + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
  1616. + if (err != EINVAL && err != 0)
  1617. + return err;
  1618. + }
  1619. + pkg_info_preinstall_check(conf);
  1620. +
  1621. + for (i=0; i < argc; i++) {
  1622. + arg = argv[i];
  1623. + if (conf->multiple_providers)
  1624. + err = ipkg_install_multi_by_name(conf, arg);
  1625. + else{
  1626. + err = ipkg_install_by_name(conf, arg);
  1627. + }
  1628. + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
  1629. + ipkg_message(conf, IPKG_ERROR,
  1630. + "Cannot find package %s.\n"
  1631. + "Check the spelling or perhaps run 'ipkg update'\n",
  1632. + arg);
  1633. + }
  1634. + }
  1635. +
  1636. + /* recheck to verify that all dependences are satisfied */
  1637. + if (0) ipkg_satisfy_all_dependences(conf);
  1638. +
  1639. + ipkg_configure_packages(conf, NULL);
  1640. +
  1641. + write_status_files_if_changed(conf);
  1642. +
  1643. + return err;
  1644. +}
  1645. +
  1646. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1647. +{
  1648. + int i;
  1649. + pkg_t *pkg;
  1650. + int err;
  1651. +
  1652. + global_conf = conf;
  1653. + signal(SIGINT, sigint_handler);
  1654. +
  1655. + if (argc) {
  1656. + for (i=0; i < argc; i++) {
  1657. + char *arg = argv[i];
  1658. +
  1659. + err = ipkg_prepare_url_for_install(conf, arg, &arg);
  1660. + if (err != EINVAL && err != 0)
  1661. + return err;
  1662. + }
  1663. + pkg_info_preinstall_check(conf);
  1664. +
  1665. + for (i=0; i < argc; i++) {
  1666. + char *arg = argv[i];
  1667. + if (conf->restrict_to_default_dest) {
  1668. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1669. + argv[i],
  1670. + conf->default_dest);
  1671. + if (pkg == NULL) {
  1672. + ipkg_message(conf, IPKG_NOTICE,
  1673. + "Package %s not installed in %s\n",
  1674. + argv[i], conf->default_dest->name);
  1675. + continue;
  1676. + }
  1677. + } else {
  1678. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  1679. + argv[i]);
  1680. + }
  1681. + if (pkg)
  1682. + ipkg_upgrade_pkg(conf, pkg);
  1683. + else {
  1684. + ipkg_install_by_name(conf, arg);
  1685. + }
  1686. + }
  1687. + } else {
  1688. + pkg_vec_t *installed = pkg_vec_alloc();
  1689. +
  1690. + pkg_info_preinstall_check(conf);
  1691. +
  1692. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  1693. + for (i = 0; i < installed->len; i++) {
  1694. + pkg = installed->pkgs[i];
  1695. + ipkg_upgrade_pkg(conf, pkg);
  1696. + }
  1697. + pkg_vec_free(installed);
  1698. + }
  1699. +
  1700. + /* recheck to verify that all dependences are satisfied */
  1701. + if (0) ipkg_satisfy_all_dependences(conf);
  1702. +
  1703. + ipkg_configure_packages(conf, NULL);
  1704. +
  1705. + write_status_files_if_changed(conf);
  1706. +
  1707. + return 0;
  1708. +}
  1709. +
  1710. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1711. +{
  1712. + int i, err;
  1713. + char *arg;
  1714. + pkg_t *pkg;
  1715. +
  1716. + pkg_info_preinstall_check(conf);
  1717. + for (i = 0; i < argc; i++) {
  1718. + arg = argv[i];
  1719. +
  1720. + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
  1721. + if (pkg == NULL) {
  1722. + ipkg_message(conf, IPKG_ERROR,
  1723. + "Cannot find package %s.\n"
  1724. + "Check the spelling or perhaps run 'ipkg update'\n",
  1725. + arg);
  1726. + continue;
  1727. + }
  1728. +
  1729. + err = ipkg_download_pkg(conf, pkg, ".");
  1730. +
  1731. + if (err) {
  1732. + ipkg_message(conf, IPKG_ERROR,
  1733. + "Failed to download %s\n", pkg->name);
  1734. + } else {
  1735. + ipkg_message(conf, IPKG_NOTICE,
  1736. + "Downloaded %s as %s\n",
  1737. + pkg->name, pkg->local_filename);
  1738. + }
  1739. + }
  1740. +
  1741. + return 0;
  1742. +}
  1743. +
  1744. +
  1745. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1746. +{
  1747. + int i ;
  1748. + pkg_vec_t *available;
  1749. + pkg_t *pkg;
  1750. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1751. + char *newline;
  1752. + char *pkg_name = NULL;
  1753. + char *version_str;
  1754. +
  1755. + if (argc > 0) {
  1756. + pkg_name = argv[0];
  1757. + }
  1758. + available = pkg_vec_alloc();
  1759. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1760. + for (i=0; i < available->len; i++) {
  1761. + pkg = available->pkgs[i];
  1762. + /* if we have package name or pattern and pkg does not match, then skip it */
  1763. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1764. + continue;
  1765. + if (pkg->description) {
  1766. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1767. + } else {
  1768. + desc_short[0] = '\0';
  1769. + }
  1770. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1771. + newline = strchr(desc_short, '\n');
  1772. + if (newline) {
  1773. + *newline = '\0';
  1774. + }
  1775. + if (ipkg_cb_list) {
  1776. + version_str = pkg_version_str_alloc(pkg);
  1777. + ipkg_cb_list(pkg->name,desc_short,
  1778. + version_str,
  1779. + pkg->state_status,
  1780. + p_userdata);
  1781. + free(version_str);
  1782. + }
  1783. + }
  1784. + pkg_vec_free(available);
  1785. +
  1786. + return 0;
  1787. +}
  1788. +
  1789. +
  1790. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1791. +{
  1792. + int i ;
  1793. + pkg_vec_t *available;
  1794. + pkg_t *pkg;
  1795. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1796. + char *newline;
  1797. + char *pkg_name = NULL;
  1798. + char *version_str;
  1799. +
  1800. + if (argc > 0) {
  1801. + pkg_name = argv[0];
  1802. + }
  1803. + available = pkg_vec_alloc();
  1804. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1805. + for (i=0; i < available->len; i++) {
  1806. + pkg = available->pkgs[i];
  1807. + /* if we have package name or pattern and pkg does not match, then skip it */
  1808. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1809. + continue;
  1810. + if (pkg->description) {
  1811. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1812. + } else {
  1813. + desc_short[0] = '\0';
  1814. + }
  1815. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1816. + newline = strchr(desc_short, '\n');
  1817. + if (newline) {
  1818. + *newline = '\0';
  1819. + }
  1820. + if (ipkg_cb_list) {
  1821. + version_str = pkg_version_str_alloc(pkg);
  1822. + ipkg_cb_list(pkg->name,desc_short,
  1823. + version_str,
  1824. + pkg->state_status,
  1825. + p_userdata);
  1826. + free(version_str);
  1827. + }
  1828. + }
  1829. +
  1830. + return 0;
  1831. +}
  1832. +
  1833. +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
  1834. +{
  1835. + int i;
  1836. + pkg_vec_t *available;
  1837. + pkg_t *pkg;
  1838. + char *pkg_name = NULL;
  1839. + char **pkg_fields = NULL;
  1840. + int n_fields = 0;
  1841. + char *buff ; // = (char *)malloc(1);
  1842. +
  1843. + if (argc > 0) {
  1844. + pkg_name = argv[0];
  1845. + }
  1846. + if (argc > 1) {
  1847. + pkg_fields = &argv[1];
  1848. + n_fields = argc - 1;
  1849. + }
  1850. +
  1851. + available = pkg_vec_alloc();
  1852. + if (installed_only)
  1853. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1854. + else
  1855. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1856. + for (i=0; i < available->len; i++) {
  1857. + pkg = available->pkgs[i];
  1858. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1859. + continue;
  1860. + }
  1861. + buff = pkg_formatted_info(pkg);
  1862. + if ( buff ) {
  1863. + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
  1864. + pkg->state_status,
  1865. + buff,
  1866. + p_userdata);
  1867. + free(buff);
  1868. + }
  1869. + if (conf->verbosity > 1) {
  1870. + conffile_list_elt_t *iter;
  1871. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  1872. + conffile_t *cf = iter->data;
  1873. + int modified = conffile_has_been_modified(conf, cf);
  1874. + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
  1875. + cf->name, cf->value, modified);
  1876. + }
  1877. + }
  1878. + }
  1879. + pkg_vec_free(available);
  1880. +
  1881. + return 0;
  1882. +}
  1883. +
  1884. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1885. +{
  1886. + return ipkg_info_status_cmd(conf, argc, argv, 0);
  1887. +}
  1888. +
  1889. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1890. +{
  1891. + return ipkg_info_status_cmd(conf, argc, argv, 1);
  1892. +}
  1893. +
  1894. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1895. +{
  1896. +
  1897. + int err;
  1898. + if (argc > 0) {
  1899. + char *pkg_name = NULL;
  1900. +
  1901. + pkg_name = argv[0];
  1902. +
  1903. + err = ipkg_configure_packages (conf, pkg_name);
  1904. +
  1905. + } else {
  1906. + err = ipkg_configure_packages (conf, NULL);
  1907. + }
  1908. +
  1909. + write_status_files_if_changed(conf);
  1910. +
  1911. + return err;
  1912. +}
  1913. +
  1914. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf)
  1915. +{
  1916. + int i, err;
  1917. + char *globpattern;
  1918. + glob_t globbuf;
  1919. +
  1920. + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
  1921. + err = glob(globpattern, 0, NULL, &globbuf);
  1922. + free(globpattern);
  1923. + if (err) {
  1924. + return 0;
  1925. + }
  1926. +
  1927. + ipkg_message(conf, IPKG_NOTICE,
  1928. + "The following packages in %s will now be installed.\n",
  1929. + conf->pending_dir);
  1930. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1931. + ipkg_message(conf, IPKG_NOTICE,
  1932. + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
  1933. + }
  1934. + ipkg_message(conf, IPKG_NOTICE, "\n");
  1935. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1936. + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
  1937. + if (err == 0) {
  1938. + err = unlink(globbuf.gl_pathv[i]);
  1939. + if (err) {
  1940. + ipkg_message(conf, IPKG_ERROR,
  1941. + "%s: ERROR: failed to unlink %s: %s\n",
  1942. + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
  1943. + return err;
  1944. + }
  1945. + }
  1946. + }
  1947. + globfree(&globbuf);
  1948. +
  1949. + return err;
  1950. +}
  1951. +
  1952. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1953. +{
  1954. + int i,a,done;
  1955. + pkg_t *pkg;
  1956. + pkg_t *pkg_to_remove;
  1957. + pkg_vec_t *available;
  1958. + char *pkg_name = NULL;
  1959. + global_conf = conf;
  1960. + signal(SIGINT, sigint_handler);
  1961. +
  1962. +// ENH: Add the "no pkg removed" just in case.
  1963. +
  1964. + done = 0;
  1965. +
  1966. + available = pkg_vec_alloc();
  1967. + pkg_info_preinstall_check(conf);
  1968. + if ( argc > 0 ) {
  1969. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1970. + for (i=0; i < argc; i++) {
  1971. + pkg_name = malloc(strlen(argv[i])+2);
  1972. + strcpy(pkg_name,argv[i]);
  1973. + for (a=0; a < available->len; a++) {
  1974. + pkg = available->pkgs[a];
  1975. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1976. + continue;
  1977. + }
  1978. + if (conf->restrict_to_default_dest) {
  1979. + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1980. + pkg->name,
  1981. + conf->default_dest);
  1982. + } else {
  1983. + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
  1984. + }
  1985. +
  1986. + if (pkg == NULL) {
  1987. + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
  1988. + continue;
  1989. + }
  1990. + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
  1991. + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
  1992. + continue;
  1993. + }
  1994. + ipkg_remove_pkg(conf, pkg_to_remove,0);
  1995. + done = 1;
  1996. + }
  1997. + free (pkg_name);
  1998. + }
  1999. + pkg_vec_free(available);
  2000. + } else {
  2001. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  2002. + int flagged_pkg_count = 0;
  2003. + int removed;
  2004. +
  2005. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
  2006. +
  2007. + for (i = 0; i < installed_pkgs->len; i++) {
  2008. + pkg = installed_pkgs->pkgs[i];
  2009. + if (pkg->state_flag & SF_USER) {
  2010. + flagged_pkg_count++;
  2011. + } else {
  2012. + if (!pkg_has_installed_dependents(pkg, NULL))
  2013. + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
  2014. + }
  2015. + }
  2016. + if (!flagged_pkg_count) {
  2017. + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
  2018. + "so refusing to uninstall unflagged non-leaf packages\n");
  2019. + return 0;
  2020. + }
  2021. +
  2022. + /* find packages not flagged SF_USER (i.e., installed to
  2023. + * satisfy a dependence) and not having any dependents, and
  2024. + * remove them */
  2025. + do {
  2026. + removed = 0;
  2027. + for (i = 0; i < installed_pkgs->len; i++) {
  2028. + pkg = installed_pkgs->pkgs[i];
  2029. + if (!(pkg->state_flag & SF_USER)
  2030. + && !pkg_has_installed_dependents(pkg, NULL)) {
  2031. + removed++;
  2032. + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
  2033. + ipkg_remove_pkg(conf, pkg,0);
  2034. + done = 1;
  2035. + }
  2036. + }
  2037. + } while (removed);
  2038. + pkg_vec_free(installed_pkgs);
  2039. + }
  2040. +
  2041. + if ( done == 0 )
  2042. + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
  2043. +
  2044. + write_status_files_if_changed(conf);
  2045. + return 0;
  2046. +}
  2047. +
  2048. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2049. +{
  2050. + int i;
  2051. + pkg_t *pkg;
  2052. +
  2053. + global_conf = conf;
  2054. + signal(SIGINT, sigint_handler);
  2055. +
  2056. + pkg_info_preinstall_check(conf);
  2057. +
  2058. + for (i=0; i < argc; i++) {
  2059. + if (conf->restrict_to_default_dest) {
  2060. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  2061. + argv[i],
  2062. + conf->default_dest);
  2063. + } else {
  2064. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  2065. + }
  2066. +
  2067. + if (pkg == NULL) {
  2068. + ipkg_message(conf, IPKG_ERROR,
  2069. + "Package %s is not installed.\n", argv[i]);
  2070. + continue;
  2071. + }
  2072. + ipkg_purge_pkg(conf, pkg);
  2073. + }
  2074. +
  2075. + write_status_files_if_changed(conf);
  2076. + return 0;
  2077. +}
  2078. +
  2079. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2080. +{
  2081. + int i;
  2082. + pkg_t *pkg;
  2083. + char *flags = argv[0];
  2084. +
  2085. + global_conf = conf;
  2086. + signal(SIGINT, sigint_handler);
  2087. +
  2088. + for (i=1; i < argc; i++) {
  2089. + if (conf->restrict_to_default_dest) {
  2090. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  2091. + argv[i],
  2092. + conf->default_dest);
  2093. + } else {
  2094. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  2095. + }
  2096. +
  2097. + if (pkg == NULL) {
  2098. + ipkg_message(conf, IPKG_ERROR,
  2099. + "Package %s is not installed.\n", argv[i]);
  2100. + continue;
  2101. + }
  2102. + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
  2103. + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
  2104. + pkg->state_flag = pkg_state_flag_from_str(flags);
  2105. + }
  2106. +/* pb_ asked this feature 03292004 */
  2107. +/* Actually I will use only this two, but this is an open for various status */
  2108. + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
  2109. + pkg->state_status = pkg_state_status_from_str(flags);
  2110. + }
  2111. + ipkg_state_changed++;
  2112. + ipkg_message(conf, IPKG_NOTICE,
  2113. + "Setting flags for package %s to %s\n",
  2114. + pkg->name, flags);
  2115. + }
  2116. +
  2117. + write_status_files_if_changed(conf);
  2118. + return 0;
  2119. +}
  2120. +
  2121. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2122. +{
  2123. + pkg_t *pkg;
  2124. + str_list_t *installed_files;
  2125. + str_list_elt_t *iter;
  2126. + char *pkg_version;
  2127. + size_t buff_len = 8192;
  2128. + size_t used_len;
  2129. + char *buff ;
  2130. +
  2131. + buff = (char *)malloc(buff_len);
  2132. + if ( buff == NULL ) {
  2133. + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
  2134. + return ENOMEM;
  2135. + }
  2136. +
  2137. + if (argc < 1) {
  2138. + return EINVAL;
  2139. + }
  2140. +
  2141. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  2142. + argv[0]);
  2143. + if (pkg == NULL) {
  2144. + ipkg_message(conf, IPKG_ERROR,
  2145. + "Package %s not installed.\n", argv[0]);
  2146. + return 0;
  2147. + }
  2148. +
  2149. + installed_files = pkg_get_installed_files(pkg);
  2150. + pkg_version = pkg_version_str_alloc(pkg);
  2151. +
  2152. + printf("Package %s (%s) is installed on %s and has the following files:\n",
  2153. + pkg->name, pkg_version, pkg->dest->name);
  2154. + for (iter = installed_files->head; iter; iter = iter->next) {
  2155. + puts(iter->data);
  2156. + }
  2157. +
  2158. + free(pkg_version);
  2159. + pkg_free_installed_files(pkg);
  2160. +
  2161. + return 0;
  2162. +}
  2163. +
  2164. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2165. +{
  2166. +
  2167. + if (argc > 0) {
  2168. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2169. + const char *rel_str = "depends on";
  2170. + int i;
  2171. +
  2172. + pkg_info_preinstall_check(conf);
  2173. +
  2174. + if (conf->query_all)
  2175. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2176. + else
  2177. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2178. + for (i = 0; i < argc; i++) {
  2179. + const char *target = argv[i];
  2180. + int j;
  2181. +
  2182. + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
  2183. +
  2184. + for (j = 0; j < available_pkgs->len; j++) {
  2185. + pkg_t *pkg = available_pkgs->pkgs[j];
  2186. + if (fnmatch(target, pkg->name, 0) == 0) {
  2187. + int k;
  2188. + int count = pkg->depends_count + pkg->pre_depends_count;
  2189. + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
  2190. + target, pkg->architecture, rel_str);
  2191. + for (k = 0; k < count; k++) {
  2192. + compound_depend_t *cdepend = &pkg->depends[k];
  2193. + int l;
  2194. + for (l = 0; l < cdepend->possibility_count; l++) {
  2195. + depend_t *possibility = cdepend->possibilities[l];
  2196. + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
  2197. + if (conf->verbosity > 0) {
  2198. + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
  2199. + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
  2200. + if (possibility->version) {
  2201. + const char *typestr = NULL;
  2202. + switch (possibility->constraint) {
  2203. + case NONE: typestr = "none"; break;
  2204. + case EARLIER: typestr = "<"; break;
  2205. + case EARLIER_EQUAL: typestr = "<="; break;
  2206. + case EQUAL: typestr = "="; break;
  2207. + case LATER_EQUAL: typestr = ">="; break;
  2208. + case LATER: typestr = ">"; break;
  2209. + }
  2210. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2211. + }
  2212. + // free(ver);
  2213. + }
  2214. + ipkg_message(conf, IPKG_ERROR, "\n");
  2215. + }
  2216. + }
  2217. + }
  2218. + }
  2219. + }
  2220. + pkg_vec_free(available_pkgs);
  2221. + }
  2222. + return 0;
  2223. +}
  2224. +
  2225. +enum what_field_type {
  2226. + WHATDEPENDS,
  2227. + WHATCONFLICTS,
  2228. + WHATPROVIDES,
  2229. + WHATREPLACES,
  2230. + WHATRECOMMENDS,
  2231. + WHATSUGGESTS
  2232. +};
  2233. +
  2234. +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
  2235. +{
  2236. +
  2237. + if (argc > 0) {
  2238. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2239. + const char *rel_str = NULL;
  2240. + int i;
  2241. + int changed;
  2242. +
  2243. + switch (what_field_type) {
  2244. + case WHATDEPENDS: rel_str = "depends on"; break;
  2245. + case WHATCONFLICTS: rel_str = "conflicts with"; break;
  2246. + case WHATSUGGESTS: rel_str = "suggests"; break;
  2247. + case WHATRECOMMENDS: rel_str = "recommends"; break;
  2248. + case WHATPROVIDES: rel_str = "provides"; break;
  2249. + case WHATREPLACES: rel_str = "replaces"; break;
  2250. + }
  2251. +
  2252. + if (conf->query_all)
  2253. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2254. + else
  2255. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2256. +
  2257. + /* mark the root set */
  2258. + pkg_vec_clear_marks(available_pkgs);
  2259. + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
  2260. + for (i = 0; i < argc; i++) {
  2261. + const char *dependee_pattern = argv[i];
  2262. + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
  2263. + }
  2264. + for (i = 0; i < available_pkgs->len; i++) {
  2265. + pkg_t *pkg = available_pkgs->pkgs[i];
  2266. + if (pkg->state_flag & SF_MARKED) {
  2267. + /* mark the parent (abstract) package */
  2268. + pkg_mark_provides(pkg);
  2269. + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
  2270. + }
  2271. + }
  2272. +
  2273. + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
  2274. + do {
  2275. + int j;
  2276. + changed = 0;
  2277. +
  2278. + for (j = 0; j < available_pkgs->len; j++) {
  2279. + pkg_t *pkg = available_pkgs->pkgs[j];
  2280. + int k;
  2281. + int count = ((what_field_type == WHATCONFLICTS)
  2282. + ? pkg->conflicts_count
  2283. + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
  2284. + /* skip this package if it is already marked */
  2285. + if (pkg->parent->state_flag & SF_MARKED) {
  2286. + continue;
  2287. + }
  2288. + for (k = 0; k < count; k++) {
  2289. + compound_depend_t *cdepend =
  2290. + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
  2291. + int l;
  2292. + for (l = 0; l < cdepend->possibility_count; l++) {
  2293. + depend_t *possibility = cdepend->possibilities[l];
  2294. + if (possibility->pkg->state_flag & SF_MARKED) {
  2295. + /* mark the depending package so we won't visit it again */
  2296. + pkg->state_flag |= SF_MARKED;
  2297. + pkg_mark_provides(pkg);
  2298. + changed++;
  2299. +
  2300. + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
  2301. + if (conf->verbosity > 0) {
  2302. + char *ver = pkg_version_str_alloc(pkg);
  2303. + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
  2304. + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
  2305. + if (possibility->version) {
  2306. + const char *typestr = NULL;
  2307. + switch (possibility->constraint) {
  2308. + case NONE: typestr = "none"; break;
  2309. + case EARLIER: typestr = "<"; break;
  2310. + case EARLIER_EQUAL: typestr = "<="; break;
  2311. + case EQUAL: typestr = "="; break;
  2312. + case LATER_EQUAL: typestr = ">="; break;
  2313. + case LATER: typestr = ">"; break;
  2314. + }
  2315. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2316. + }
  2317. + free(ver);
  2318. + if (!pkg_dependence_satisfiable(possibility))
  2319. + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
  2320. + }
  2321. + ipkg_message(conf, IPKG_NOTICE, "\n");
  2322. + goto next_package;
  2323. + }
  2324. + }
  2325. + }
  2326. + next_package:
  2327. + ;
  2328. + }
  2329. + } while (changed && recursive);
  2330. + pkg_vec_free(available_pkgs);
  2331. + }
  2332. +
  2333. + return 0;
  2334. +}
  2335. +
  2336. +int pkg_mark_provides(pkg_t *pkg)
  2337. +{
  2338. + int provides_count = pkg->provides_count;
  2339. + abstract_pkg_t **provides = pkg->provides;
  2340. + int i;
  2341. + pkg->parent->state_flag |= SF_MARKED;
  2342. + for (i = 0; i < provides_count; i++) {
  2343. + provides[i]->state_flag |= SF_MARKED;
  2344. + }
  2345. + return 0;
  2346. +}
  2347. +
  2348. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2349. +{
  2350. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
  2351. +}
  2352. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2353. +{
  2354. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
  2355. +}
  2356. +
  2357. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2358. +{
  2359. + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
  2360. +}
  2361. +
  2362. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2363. +{
  2364. + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
  2365. +}
  2366. +
  2367. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2368. +{
  2369. + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
  2370. +}
  2371. +
  2372. +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
  2373. +{
  2374. +
  2375. + if (argc > 0) {
  2376. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2377. + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
  2378. + int i;
  2379. +
  2380. + pkg_info_preinstall_check(conf);
  2381. +
  2382. + if (conf->query_all)
  2383. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2384. + else
  2385. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2386. + for (i = 0; i < argc; i++) {
  2387. + const char *target = argv[i];
  2388. + int j;
  2389. +
  2390. + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
  2391. + rel_str, target);
  2392. + for (j = 0; j < available_pkgs->len; j++) {
  2393. + pkg_t *pkg = available_pkgs->pkgs[j];
  2394. + int k;
  2395. + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
  2396. + for (k = 0; k < count; k++) {
  2397. + abstract_pkg_t *apkg =
  2398. + ((what_field_type == WHATPROVIDES)
  2399. + ? pkg->provides[k]
  2400. + : pkg->replaces[k]);
  2401. + if (fnmatch(target, apkg->name, 0) == 0) {
  2402. + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
  2403. + if (strcmp(target, apkg->name) != 0)
  2404. + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
  2405. + ipkg_message(conf, IPKG_ERROR, "\n");
  2406. + }
  2407. + }
  2408. + }
  2409. + }
  2410. + pkg_vec_free(available_pkgs);
  2411. + }
  2412. + return 0;
  2413. +}
  2414. +
  2415. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2416. +{
  2417. + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
  2418. +}
  2419. +
  2420. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2421. +{
  2422. + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
  2423. +}
  2424. +
  2425. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2426. +{
  2427. + int i;
  2428. +
  2429. + pkg_vec_t *installed;
  2430. + pkg_t *pkg;
  2431. + str_list_t *installed_files;
  2432. + str_list_elt_t *iter;
  2433. + char *installed_file;
  2434. +
  2435. + if (argc < 1) {
  2436. + return EINVAL;
  2437. + }
  2438. +
  2439. + installed = pkg_vec_alloc();
  2440. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  2441. +
  2442. + for (i=0; i < installed->len; i++) {
  2443. + pkg = installed->pkgs[i];
  2444. +
  2445. + installed_files = pkg_get_installed_files(pkg);
  2446. +
  2447. + for (iter = installed_files->head; iter; iter = iter->next) {
  2448. + installed_file = iter->data;
  2449. + if (fnmatch(argv[0], installed_file, 0)==0) {
  2450. + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
  2451. + installed_file,
  2452. + pkg_version_str_alloc(pkg),
  2453. + pkg->state_status, p_userdata);
  2454. + }
  2455. + }
  2456. +
  2457. + pkg_free_installed_files(pkg);
  2458. + }
  2459. +
  2460. + /* XXX: CLEANUP: It's not obvious from the name of
  2461. + pkg_hash_fetch_all_installed that we need to call
  2462. + pkg_vec_free to avoid a memory leak. */
  2463. + pkg_vec_free(installed);
  2464. +
  2465. + return 0;
  2466. +}
  2467. +
  2468. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2469. +{
  2470. + if (argc == 3) {
  2471. + /* this is a bit gross */
  2472. + struct pkg p1, p2;
  2473. + parseVersion(&p1, argv[0]);
  2474. + parseVersion(&p2, argv[2]);
  2475. + return pkg_version_satisfied(&p1, &p2, argv[1]);
  2476. + } else {
  2477. + ipkg_message(conf, IPKG_ERROR,
  2478. + "ipkg compare_versions <v1> <op> <v2>\n"
  2479. + "<op> is one of <= >= << >> =\n");
  2480. + return -1;
  2481. + }
  2482. +}
  2483. +
  2484. +#ifndef HOST_CPU_STR
  2485. +#define HOST_CPU_STR__(X) #X
  2486. +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
  2487. +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
  2488. +#endif
  2489. +
  2490. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf)
  2491. +{
  2492. + nv_pair_list_elt_t *l;
  2493. +
  2494. + l = conf->arch_list.head;
  2495. + while (l) {
  2496. + nv_pair_t *nv = l->data;
  2497. + printf("arch %s %s\n", nv->name, nv->value);
  2498. + l = l->next;
  2499. + }
  2500. + return 0;
  2501. +}
  2502. +
  2503. +
  2504. --- /dev/null
  2505. +++ busybox-1.18.1/archival/libipkg/ipkg_cmd.h
  2506. @@ -0,0 +1,41 @@
  2507. +/* ipkg_cmd.h - the itsy package management system
  2508. +
  2509. + Carl D. Worth
  2510. +
  2511. + Copyright (C) 2001 University of Southern California
  2512. +
  2513. + This program is free software; you can redistribute it and/or
  2514. + modify it under the terms of the GNU General Public License as
  2515. + published by the Free Software Foundation; either version 2, or (at
  2516. + your option) any later version.
  2517. +
  2518. + This program is distributed in the hope that it will be useful, but
  2519. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2520. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2521. + General Public License for more details.
  2522. +*/
  2523. +
  2524. +#ifndef IPKG_CMD_H
  2525. +#define IPKG_CMD_H
  2526. +
  2527. +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
  2528. +
  2529. +struct ipkg_cmd
  2530. +{
  2531. + const char *name;
  2532. + int requires_args;
  2533. + ipkg_cmd_fun_t fun;
  2534. +};
  2535. +typedef struct ipkg_cmd ipkg_cmd_t;
  2536. +
  2537. +ipkg_cmd_t *ipkg_cmd_find(const char *name);
  2538. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
  2539. + const char **argv, void *userdata);
  2540. +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
  2541. +/* install any packges with state_want == SW_INSTALL */
  2542. +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
  2543. +/* ensure that all dependences are satisfied */
  2544. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
  2545. +int pkg_mark_provides(pkg_t *pkg);
  2546. +
  2547. +#endif
  2548. --- /dev/null
  2549. +++ busybox-1.18.1/archival/libipkg/ipkg_conf.c
  2550. @@ -0,0 +1,711 @@
  2551. +/* ipkg_conf.c - the itsy package management system
  2552. +
  2553. + Carl D. Worth
  2554. +
  2555. + Copyright (C) 2001 University of Southern California
  2556. +
  2557. + This program is free software; you can redistribute it and/or
  2558. + modify it under the terms of the GNU General Public License as
  2559. + published by the Free Software Foundation; either version 2, or (at
  2560. + your option) any later version.
  2561. +
  2562. + This program is distributed in the hope that it will be useful, but
  2563. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2564. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2565. + General Public License for more details.
  2566. +*/
  2567. +
  2568. +#include <glob.h>
  2569. +
  2570. +#include "ipkg.h"
  2571. +#include "ipkg_conf.h"
  2572. +
  2573. +#include "xregex.h"
  2574. +#include "sprintf_alloc.h"
  2575. +#include "ipkg_conf.h"
  2576. +#include "ipkg_message.h"
  2577. +#include "file_util.h"
  2578. +#include "str_util.h"
  2579. +#include "xsystem.h"
  2580. +
  2581. +
  2582. +ipkg_conf_t *global_conf;
  2583. +
  2584. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  2585. + pkg_src_list_t *pkg_src_list,
  2586. + nv_pair_list_t *tmp_dest_nv_pair_list,
  2587. + char **tmp_lists_dir);
  2588. +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
  2589. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  2590. + const char *name, const char *value);
  2591. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2592. + const char *default_dest_name);
  2593. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
  2594. + pkg_src_list_t *nv_pair_list);
  2595. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
  2596. + nv_pair_list_t *nv_pair_list, char * lists_dir);
  2597. +
  2598. +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
  2599. +{
  2600. + ipkg_option_t tmp[] = {
  2601. + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
  2602. + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
  2603. + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
  2604. + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
  2605. + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
  2606. + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
  2607. + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
  2608. + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
  2609. + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
  2610. + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
  2611. + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
  2612. + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
  2613. + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
  2614. + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
  2615. + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
  2616. + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
  2617. + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
  2618. + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
  2619. + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
  2620. + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
  2621. + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
  2622. + { NULL }
  2623. + };
  2624. +
  2625. + *options = (ipkg_option_t *)malloc(sizeof(tmp));
  2626. + if ( options == NULL ){
  2627. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  2628. + return -1;
  2629. + }
  2630. +
  2631. + memcpy(*options, tmp, sizeof(tmp));
  2632. + return 0;
  2633. +};
  2634. +
  2635. +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
  2636. +{
  2637. + if (arg_str) {
  2638. + if (*conf_str) {
  2639. + free(*conf_str);
  2640. + }
  2641. + *conf_str = strdup(arg_str);
  2642. + }
  2643. +}
  2644. +
  2645. +static void ipkg_conf_free_string(char **conf_str)
  2646. +{
  2647. + if (*conf_str) {
  2648. + free(*conf_str);
  2649. + *conf_str = NULL;
  2650. + }
  2651. +}
  2652. +
  2653. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
  2654. +{
  2655. + int err;
  2656. + char *tmp_dir_base;
  2657. + nv_pair_list_t tmp_dest_nv_pair_list;
  2658. + char * lists_dir =NULL;
  2659. + glob_t globbuf;
  2660. + const char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
  2661. + char *pending_dir =NULL;
  2662. +
  2663. + memset(conf, 0, sizeof(ipkg_conf_t));
  2664. +
  2665. + pkg_src_list_init(&conf->pkg_src_list);
  2666. +
  2667. + nv_pair_list_init(&tmp_dest_nv_pair_list);
  2668. + pkg_dest_list_init(&conf->pkg_dest_list);
  2669. +
  2670. + nv_pair_list_init(&conf->arch_list);
  2671. +
  2672. + conf->restrict_to_default_dest = 0;
  2673. + conf->default_dest = NULL;
  2674. +
  2675. +
  2676. + if (args->tmp_dir)
  2677. + tmp_dir_base = args->tmp_dir;
  2678. + else
  2679. + tmp_dir_base = getenv("TMPDIR");
  2680. + sprintf_alloc(&conf->tmp_dir, "%s/%s",
  2681. + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
  2682. + IPKG_CONF_TMP_DIR_SUFFIX);
  2683. + conf->tmp_dir = mkdtemp(conf->tmp_dir);
  2684. + if (conf->tmp_dir == NULL) {
  2685. + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
  2686. + __FUNCTION__, conf->tmp_dir, strerror(errno));
  2687. + return errno;
  2688. + }
  2689. +
  2690. + conf->force_depends = 0;
  2691. + conf->force_defaults = 0;
  2692. + conf->force_overwrite = 0;
  2693. + conf->force_downgrade = 0;
  2694. + conf->force_reinstall = 0;
  2695. + conf->force_space = 0;
  2696. + conf->force_removal_of_essential_packages = 0;
  2697. + conf->force_removal_of_dependent_packages = 0;
  2698. + conf->nodeps = 0;
  2699. + conf->verbose_wget = 0;
  2700. + conf->offline_root = NULL;
  2701. + conf->offline_root_pre_script_cmd = NULL;
  2702. + conf->offline_root_post_script_cmd = NULL;
  2703. + conf->multiple_providers = 0;
  2704. + conf->verbosity = 1;
  2705. + conf->noaction = 0;
  2706. +
  2707. + conf->http_proxy = NULL;
  2708. + conf->ftp_proxy = NULL;
  2709. + conf->no_proxy = NULL;
  2710. + conf->proxy_user = NULL;
  2711. + conf->proxy_passwd = NULL;
  2712. +
  2713. + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2714. + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2715. + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2716. + lists_dir=(char *)malloc(1);
  2717. + lists_dir[0]='\0';
  2718. + if (args->conf_file) {
  2719. + struct stat stat_buf;
  2720. + err = stat(args->conf_file, &stat_buf);
  2721. + if (err == 0)
  2722. + if (ipkg_conf_parse_file(conf, args->conf_file,
  2723. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2724. + /* Memory leakage from ipkg_conf_parse-file */
  2725. + return -1;
  2726. + }
  2727. +
  2728. + }
  2729. +
  2730. + /* if (!lists_dir ){*/
  2731. + if (strlen(lists_dir)<=1 ){
  2732. + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
  2733. + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
  2734. + }
  2735. +
  2736. + if (args->offline_root) {
  2737. + char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
  2738. + sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
  2739. + free(lists_dir);
  2740. + lists_dir = tmp;
  2741. + }
  2742. +
  2743. + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
  2744. + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
  2745. +
  2746. + conf->lists_dir = strdup(lists_dir);
  2747. + conf->pending_dir = strdup(pending_dir);
  2748. +
  2749. + if (args->offline_root)
  2750. + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
  2751. + memset(&globbuf, 0, sizeof(globbuf));
  2752. + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
  2753. + if (!err) {
  2754. + int i;
  2755. + for (i = 0; i < globbuf.gl_pathc; i++) {
  2756. + if (globbuf.gl_pathv[i])
  2757. + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
  2758. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2759. + /* Memory leakage from ipkg_conf_parse-file */
  2760. + return -1;
  2761. + }
  2762. + }
  2763. + }
  2764. + globfree(&globbuf);
  2765. +
  2766. + /* if no architectures were defined, then default all, noarch, and host architecture */
  2767. + if (nv_pair_list_empty(&conf->arch_list)) {
  2768. + nv_pair_list_append(&conf->arch_list, "all", "1");
  2769. + nv_pair_list_append(&conf->arch_list, "noarch", "1");
  2770. + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
  2771. + }
  2772. +
  2773. + /* Even if there is no conf file, we'll need at least one dest. */
  2774. + if (tmp_dest_nv_pair_list.head == NULL) {
  2775. + nv_pair_list_append(&tmp_dest_nv_pair_list,
  2776. + IPKG_CONF_DEFAULT_DEST_NAME,
  2777. + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
  2778. + }
  2779. +
  2780. + /* After parsing the file, set options from command-line, (so that
  2781. + command-line arguments take precedence) */
  2782. + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
  2783. + really needs to be cleaned up. There is so much duplication
  2784. + right now it is ridiculous. Maybe ipkg_conf_t should just save
  2785. + a pointer to args_t (which could then not be freed), rather
  2786. + than duplicating every field here? */
  2787. + if (args->force_depends) {
  2788. + conf->force_depends = 1;
  2789. + }
  2790. + if (args->force_defaults) {
  2791. + conf->force_defaults = 1;
  2792. + }
  2793. + if (args->force_overwrite) {
  2794. + conf->force_overwrite = 1;
  2795. + }
  2796. + if (args->force_downgrade) {
  2797. + conf->force_downgrade = 1;
  2798. + }
  2799. + if (args->force_reinstall) {
  2800. + conf->force_reinstall = 1;
  2801. + }
  2802. + if (args->force_removal_of_dependent_packages) {
  2803. + conf->force_removal_of_dependent_packages = 1;
  2804. + }
  2805. + if (args->force_removal_of_essential_packages) {
  2806. + conf->force_removal_of_essential_packages = 1;
  2807. + }
  2808. + if (args->nodeps) {
  2809. + conf->nodeps = 1;
  2810. + }
  2811. + if (args->noaction) {
  2812. + conf->noaction = 1;
  2813. + }
  2814. + if (args->query_all) {
  2815. + conf->query_all = 1;
  2816. + }
  2817. + if (args->verbose_wget) {
  2818. + conf->verbose_wget = 1;
  2819. + }
  2820. + if (args->multiple_providers) {
  2821. + conf->multiple_providers = 1;
  2822. + }
  2823. + if (args->verbosity != conf->verbosity) {
  2824. + conf->verbosity = args->verbosity;
  2825. + }
  2826. +
  2827. + ipkg_conf_override_string(&conf->offline_root,
  2828. + args->offline_root);
  2829. + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
  2830. + args->offline_root_pre_script_cmd);
  2831. + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
  2832. + args->offline_root_post_script_cmd);
  2833. +
  2834. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  2835. + read anything from there.
  2836. +*/
  2837. + if ( !(args->nocheckfordirorfile)){
  2838. + /* need to run load the source list before dest list -Jamey */
  2839. + if ( !(args->noreadfeedsfile))
  2840. + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
  2841. +
  2842. + /* Now that we have resolved conf->offline_root, we can commit to
  2843. + the directory names for the dests and load in all the package
  2844. + lists. */
  2845. + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
  2846. +
  2847. + if (args->dest) {
  2848. + err = ipkg_conf_set_default_dest(conf, args->dest);
  2849. + if (err) {
  2850. + return err;
  2851. + }
  2852. + }
  2853. + }
  2854. + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
  2855. + free(lists_dir);
  2856. + free(pending_dir);
  2857. +
  2858. + return 0;
  2859. +}
  2860. +
  2861. +void ipkg_conf_deinit(ipkg_conf_t *conf)
  2862. +{
  2863. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  2864. +#error
  2865. + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
  2866. + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  2867. + __FUNCTION__, conf->tmp_dir);
  2868. +#else
  2869. + int err;
  2870. +
  2871. + err = rmdir(conf->tmp_dir);
  2872. + if (err) {
  2873. + if (errno == ENOTEMPTY) {
  2874. + char *cmd;
  2875. + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
  2876. + err = xsystem(cmd);
  2877. + free(cmd);
  2878. + }
  2879. + if (err)
  2880. + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
  2881. + }
  2882. +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
  2883. +
  2884. + free(conf->tmp_dir); /*XXX*/
  2885. +
  2886. + pkg_src_list_deinit(&conf->pkg_src_list);
  2887. + pkg_dest_list_deinit(&conf->pkg_dest_list);
  2888. + nv_pair_list_deinit(&conf->arch_list);
  2889. + if (&conf->pkg_hash)
  2890. + pkg_hash_deinit(&conf->pkg_hash);
  2891. + if (&conf->file_hash)
  2892. + hash_table_deinit(&conf->file_hash);
  2893. + if (&conf->obs_file_hash)
  2894. + hash_table_deinit(&conf->obs_file_hash);
  2895. +
  2896. + ipkg_conf_free_string(&conf->offline_root);
  2897. + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
  2898. + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
  2899. +
  2900. + if (conf->verbosity > 1) {
  2901. + int i;
  2902. + hash_table_t *hashes[] = {
  2903. + &conf->pkg_hash,
  2904. + &conf->file_hash,
  2905. + &conf->obs_file_hash };
  2906. + for (i = 0; i < 3; i++) {
  2907. + hash_table_t *hash = hashes[i];
  2908. + int c = 0;
  2909. + int n_conflicts = 0;
  2910. + int j;
  2911. + for (j = 0; j < hash->n_entries; j++) {
  2912. + int len = 0;
  2913. + hash_entry_t *e = &hash->entries[j];
  2914. + if (e->next)
  2915. + n_conflicts++;
  2916. + while (e && e->key) {
  2917. + len++;
  2918. + e = e->next;
  2919. + }
  2920. + if (len > c)
  2921. + c = len;
  2922. + }
  2923. + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
  2924. + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
  2925. + hash_table_deinit(hash);
  2926. + }
  2927. + }
  2928. +}
  2929. +
  2930. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2931. + const char *default_dest_name)
  2932. +{
  2933. + pkg_dest_list_elt_t *iter;
  2934. + pkg_dest_t *dest;
  2935. +
  2936. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  2937. + dest = iter->data;
  2938. + if (strcmp(dest->name, default_dest_name) == 0) {
  2939. + conf->default_dest = dest;
  2940. + conf->restrict_to_default_dest = 1;
  2941. + return 0;
  2942. + }
  2943. + }
  2944. +
  2945. + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
  2946. +
  2947. + return 1;
  2948. +}
  2949. +
  2950. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
  2951. +{
  2952. + pkg_src_list_elt_t *iter;
  2953. + pkg_src_t *src;
  2954. + char *list_file;
  2955. +
  2956. + for (iter = pkg_src_list->head; iter; iter = iter->next) {
  2957. + src = iter->data;
  2958. + if (src == NULL) {
  2959. + continue;
  2960. + }
  2961. +
  2962. + sprintf_alloc(&list_file, "%s/%s",
  2963. + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
  2964. + src->name);
  2965. +
  2966. + if (file_exists(list_file)) {
  2967. + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
  2968. + }
  2969. + free(list_file);
  2970. + }
  2971. +
  2972. + return 0;
  2973. +}
  2974. +
  2975. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
  2976. +{
  2977. + nv_pair_list_elt_t *iter;
  2978. + nv_pair_t *nv_pair;
  2979. + pkg_dest_t *dest;
  2980. + char *root_dir;
  2981. +
  2982. + for (iter = nv_pair_list->head; iter; iter = iter->next) {
  2983. + nv_pair = iter->data;
  2984. +
  2985. + if (conf->offline_root) {
  2986. + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
  2987. + } else {
  2988. + root_dir = strdup(nv_pair->value);
  2989. + }
  2990. + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
  2991. + free(root_dir);
  2992. + if (dest == NULL) {
  2993. + continue;
  2994. + }
  2995. + if (conf->default_dest == NULL) {
  2996. + conf->default_dest = dest;
  2997. + }
  2998. + if (file_exists(dest->status_file_name)) {
  2999. + pkg_hash_add_from_file(conf, dest->status_file_name,
  3000. + NULL, dest, 1);
  3001. + }
  3002. + }
  3003. +
  3004. + return 0;
  3005. +}
  3006. +
  3007. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  3008. + pkg_src_list_t *pkg_src_list,
  3009. + nv_pair_list_t *tmp_dest_nv_pair_list,
  3010. + char **lists_dir)
  3011. +{
  3012. + ipkg_option_t * options;
  3013. + FILE *file = fopen(filename, "r");
  3014. + regex_t valid_line_re, comment_re;
  3015. +#define regmatch_size 12
  3016. + regmatch_t regmatch[regmatch_size];
  3017. +
  3018. + if (ipkg_init_options_array(conf, &options)<0)
  3019. + return ENOMEM;
  3020. +
  3021. + if (file == NULL) {
  3022. + fprintf(stderr, "%s: failed to open %s: %s\n",
  3023. + __FUNCTION__, filename, strerror(errno));
  3024. + free(options);
  3025. + return errno;
  3026. + }
  3027. + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
  3028. +
  3029. + xregcomp(&comment_re,
  3030. + "^[[:space:]]*(#.*|[[:space:]]*)$",
  3031. + REG_EXTENDED);
  3032. + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
  3033. +
  3034. + while(1) {
  3035. + int line_num = 0;
  3036. + char *line;
  3037. + char *type, *name, *value, *extra;
  3038. +
  3039. + line = file_read_line_alloc(file);
  3040. + line_num++;
  3041. + if (line == NULL) {
  3042. + break;
  3043. + }
  3044. +
  3045. + str_chomp(line);
  3046. +
  3047. + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
  3048. + goto NEXT_LINE;
  3049. + }
  3050. +
  3051. + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
  3052. + str_chomp(line);
  3053. + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
  3054. + filename, line_num, line);
  3055. + goto NEXT_LINE;
  3056. + }
  3057. +
  3058. + /* This has to be so ugly to deal with optional quotation marks */
  3059. + if (regmatch[2].rm_so > 0) {
  3060. + type = strndup(line + regmatch[2].rm_so,
  3061. + regmatch[2].rm_eo - regmatch[2].rm_so);
  3062. + } else {
  3063. + type = strndup(line + regmatch[3].rm_so,
  3064. + regmatch[3].rm_eo - regmatch[3].rm_so);
  3065. + }
  3066. + if (regmatch[5].rm_so > 0) {
  3067. + name = strndup(line + regmatch[5].rm_so,
  3068. + regmatch[5].rm_eo - regmatch[5].rm_so);
  3069. + } else {
  3070. + name = strndup(line + regmatch[6].rm_so,
  3071. + regmatch[6].rm_eo - regmatch[6].rm_so);
  3072. + }
  3073. + if (regmatch[8].rm_so > 0) {
  3074. + value = strndup(line + regmatch[8].rm_so,
  3075. + regmatch[8].rm_eo - regmatch[8].rm_so);
  3076. + } else {
  3077. + value = strndup(line + regmatch[9].rm_so,
  3078. + regmatch[9].rm_eo - regmatch[9].rm_so);
  3079. + }
  3080. + extra = NULL;
  3081. + if (regmatch[11].rm_so > 0) {
  3082. + extra = strndup (line + regmatch[11].rm_so,
  3083. + regmatch[11].rm_eo - regmatch[11].rm_so);
  3084. + }
  3085. +
  3086. + /* We use the tmp_dest_nv_pair_list below instead of
  3087. + conf->pkg_dest_list because we might encounter an
  3088. + offline_root option later and that would invalidate the
  3089. + directories we would have computed in
  3090. + pkg_dest_list_init. (We do a similar thing with
  3091. + tmp_src_nv_pair_list for sake of symmetry.) */
  3092. + if (strcmp(type, "option") == 0) {
  3093. + ipkg_conf_set_option(options, name, value);
  3094. + } else if (strcmp(type, "src") == 0) {
  3095. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  3096. + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
  3097. + } else {
  3098. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  3099. + name, value);
  3100. + }
  3101. + } else if (strcmp(type, "src/gz") == 0) {
  3102. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  3103. + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
  3104. + } else {
  3105. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  3106. + name, value);
  3107. + }
  3108. + } else if (strcmp(type, "dest") == 0) {
  3109. + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
  3110. + } else if (strcmp(type, "lists_dir") == 0) {
  3111. + *lists_dir = realloc(*lists_dir,strlen(value)+1);
  3112. + if (*lists_dir == NULL) {
  3113. + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
  3114. + free(options);
  3115. + return EINVAL;
  3116. + }
  3117. + sprintf (*lists_dir,"%s",value);
  3118. + } else if (strcmp(type, "arch") == 0) {
  3119. + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
  3120. + if (!value) {
  3121. + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
  3122. + value = strdup("10");
  3123. + }
  3124. + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
  3125. + } else {
  3126. + fprintf(stderr, "WARNING: Ignoring unknown configuration "
  3127. + "parameter: %s %s %s\n", type, name, value);
  3128. + free(options);
  3129. + return EINVAL;
  3130. + }
  3131. +
  3132. + free(type);
  3133. + free(name);
  3134. + free(value);
  3135. + if (extra)
  3136. + free (extra);
  3137. +
  3138. + NEXT_LINE:
  3139. + free(line);
  3140. + }
  3141. +
  3142. + free(options);
  3143. + regfree(&comment_re);
  3144. + regfree(&valid_line_re);
  3145. + fclose(file);
  3146. +
  3147. + return 0;
  3148. +}
  3149. +
  3150. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  3151. + const char *name, const char *value)
  3152. +{
  3153. + int i = 0;
  3154. + while (options[i].name) {
  3155. + if (strcmp(options[i].name, name) == 0) {
  3156. + switch (options[i].type) {
  3157. + case IPKG_OPT_TYPE_BOOL:
  3158. + *((int *)options[i].value) = 1;
  3159. + return 0;
  3160. + case IPKG_OPT_TYPE_INT:
  3161. + if (value) {
  3162. + *((int *)options[i].value) = atoi(value);
  3163. + return 0;
  3164. + } else {
  3165. + printf("%s: Option %s need an argument\n",
  3166. + __FUNCTION__, name);
  3167. + return EINVAL;
  3168. + }
  3169. + case IPKG_OPT_TYPE_STRING:
  3170. + if (value) {
  3171. + *((char **)options[i].value) = strdup(value);
  3172. + return 0;
  3173. + } else {
  3174. + printf("%s: Option %s need an argument\n",
  3175. + __FUNCTION__, name);
  3176. + return EINVAL;
  3177. + }
  3178. + }
  3179. + }
  3180. + i++;
  3181. + }
  3182. +
  3183. + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
  3184. + __FUNCTION__, name, value);
  3185. + return EINVAL;
  3186. +}
  3187. +
  3188. +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
  3189. +{
  3190. + pkg_dest_list_elt_t *iter;
  3191. + pkg_dest_t *dest;
  3192. + pkg_vec_t *all;
  3193. + pkg_t *pkg;
  3194. + register int i;
  3195. + int err;
  3196. +
  3197. + if (conf->noaction)
  3198. + return 0;
  3199. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3200. + dest = iter->data;
  3201. + dest->status_file = fopen(dest->status_file_tmp_name, "w");
  3202. + if (dest->status_file == NULL) {
  3203. + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
  3204. + __FUNCTION__, dest->status_file_name, strerror(errno));
  3205. + }
  3206. + }
  3207. +
  3208. + all = pkg_vec_alloc();
  3209. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  3210. +
  3211. + for(i = 0; i < all->len; i++) {
  3212. + pkg = all->pkgs[i];
  3213. + /* We don't need most uninstalled packages in the status file */
  3214. + if (pkg->state_status == SS_NOT_INSTALLED
  3215. + && (pkg->state_want == SW_UNKNOWN
  3216. + || pkg->state_want == SW_DEINSTALL
  3217. + || pkg->state_want == SW_PURGE)) {
  3218. + continue;
  3219. + }
  3220. + if (!pkg) {
  3221. + fprintf(stderr, "Null package\n");
  3222. + }
  3223. + if (pkg->dest == NULL) {
  3224. + fprintf(stderr, "%s: ERROR: Can't write status for "
  3225. + "package %s since it has a NULL dest\n",
  3226. + __FUNCTION__, pkg->name);
  3227. + continue;
  3228. + }
  3229. + if (pkg->dest->status_file) {
  3230. + pkg_print_status(pkg, pkg->dest->status_file);
  3231. + }
  3232. + }
  3233. +
  3234. + pkg_vec_free(all);
  3235. +
  3236. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3237. + dest = iter->data;
  3238. + if (dest->status_file) {
  3239. + err = ferror(dest->status_file);
  3240. + fclose(dest->status_file);
  3241. + dest->status_file = NULL;
  3242. + if (!err) {
  3243. + file_move(dest->status_file_tmp_name, dest->status_file_name);
  3244. + } else {
  3245. + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
  3246. + "retaining old %s\n", __FUNCTION__,
  3247. + dest->status_file_tmp_name, dest->status_file_name);
  3248. + }
  3249. + }
  3250. + }
  3251. +
  3252. + return 0;
  3253. +}
  3254. +
  3255. +
  3256. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
  3257. +{
  3258. + char *root_filename;
  3259. + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
  3260. + return root_filename;
  3261. +}
  3262. --- /dev/null
  3263. +++ busybox-1.18.1/archival/libipkg/ipkg_conf.h
  3264. @@ -0,0 +1,107 @@
  3265. +/* ipkg_conf.h - the itsy package management system
  3266. +
  3267. + Carl D. Worth
  3268. +
  3269. + Copyright (C) 2001 University of Southern California
  3270. +
  3271. + This program is free software; you can redistribute it and/or
  3272. + modify it under the terms of the GNU General Public License as
  3273. + published by the Free Software Foundation; either version 2, or (at
  3274. + your option) any later version.
  3275. +
  3276. + This program is distributed in the hope that it will be useful, but
  3277. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3278. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3279. + General Public License for more details.
  3280. +*/
  3281. +
  3282. +#ifndef IPKG_CONF_H
  3283. +#define IPKG_CONF_H
  3284. +
  3285. +typedef struct ipkg_conf ipkg_conf_t;
  3286. +
  3287. +#include "hash_table.h"
  3288. +#include "ipkg.h"
  3289. +#include "args.h"
  3290. +#include "pkg.h"
  3291. +#include "pkg_hash.h"
  3292. +#include "pkg_src_list.h"
  3293. +#include "pkg_dest_list.h"
  3294. +#include "nv_pair_list.h"
  3295. +
  3296. +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
  3297. +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
  3298. +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
  3299. +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
  3300. +
  3301. +/* In case the config file defines no dest */
  3302. +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
  3303. +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
  3304. +
  3305. +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
  3306. +
  3307. +struct ipkg_conf
  3308. +{
  3309. + pkg_src_list_t pkg_src_list;
  3310. + pkg_dest_list_t pkg_dest_list;
  3311. + nv_pair_list_t arch_list;
  3312. +
  3313. + int restrict_to_default_dest;
  3314. + pkg_dest_t *default_dest;
  3315. +
  3316. + char *tmp_dir;
  3317. + char *lists_dir;
  3318. + char *pending_dir;
  3319. +
  3320. + /* options */
  3321. + int force_depends;
  3322. + int force_defaults;
  3323. + int force_overwrite;
  3324. + int force_downgrade;
  3325. + int force_reinstall;
  3326. + int force_space;
  3327. + int force_removal_of_dependent_packages;
  3328. + int force_removal_of_essential_packages;
  3329. + int nodeps; /* do not follow dependences */
  3330. + int verbose_wget;
  3331. + int multiple_providers;
  3332. + char *offline_root;
  3333. + char *offline_root_pre_script_cmd;
  3334. + char *offline_root_post_script_cmd;
  3335. + int query_all;
  3336. + int verbosity;
  3337. + int noaction;
  3338. +
  3339. + /* proxy options */
  3340. + char *http_proxy;
  3341. + char *ftp_proxy;
  3342. + char *no_proxy;
  3343. + char *proxy_user;
  3344. + char *proxy_passwd;
  3345. +
  3346. + hash_table_t pkg_hash;
  3347. + hash_table_t file_hash;
  3348. + hash_table_t obs_file_hash;
  3349. +};
  3350. +
  3351. +enum ipkg_option_type {
  3352. + IPKG_OPT_TYPE_BOOL,
  3353. + IPKG_OPT_TYPE_INT,
  3354. + IPKG_OPT_TYPE_STRING
  3355. +};
  3356. +typedef enum ipkg_option_type ipkg_option_type_t;
  3357. +
  3358. +typedef struct ipkg_option ipkg_option_t;
  3359. +struct ipkg_option {
  3360. + const char *name;
  3361. + const ipkg_option_type_t type;
  3362. + const void *value;
  3363. +};
  3364. +
  3365. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
  3366. +void ipkg_conf_deinit(ipkg_conf_t *conf);
  3367. +
  3368. +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
  3369. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
  3370. +
  3371. +#endif
  3372. --- /dev/null
  3373. +++ busybox-1.18.1/archival/libipkg/ipkg_configure.c
  3374. @@ -0,0 +1,40 @@
  3375. +/* ipkg_configure.c - the itsy package management system
  3376. +
  3377. + Carl D. Worth
  3378. +
  3379. + Copyright (C) 2001 University of Southern California
  3380. +
  3381. + This program is free software; you can redistribute it and/or
  3382. + modify it under the terms of the GNU General Public License as
  3383. + published by the Free Software Foundation; either version 2, or (at
  3384. + your option) any later version.
  3385. +
  3386. + This program is distributed in the hope that it will be useful, but
  3387. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3388. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3389. + General Public License for more details.
  3390. +*/
  3391. +
  3392. +#include "ipkg.h"
  3393. +
  3394. +#include "ipkg_configure.h"
  3395. +
  3396. +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
  3397. +{
  3398. + int err;
  3399. +
  3400. + /* DPKG_INCOMPATIBILITY:
  3401. + dpkg actually does some conffile handling here, rather than at the
  3402. + end of ipkg_install(). Do we care? */
  3403. + /* DPKG_INCOMPATIBILITY:
  3404. + dpkg actually includes a version number to this script call */
  3405. + err = pkg_run_script(conf, pkg, "postinst", "configure");
  3406. + if (err) {
  3407. + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
  3408. + return err;
  3409. + }
  3410. +
  3411. + ipkg_state_changed++;
  3412. + return 0;
  3413. +}
  3414. +
  3415. --- /dev/null
  3416. +++ busybox-1.18.1/archival/libipkg/ipkg_configure.h
  3417. @@ -0,0 +1,25 @@
  3418. +/* ipkg_configure.h - the itsy package management system
  3419. +
  3420. + Carl D. Worth
  3421. +
  3422. + Copyright (C) 2001 University of Southern California
  3423. +
  3424. + This program is free software; you can redistribute it and/or
  3425. + modify it under the terms of the GNU General Public License as
  3426. + published by the Free Software Foundation; either version 2, or (at
  3427. + your option) any later version.
  3428. +
  3429. + This program is distributed in the hope that it will be useful, but
  3430. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3431. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3432. + General Public License for more details.
  3433. +*/
  3434. +
  3435. +#ifndef IPKG_CONFIGURE_H
  3436. +#define IPKG_CONFIGURE_H
  3437. +
  3438. +#include "ipkg_conf.h"
  3439. +
  3440. +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
  3441. +
  3442. +#endif
  3443. --- /dev/null
  3444. +++ busybox-1.18.1/archival/libipkg/ipkg_download.c
  3445. @@ -0,0 +1,195 @@
  3446. +/* ipkg_download.c - the itsy package management system
  3447. +
  3448. + Carl D. Worth
  3449. +
  3450. + Copyright (C) 2001 University of Southern California
  3451. +
  3452. + This program is free software; you can redistribute it and/or
  3453. + modify it under the terms of the GNU General Public License as
  3454. + published by the Free Software Foundation; either version 2, or (at
  3455. + your option) any later version.
  3456. +
  3457. + This program is distributed in the hope that it will be useful, but
  3458. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3459. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3460. + General Public License for more details.
  3461. +*/
  3462. +
  3463. +#include "ipkg.h"
  3464. +#include "ipkg_download.h"
  3465. +#include "ipkg_message.h"
  3466. +
  3467. +#include "sprintf_alloc.h"
  3468. +#include "xsystem.h"
  3469. +#include "file_util.h"
  3470. +#include "str_util.h"
  3471. +
  3472. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
  3473. +{
  3474. + int err = 0;
  3475. +
  3476. + char *src_basec = strdup(src);
  3477. + char *src_base = basename(src_basec);
  3478. + char *tmp_file_location;
  3479. + char *cmd;
  3480. +
  3481. + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
  3482. +
  3483. + fflush(stdout);
  3484. +
  3485. + if (str_starts_with(src, "file:")) {
  3486. + int ret;
  3487. + const char *file_src = src + 5;
  3488. + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
  3489. + ret = file_copy(src + 5, dest_file_name);
  3490. + ipkg_message(conf,IPKG_INFO,"Done.\n");
  3491. + return ret;
  3492. + }
  3493. +
  3494. + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
  3495. + err = unlink(tmp_file_location);
  3496. + if (err && errno != ENOENT) {
  3497. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
  3498. + __FUNCTION__, tmp_file_location, strerror(errno));
  3499. + free(tmp_file_location);
  3500. + return errno;
  3501. + }
  3502. +
  3503. + if (conf->http_proxy) {
  3504. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
  3505. + setenv("http_proxy", conf->http_proxy, 1);
  3506. + }
  3507. + if (conf->ftp_proxy) {
  3508. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
  3509. + setenv("ftp_proxy", conf->ftp_proxy, 1);
  3510. + }
  3511. + if (conf->no_proxy) {
  3512. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
  3513. + setenv("no_proxy", conf->no_proxy, 1);
  3514. + }
  3515. +
  3516. + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
  3517. + sprintf_alloc(&cmd, "wget %s %s%s %s%s %s -P %s %s",
  3518. + (conf->http_proxy || conf->ftp_proxy) ? "-Y on" : "",
  3519. + conf->proxy_user ? "--proxy-user=" : "",
  3520. + conf->proxy_user ? conf->proxy_user : "",
  3521. + conf->proxy_passwd ? "--proxy-passwd=" : "",
  3522. + conf->proxy_passwd ? conf->proxy_passwd : "",
  3523. + conf->verbose_wget ? "" : "-q",
  3524. + conf->tmp_dir,
  3525. + src);
  3526. + err = xsystem(cmd);
  3527. + if (err) {
  3528. + if (err != -1) {
  3529. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
  3530. + __FUNCTION__, err, cmd);
  3531. + }
  3532. + unlink(tmp_file_location);
  3533. + free(tmp_file_location);
  3534. + free(src_basec);
  3535. + free(cmd);
  3536. + return EINVAL;
  3537. + }
  3538. + free(cmd);
  3539. +
  3540. + err = file_move(tmp_file_location, dest_file_name);
  3541. +
  3542. + free(tmp_file_location);
  3543. + free(src_basec);
  3544. +
  3545. + if (err) {
  3546. + return err;
  3547. + }
  3548. +
  3549. + return 0;
  3550. +}
  3551. +
  3552. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
  3553. +{
  3554. + int err;
  3555. + char *url;
  3556. +
  3557. + if (pkg->src == NULL) {
  3558. + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
  3559. + pkg->name, pkg->parent->name);
  3560. + return -1;
  3561. + }
  3562. +
  3563. + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
  3564. +
  3565. + /* XXX: BUG: The pkg->filename might be something like
  3566. + "../../foo.ipk". While this is correct, and exactly what we
  3567. + want to use to construct url above, here we actually need to
  3568. + use just the filename part, without any directory. */
  3569. + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
  3570. +
  3571. + err = ipkg_download(conf, url, pkg->local_filename);
  3572. + free(url);
  3573. +
  3574. + return err;
  3575. +}
  3576. +
  3577. +/*
  3578. + * Downloads file from url, installs in package database, return package name.
  3579. + */
  3580. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
  3581. +{
  3582. + int err = 0;
  3583. + pkg_t *pkg;
  3584. + pkg = pkg_new();
  3585. + if (pkg == NULL)
  3586. + return ENOMEM;
  3587. +
  3588. + if (str_starts_with(url, "http://")
  3589. + || str_starts_with(url, "ftp://")) {
  3590. + char *tmp_file;
  3591. + char *file_basec = strdup(url);
  3592. + char *file_base = basename(file_basec);
  3593. +
  3594. + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
  3595. + err = ipkg_download(conf, url, tmp_file);
  3596. + if (err)
  3597. + return err;
  3598. +
  3599. + err = pkg_init_from_file(pkg, tmp_file);
  3600. + if (err)
  3601. + return err;
  3602. + pkg->local_filename = strdup(tmp_file);
  3603. +
  3604. + free(tmp_file);
  3605. + free(file_basec);
  3606. +
  3607. + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
  3608. + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
  3609. +
  3610. + err = pkg_init_from_file(pkg, url);
  3611. + if (err)
  3612. + return err;
  3613. + pkg->local_filename = strdup(url);
  3614. + ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand (%s).\n", pkg->name,pkg->local_filename);
  3615. + pkg->provided_by_hand = 1;
  3616. +
  3617. + } else {
  3618. + pkg_deinit(pkg);
  3619. + free(pkg);
  3620. + return 0;
  3621. + }
  3622. +
  3623. + if (!pkg->architecture) {
  3624. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3625. + return -EINVAL;
  3626. + }
  3627. +
  3628. + pkg->dest = conf->default_dest;
  3629. + pkg->state_want = SW_INSTALL;
  3630. + pkg->state_flag |= SF_PREFER;
  3631. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3632. + if ( pkg == NULL ){
  3633. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  3634. + return 0;
  3635. + }
  3636. + if (namep) {
  3637. + *namep = strdup(pkg->name);
  3638. + }
  3639. + return 0;
  3640. +}
  3641. --- /dev/null
  3642. +++ busybox-1.18.1/archival/libipkg/ipkg_download.h
  3643. @@ -0,0 +1,30 @@
  3644. +/* ipkg_download.h - the itsy package management system
  3645. +
  3646. + Carl D. Worth
  3647. +
  3648. + Copyright (C) 2001 University of Southern California
  3649. +
  3650. + This program is free software; you can redistribute it and/or
  3651. + modify it under the terms of the GNU General Public License as
  3652. + published by the Free Software Foundation; either version 2, or (at
  3653. + your option) any later version.
  3654. +
  3655. + This program is distributed in the hope that it will be useful, but
  3656. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3657. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3658. + General Public License for more details.
  3659. +*/
  3660. +
  3661. +#ifndef IPKG_DOWNLOAD_H
  3662. +#define IPKG_DOWNLOAD_H
  3663. +
  3664. +#include "ipkg_conf.h"
  3665. +
  3666. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
  3667. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
  3668. +/*
  3669. + * Downloads file from url, installs in package database, return package name.
  3670. + */
  3671. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
  3672. +
  3673. +#endif
  3674. --- /dev/null
  3675. +++ busybox-1.18.1/archival/libipkg/ipkg_includes.h
  3676. @@ -0,0 +1,82 @@
  3677. +#ifndef IPKG_INCLUDES_H
  3678. +#define IPKG_INCLUDES_H
  3679. +
  3680. +/* Define to 1 if you have the <memory.h> header file. */
  3681. +#define HAVE_MEMORY_H 1
  3682. +
  3683. +/* Define to 1 if you have the <regex.h> header file. */
  3684. +#define HAVE_REGEX_H 1
  3685. +
  3686. +/* Define to 1 if you have the <stdlib.h> header file. */
  3687. +#define HAVE_STDLIB_H 1
  3688. +
  3689. +/* Define to 1 if you have the <strings.h> header file. */
  3690. +#define HAVE_STRINGS_H 1
  3691. +
  3692. +/* Define to 1 if you have the <string.h> header file. */
  3693. +#define HAVE_STRING_H 1
  3694. +
  3695. +/* Define to 1 if you have the <sys/stat.h> header file. */
  3696. +#define HAVE_SYS_STAT_H 1
  3697. +
  3698. +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
  3699. +#define HAVE_SYS_WAIT_H 1
  3700. +
  3701. +/* Define to 1 if you have the <unistd.h> header file. */
  3702. +#define HAVE_UNISTD_H 1
  3703. +
  3704. +/* Define to 1 if you have the ANSI C header files. */
  3705. +#define STDC_HEADERS 1
  3706. +
  3707. +
  3708. +#include <stdio.h>
  3709. +
  3710. +#if STDC_HEADERS
  3711. +# include <stdlib.h>
  3712. +# include <stdarg.h>
  3713. +# include <stddef.h>
  3714. +# include <ctype.h>
  3715. +# include <errno.h>
  3716. +#else
  3717. +# if HAVE_STDLIB_H
  3718. +# include <stdlib.h>
  3719. +# endif
  3720. +#endif
  3721. +
  3722. +#if HAVE_REGEX_H
  3723. +# include <regex.h>
  3724. +#endif
  3725. +
  3726. +#if HAVE_STRING_H
  3727. +# if !STDC_HEADERS && HAVE_MEMORY_H
  3728. +# include <memory.h>
  3729. +# endif
  3730. +/* XXX: What's the right way to pick up GNU's strndup declaration? */
  3731. +# if __GNUC__
  3732. +# define __USE_GNU 1
  3733. +# endif
  3734. +# include <string.h>
  3735. +# undef __USE_GNU
  3736. +#endif
  3737. +
  3738. +#if HAVE_STRINGS_H
  3739. +# include <strings.h>
  3740. +#endif
  3741. +
  3742. +#if HAVE_SYS_STAT_H
  3743. +# include <sys/stat.h>
  3744. +#endif
  3745. +
  3746. +#if HAVE_SYS_WAIT_H
  3747. +# include <sys/wait.h>
  3748. +#endif
  3749. +
  3750. +#if HAVE_UNISTD_H
  3751. +# include <sys/types.h>
  3752. +# include <unistd.h>
  3753. +#endif
  3754. +
  3755. +#include <sys/mount.h>
  3756. +#include <mntent.h>
  3757. +
  3758. +#endif /* IPKG_INCLUDES_H */
  3759. --- /dev/null
  3760. +++ busybox-1.18.1/archival/libipkg/ipkg_install.c
  3761. @@ -0,0 +1,1982 @@
  3762. +/* ipkg_install.c - the itsy package management system
  3763. +
  3764. + Carl D. Worth
  3765. +
  3766. + Copyright (C) 2001 University of Southern California
  3767. +
  3768. + This program is free software; you can redistribute it and/or
  3769. + modify it under the terms of the GNU General Public License as
  3770. + published by the Free Software Foundation; either version 2, or (at
  3771. + your option) any later version.
  3772. +
  3773. + This program is distributed in the hope that it will be useful, but
  3774. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3775. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3776. + General Public License for more details.
  3777. +*/
  3778. +
  3779. +#include "ipkg.h"
  3780. +#include <errno.h>
  3781. +#include <dirent.h>
  3782. +#include <glob.h>
  3783. +#include <time.h>
  3784. +#include <signal.h>
  3785. +typedef void (*sighandler_t)(int);
  3786. +
  3787. +#include "pkg.h"
  3788. +#include "pkg_hash.h"
  3789. +#include "pkg_extract.h"
  3790. +
  3791. +#include "ipkg_install.h"
  3792. +#include "ipkg_configure.h"
  3793. +#include "ipkg_download.h"
  3794. +#include "ipkg_remove.h"
  3795. +
  3796. +#include "ipkg_utils.h"
  3797. +#include "ipkg_message.h"
  3798. +
  3799. +#include "sprintf_alloc.h"
  3800. +#include "file_util.h"
  3801. +#include "str_util.h"
  3802. +#include "xsystem.h"
  3803. +#include "user.h"
  3804. +
  3805. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  3806. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
  3807. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
  3808. +
  3809. +/*
  3810. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3811. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3812. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3813. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3814. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3815. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3816. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3817. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
  3818. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3819. +*/
  3820. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3821. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3822. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg);
  3823. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3824. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg);
  3825. +
  3826. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3827. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3828. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
  3829. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
  3830. +
  3831. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
  3832. +
  3833. +static int user_prefers_old_conffile(const char *file, const char *backup);
  3834. +
  3835. +static char *backup_filename_alloc(const char *file_name);
  3836. +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
  3837. +static int backup_exists_for(const char *file_name);
  3838. +static int backup_remove(const char *file_name);
  3839. +
  3840. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees);
  3841. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3842. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3843. +
  3844. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
  3845. +{
  3846. + int err, cmp;
  3847. + pkg_t *pkg, *old;
  3848. + char *old_version, *new_version;
  3849. +
  3850. + pkg = pkg_new();
  3851. + if (pkg == NULL) {
  3852. + return ENOMEM;
  3853. + }
  3854. +
  3855. + err = pkg_init_from_file(pkg, filename);
  3856. + if (err) {
  3857. + return err;
  3858. + }
  3859. +
  3860. + if (!pkg->architecture) {
  3861. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3862. + return -EINVAL;
  3863. + }
  3864. +
  3865. + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
  3866. + freeing the pkg that we pass in. It might be nice to clean this up
  3867. + if possible. */
  3868. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3869. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  3870. +
  3871. + pkg->local_filename = strdup(filename);
  3872. +
  3873. + if (old) {
  3874. + old_version = pkg_version_str_alloc(old);
  3875. + new_version = pkg_version_str_alloc(pkg);
  3876. +
  3877. + cmp = pkg_compare_versions(old, pkg);
  3878. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3879. + cmp = -1 ; /* then we force ipkg to downgrade */
  3880. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3881. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3882. + }
  3883. + if (cmp > 0) {
  3884. + ipkg_message(conf, IPKG_NOTICE,
  3885. + "Not downgrading package %s on %s from %s to %s.\n",
  3886. + old->name, old->dest->name, old_version, new_version);
  3887. + pkg->state_want = SW_DEINSTALL;
  3888. + pkg->state_flag |= SF_OBSOLETE;
  3889. + free(old_version);
  3890. + free(new_version);
  3891. + return 0;
  3892. + } else {
  3893. + free(old_version);
  3894. + free(new_version);
  3895. + }
  3896. + }
  3897. +
  3898. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3899. + return ipkg_install_pkg(conf, pkg,0);
  3900. +}
  3901. +
  3902. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3903. +{
  3904. + int cmp;
  3905. + pkg_t *old, *new;
  3906. + char *old_version, *new_version;
  3907. +
  3908. + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
  3909. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  3910. + if ( old )
  3911. + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
  3912. +
  3913. + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
  3914. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  3915. + if ( new )
  3916. + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
  3917. +
  3918. +/* Pigi Basically here is broken the version stuff.
  3919. + What's happening is that nothing provide the version to differents
  3920. + functions, so the returned struct is always the latest.
  3921. + That's why the install by name don't work.
  3922. +*/
  3923. + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
  3924. +
  3925. + if ( old )
  3926. + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
  3927. + if ( new )
  3928. + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
  3929. + ipkg_message(conf, IPKG_DEBUG2, " \n");
  3930. +
  3931. + if (new == NULL) {
  3932. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3933. + }
  3934. +
  3935. + new->state_flag |= SF_USER;
  3936. + if (old) {
  3937. + old_version = pkg_version_str_alloc(old);
  3938. + new_version = pkg_version_str_alloc(new);
  3939. +
  3940. + cmp = pkg_compare_versions(old, new);
  3941. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3942. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
  3943. + cmp = -1 ; /* then we force ipkg to downgrade */
  3944. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3945. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3946. + }
  3947. + ipkg_message(conf, IPKG_DEBUG,
  3948. + "Comparing visible versions of pkg %s:"
  3949. + "\n\t%s is installed "
  3950. + "\n\t%s is available "
  3951. + "\n\t%d was comparison result\n",
  3952. + pkg_name, old_version, new_version, cmp);
  3953. + if (cmp == 0 && !conf->force_reinstall) {
  3954. + ipkg_message(conf, IPKG_NOTICE,
  3955. + "Package %s (%s) installed in %s is up to date.\n",
  3956. + old->name, old_version, old->dest->name);
  3957. + free(old_version);
  3958. + free(new_version);
  3959. + return 0;
  3960. + } else if (cmp > 0) {
  3961. + ipkg_message(conf, IPKG_NOTICE,
  3962. + "Not downgrading package %s on %s from %s to %s.\n",
  3963. + old->name, old->dest->name, old_version, new_version);
  3964. + free(old_version);
  3965. + free(new_version);
  3966. + return 0;
  3967. + } else if (cmp < 0) {
  3968. + new->dest = old->dest;
  3969. + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
  3970. + }
  3971. + }
  3972. +
  3973. + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
  3974. + supposed to be an ipkg_error_t, but ipkg_install_pkg could
  3975. + return any kind of integer, (might be errno from a syscall,
  3976. + etc.). This is a real mess and will need to be cleaned up if
  3977. + anyone ever wants to make a nice libipkg. */
  3978. +
  3979. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3980. + return ipkg_install_pkg(conf, new,0);
  3981. +}
  3982. +
  3983. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3984. +{
  3985. + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
  3986. + int i;
  3987. + ipkg_error_t err;
  3988. + abstract_pkg_t *ppkg ;
  3989. +
  3990. + if (providers == NULL)
  3991. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3992. +
  3993. + for (i = 0; i < providers->len; i++) {
  3994. + ppkg = abstract_pkg_vec_get(providers, i);
  3995. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
  3996. + err = ipkg_install_by_name(conf, ppkg->name);
  3997. + if (err)
  3998. + return err;
  3999. +/* XXX Maybe ppkg should be freed ? */
  4000. + }
  4001. + return 0;
  4002. +}
  4003. +
  4004. +/*
  4005. + * Walk dependence graph starting with pkg, collect packages to be
  4006. + * installed into pkgs_needed, in dependence order.
  4007. + */
  4008. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
  4009. +{
  4010. + int i, err;
  4011. + pkg_vec_t *depends = pkg_vec_alloc();
  4012. + char **unresolved = NULL;
  4013. + int ndepends;
  4014. +
  4015. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  4016. + pkg, depends,
  4017. + &unresolved);
  4018. +
  4019. + if (unresolved) {
  4020. + ipkg_message(conf, IPKG_ERROR,
  4021. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  4022. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  4023. + while (*unresolved) {
  4024. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  4025. + unresolved++;
  4026. + }
  4027. + ipkg_message(conf, IPKG_ERROR, "\n");
  4028. + if (! conf->force_depends) {
  4029. + ipkg_message(conf, IPKG_INFO,
  4030. + "This could mean that your package list is out of date or that the packages\n"
  4031. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4032. + "of this problem try again with the '-force-depends' option.\n");
  4033. + pkg_vec_free(depends);
  4034. + return IPKG_PKG_DEPS_UNSATISFIED;
  4035. + }
  4036. + }
  4037. +
  4038. + if (ndepends <= 0) {
  4039. + pkg_vec_free(depends);
  4040. + return 0;
  4041. + }
  4042. +
  4043. + for (i = 0; i < depends->len; i++) {
  4044. + pkg_t *dep = depends->pkgs[i];
  4045. + /* The package was uninstalled when we started, but another
  4046. + dep earlier in this loop may have depended on it and pulled
  4047. + it in, so check first. */
  4048. + if ((dep->state_status != SS_INSTALLED)
  4049. + && (dep->state_status != SS_UNPACKED)
  4050. + && (dep->state_want != SW_INSTALL)) {
  4051. +
  4052. + /* Mark packages as to-be-installed */
  4053. + dep->state_want = SW_INSTALL;
  4054. +
  4055. + /* Dependencies should be installed the same place as pkg */
  4056. + if (dep->dest == NULL) {
  4057. + dep->dest = pkg->dest;
  4058. + }
  4059. +
  4060. + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
  4061. + if (err) {
  4062. + pkg_vec_free(depends);
  4063. + return err;
  4064. + }
  4065. + }
  4066. + }
  4067. + if (pkgs_needed)
  4068. + pkg_vec_insert(pkgs_needed, pkg);
  4069. +
  4070. + pkg_vec_free(depends);
  4071. +
  4072. + return 0;
  4073. +}
  4074. +
  4075. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
  4076. +{
  4077. + int cmp;
  4078. + pkg_t *old, *new;
  4079. + char *old_version, *new_version;
  4080. +
  4081. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  4082. +
  4083. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  4084. + if (new == NULL) {
  4085. + return IPKG_PKG_HAS_NO_CANDIDATE;
  4086. + }
  4087. + if (old) {
  4088. + old_version = pkg_version_str_alloc(old);
  4089. + new_version = pkg_version_str_alloc(new);
  4090. +
  4091. + cmp = pkg_compare_versions(old, new);
  4092. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4093. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
  4094. + cmp = -1 ; /* then we force ipkg to downgrade */
  4095. + /* We need to use a value < 0 because in the 0 case we are asking to */
  4096. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4097. + }
  4098. + ipkg_message(conf, IPKG_DEBUG,
  4099. + "comparing visible versions of pkg %s:"
  4100. + "\n\t%s is installed "
  4101. + "\n\t%s is available "
  4102. + "\n\t%d was comparison result\n",
  4103. + pkg_name, old_version, new_version, cmp);
  4104. + if (cmp == 0 && !conf->force_reinstall) {
  4105. + ipkg_message(conf, IPKG_NOTICE,
  4106. + "Package %s (%s) installed in %s is up to date.\n",
  4107. + old->name, old_version, old->dest->name);
  4108. + free(old_version);
  4109. + free(new_version);
  4110. + return 0;
  4111. + } else if (cmp > 0) {
  4112. + ipkg_message(conf, IPKG_NOTICE,
  4113. + "Not downgrading package %s on %s from %s to %s.\n",
  4114. + old->name, old->dest->name, old_version, new_version);
  4115. + free(old_version);
  4116. + free(new_version);
  4117. + return 0;
  4118. + } else if (cmp < 0) {
  4119. + new->dest = old->dest;
  4120. + old->state_want = SW_DEINSTALL;
  4121. + old->state_flag |= SF_OBSOLETE;
  4122. + }
  4123. + }
  4124. + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
  4125. +}
  4126. +
  4127. +
  4128. +
  4129. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
  4130. +{
  4131. + int i, err;
  4132. + pkg_vec_t *depends = pkg_vec_alloc();
  4133. + pkg_t *dep;
  4134. + char **unresolved = NULL;
  4135. + int ndepends;
  4136. +
  4137. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  4138. + pkg, depends,
  4139. + &unresolved);
  4140. +
  4141. + if (unresolved) {
  4142. + ipkg_message(conf, IPKG_ERROR,
  4143. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  4144. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  4145. + while (*unresolved) {
  4146. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  4147. + unresolved++;
  4148. + }
  4149. + ipkg_message(conf, IPKG_ERROR, "\n");
  4150. + if (! conf->force_depends) {
  4151. + ipkg_message(conf, IPKG_INFO,
  4152. + "This could mean that your package list is out of date or that the packages\n"
  4153. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4154. + "of this problem try again with the '-force-depends' option.\n");
  4155. + pkg_vec_free(depends);
  4156. + return IPKG_PKG_DEPS_UNSATISFIED;
  4157. + }
  4158. + }
  4159. +
  4160. + if (ndepends <= 0) {
  4161. + return 0;
  4162. + }
  4163. +
  4164. + /* Mark packages as to-be-installed */
  4165. + for (i=0; i < depends->len; i++) {
  4166. + /* Dependencies should be installed the same place as pkg */
  4167. + if (depends->pkgs[i]->dest == NULL) {
  4168. + depends->pkgs[i]->dest = pkg->dest;
  4169. + }
  4170. + depends->pkgs[i]->state_want = SW_INSTALL;
  4171. + }
  4172. +
  4173. + for (i = 0; i < depends->len; i++) {
  4174. + dep = depends->pkgs[i];
  4175. + /* The package was uninstalled when we started, but another
  4176. + dep earlier in this loop may have depended on it and pulled
  4177. + it in, so check first. */
  4178. + if ((dep->state_status != SS_INSTALLED)
  4179. + && (dep->state_status != SS_UNPACKED)) {
  4180. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4181. + err = ipkg_install_pkg(conf, dep,0);
  4182. + if (err) {
  4183. + pkg_vec_free(depends);
  4184. + return err;
  4185. + }
  4186. + }
  4187. + }
  4188. +
  4189. + pkg_vec_free(depends);
  4190. +
  4191. + return 0;
  4192. +}
  4193. +
  4194. +
  4195. +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
  4196. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
  4197. +{
  4198. + if (conf->nodeps == 0) {
  4199. + int i;
  4200. + pkg_vec_t *installed = pkg_vec_alloc();
  4201. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  4202. + for (i = 0; i < installed->len; i++) {
  4203. + pkg_t *pkg = installed->pkgs[i];
  4204. + satisfy_dependencies_for(conf, pkg);
  4205. + }
  4206. + pkg_vec_free(installed);
  4207. + }
  4208. + return 0;
  4209. +}
  4210. +
  4211. +
  4212. +
  4213. +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
  4214. +{
  4215. + int i;
  4216. + pkg_vec_t *conflicts = NULL;
  4217. + int level;
  4218. + const char *prefix;
  4219. + if (conf->force_depends) {
  4220. + level = IPKG_NOTICE;
  4221. + prefix = "Warning";
  4222. + } else {
  4223. + level = IPKG_ERROR;
  4224. + prefix = "ERROR";
  4225. + }
  4226. +
  4227. + if (!conf->force_depends)
  4228. + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(pkg);
  4229. +
  4230. + if (conflicts) {
  4231. + ipkg_message(conf, level,
  4232. + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
  4233. + i = 0;
  4234. + while (i < conflicts->len)
  4235. + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
  4236. + ipkg_message(conf, level, "\n");
  4237. + pkg_vec_free(conflicts);
  4238. + return IPKG_PKG_DEPS_UNSATISFIED;
  4239. + }
  4240. + return 0;
  4241. +}
  4242. +
  4243. +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
  4244. +{
  4245. + str_list_t *new_list = pkg_get_installed_files(new_pkg);
  4246. + str_list_elt_t *iter;
  4247. +
  4248. + for (iter = new_list->head; iter; iter = iter->next) {
  4249. + char *new_file = iter->data;
  4250. + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
  4251. + if (!new_file)
  4252. + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
  4253. + if (!owner || (owner == old_pkg))
  4254. + file_hash_set_file_owner(conf, new_file, new_pkg);
  4255. + }
  4256. + if (old_pkg) {
  4257. + str_list_t *old_list = pkg_get_installed_files(old_pkg);
  4258. + for (iter = old_list->head; iter; iter = iter->next) {
  4259. + char *old_file = iter->data;
  4260. + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
  4261. + if (owner == old_pkg) {
  4262. + /* obsolete */
  4263. + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
  4264. + }
  4265. + }
  4266. + }
  4267. + return 0;
  4268. +}
  4269. +
  4270. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
  4271. +{
  4272. + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
  4273. +
  4274. + /* sma 6.20.02: yup; here's the first bit */
  4275. + /*
  4276. + * XXX: BUG easy for cworth
  4277. + * 1) please point the call below to the correct current root destination
  4278. + * 2) we need to resolve how to check the required space for a pending pkg,
  4279. + * my diddling with the .ipk file size below isn't going to cut it.
  4280. + * 3) return a proper error code instead of 1
  4281. + */
  4282. + int comp_size, blocks_available;
  4283. +
  4284. + if (!conf->force_space && pkg->installed_size != NULL) {
  4285. + blocks_available = get_available_blocks(conf->default_dest->root_dir);
  4286. +
  4287. + comp_size = strtoul(pkg->installed_size, NULL, 0);
  4288. + /* round up a blocks count without doing fancy-but-slow casting jazz */
  4289. + comp_size = (int)((comp_size + 1023) / 1024);
  4290. +
  4291. + if (comp_size >= blocks_available) {
  4292. + ipkg_message(conf, IPKG_ERROR,
  4293. + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
  4294. + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
  4295. + return ENOSPC;
  4296. + }
  4297. + }
  4298. + return 0;
  4299. +}
  4300. +
  4301. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
  4302. +{
  4303. + int err;
  4304. + char *conffiles_file_name;
  4305. + char *root_dir;
  4306. + FILE *conffiles_file;
  4307. +
  4308. + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
  4309. +
  4310. + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
  4311. + if (pkg->tmp_unpack_dir == NULL) {
  4312. + ipkg_message(conf, IPKG_ERROR,
  4313. + "%s: Failed to create temporary directory '%s': %s\n",
  4314. + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
  4315. + return errno;
  4316. + }
  4317. +
  4318. + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
  4319. + if (err) {
  4320. + return err;
  4321. + }
  4322. +
  4323. + /* XXX: CLEANUP: There might be a cleaner place to read in the
  4324. + conffiles. Seems like I should be able to get everything to go
  4325. + through pkg_init_from_file. If so, maybe it would make sense to
  4326. + move all of unpack_pkg_control_files to that function. */
  4327. +
  4328. + /* Don't need to re-read conffiles if we already have it */
  4329. + if (pkg->conffiles.head) {
  4330. + return 0;
  4331. + }
  4332. +
  4333. + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
  4334. + if (! file_exists(conffiles_file_name)) {
  4335. + free(conffiles_file_name);
  4336. + return 0;
  4337. + }
  4338. +
  4339. + conffiles_file = fopen(conffiles_file_name, "r");
  4340. + if (conffiles_file == NULL) {
  4341. + fprintf(stderr, "%s: failed to open %s: %s\n",
  4342. + __FUNCTION__, conffiles_file_name, strerror(errno));
  4343. + free(conffiles_file_name);
  4344. + return errno;
  4345. + }
  4346. + free(conffiles_file_name);
  4347. +
  4348. + while (1) {
  4349. + char *cf_name;
  4350. + char *cf_name_in_dest;
  4351. +
  4352. + cf_name = file_read_line_alloc(conffiles_file);
  4353. + if (cf_name == NULL) {
  4354. + break;
  4355. + }
  4356. + str_chomp(cf_name);
  4357. + if (cf_name[0] == '\0') {
  4358. + continue;
  4359. + }
  4360. +
  4361. + /* Prepend dest->root_dir to conffile name.
  4362. + Take pains to avoid multiple slashes. */
  4363. + root_dir = pkg->dest->root_dir;
  4364. + if (conf->offline_root)
  4365. + /* skip the offline_root prefix */
  4366. + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
  4367. + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
  4368. + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
  4369. +
  4370. + /* Can't get an md5sum now, (file isn't extracted yet).
  4371. + We'll wait until resolve_conffiles */
  4372. + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
  4373. +
  4374. + free(cf_name);
  4375. + free(cf_name_in_dest);
  4376. + }
  4377. +
  4378. + fclose(conffiles_file);
  4379. +
  4380. + return 0;
  4381. +}
  4382. +
  4383. +/* returns number of installed replacees */
  4384. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees)
  4385. +{
  4386. + abstract_pkg_t **replaces = pkg->replaces;
  4387. + int replaces_count = pkg->replaces_count;
  4388. + int i, j;
  4389. + for (i = 0; i < replaces_count; i++) {
  4390. + abstract_pkg_t *ab_pkg = replaces[i];
  4391. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  4392. + if (pkg_vec) {
  4393. + for (j = 0; j < pkg_vec->len; j++) {
  4394. + pkg_t *replacee = pkg_vec->pkgs[j];
  4395. + if (!pkg_conflicts(pkg, replacee))
  4396. + continue;
  4397. + if (replacee->state_status == SS_INSTALLED) {
  4398. + pkg_vec_insert(installed_replacees, replacee);
  4399. + }
  4400. + }
  4401. + }
  4402. + }
  4403. + return installed_replacees->len;
  4404. +}
  4405. +
  4406. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4407. +{
  4408. + int i;
  4409. + int replaces_count = replacees->len;
  4410. + for (i = 0; i < replaces_count; i++) {
  4411. + pkg_t *replacee = replacees->pkgs[i];
  4412. + int err;
  4413. + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
  4414. + err = ipkg_remove_pkg(conf, replacee,0);
  4415. + if (err)
  4416. + return err;
  4417. + }
  4418. + return 0;
  4419. +}
  4420. +
  4421. +/* to unwind the removal: make sure they are installed */
  4422. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4423. +{
  4424. + int i, err;
  4425. + int replaces_count = replacees->len;
  4426. + for (i = 0; i < replaces_count; i++) {
  4427. + pkg_t *replacee = replacees->pkgs[i];
  4428. + if (replacee->state_status != SS_INSTALLED) {
  4429. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4430. + err = ipkg_install_pkg(conf, replacee,0);
  4431. + if (err)
  4432. + return err;
  4433. + }
  4434. + }
  4435. + return 0;
  4436. +}
  4437. +
  4438. +int caught_sigint = 0;
  4439. +static void ipkg_install_pkg_sigint_handler(int sig)
  4440. +{
  4441. + caught_sigint = sig;
  4442. +}
  4443. +
  4444. +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
  4445. +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
  4446. +{
  4447. + if (old_pkg) {
  4448. + char message_out[15];
  4449. + char *old_version = pkg_version_str_alloc(old_pkg);
  4450. + char *new_version = pkg_version_str_alloc(pkg);
  4451. + int cmp = pkg_compare_versions(old_pkg, pkg);
  4452. + int rc = 0;
  4453. +
  4454. + memset(message_out,'\x0',15);
  4455. + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
  4456. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4457. + cmp = -1 ; /* then we force ipkg to downgrade */
  4458. + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
  4459. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4460. + }
  4461. +
  4462. + if (cmp > 0) {
  4463. + ipkg_message(conf, IPKG_NOTICE,
  4464. + "Not downgrading package %s on %s from %s to %s.\n",
  4465. + old_pkg->name, old_pkg->dest->name, old_version, new_version);
  4466. + rc = 1;
  4467. + } else if (cmp < 0) {
  4468. + ipkg_message(conf, IPKG_NOTICE,
  4469. + "%s%s on %s from %s to %s...\n",
  4470. + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
  4471. + pkg->dest = old_pkg->dest;
  4472. + rc = 0;
  4473. + } else /* cmp == 0 */ {
  4474. + if (conf->force_reinstall) {
  4475. + ipkg_message(conf, IPKG_NOTICE,
  4476. + "Reinstalling %s (%s) on %s...\n",
  4477. + pkg->name, new_version, old_pkg->dest->name);
  4478. + pkg->dest = old_pkg->dest;
  4479. + rc = 0;
  4480. + } else {
  4481. + ipkg_message(conf, IPKG_NOTICE,
  4482. + "Not installing %s (%s) on %s -- already installed.\n",
  4483. + pkg->name, new_version, old_pkg->dest->name);
  4484. + rc = 1;
  4485. + }
  4486. + }
  4487. + free(old_version);
  4488. + free(new_version);
  4489. + return rc;
  4490. + } else {
  4491. + char message_out[15], *version ;
  4492. + memset(message_out,'\x0',15);
  4493. + if ( message )
  4494. + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
  4495. + else
  4496. + strncpy( message_out,"Installing ",strlen("Installing ") );
  4497. + version = pkg_version_str_alloc(pkg);
  4498. +
  4499. + ipkg_message(conf, IPKG_NOTICE,
  4500. + "%s%s (%s) to %s...\n", message_out,
  4501. + pkg->name, version, pkg->dest->name);
  4502. + free(version);
  4503. + return 0;
  4504. + }
  4505. +}
  4506. +
  4507. +/* and now the meat... */
  4508. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
  4509. +{
  4510. + int err = 0;
  4511. + int message = 0;
  4512. + pkg_t *old_pkg = NULL;
  4513. + pkg_vec_t *replacees;
  4514. + abstract_pkg_t *ab_pkg = NULL;
  4515. + int old_state_flag;
  4516. + uint8_t *file_md5;
  4517. +
  4518. +
  4519. + if ( from_upgrade )
  4520. + message = 1; /* Coming from an upgrade, and should change the output message */
  4521. +
  4522. + if (!pkg) {
  4523. + ipkg_message(conf, IPKG_ERROR,
  4524. + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
  4525. + return -EINVAL;
  4526. + }
  4527. +
  4528. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
  4529. +
  4530. + if (!pkg_arch_supported(conf, pkg)) {
  4531. + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
  4532. + pkg->architecture, pkg->name);
  4533. + return -EINVAL;
  4534. + }
  4535. + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
  4536. + err = satisfy_dependencies_for(conf, pkg);
  4537. + if (err) { return err; }
  4538. +
  4539. + ipkg_message(conf, IPKG_NOTICE,
  4540. + "Package %s is already installed in %s.\n",
  4541. + pkg->name, pkg->dest->name);
  4542. + return 0;
  4543. + }
  4544. +
  4545. + if (pkg->dest == NULL) {
  4546. + pkg->dest = conf->default_dest;
  4547. + }
  4548. +
  4549. + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  4550. +
  4551. + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
  4552. + if (err) { return err; }
  4553. +
  4554. + pkg->state_want = SW_INSTALL;
  4555. + if (old_pkg){
  4556. + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
  4557. + }
  4558. +
  4559. +
  4560. + /* Abhaya: conflicts check */
  4561. + err = check_conflicts_for(conf, pkg);
  4562. + if (err) { return err; }
  4563. +
  4564. + /* this setup is to remove the upgrade scenario in the end when
  4565. + installing pkg A, A deps B & B deps on A. So both B and A are
  4566. + installed. Then A's installation is started resulting in an
  4567. + uncecessary upgrade */
  4568. + if (pkg->state_status == SS_INSTALLED
  4569. + && conf->force_reinstall == 0) return 0;
  4570. +
  4571. + err = verify_pkg_installable(conf, pkg);
  4572. + if (err) { return err; }
  4573. +
  4574. + if (pkg->local_filename == NULL) {
  4575. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  4576. + if (err) {
  4577. + ipkg_message(conf, IPKG_ERROR,
  4578. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  4579. + pkg->name);
  4580. + return err;
  4581. + }
  4582. + }
  4583. +
  4584. +/* Check for md5 values */
  4585. + if (pkg->md5sum)
  4586. + {
  4587. + file_md5 = file_md5sum_alloc(pkg->local_filename);
  4588. + if (strcmp((char *)file_md5, pkg->md5sum))
  4589. + {
  4590. + ipkg_message(conf, IPKG_ERROR,
  4591. + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
  4592. + pkg->name);
  4593. + free(file_md5);
  4594. + return err;
  4595. + }
  4596. + free(file_md5);
  4597. + }
  4598. +
  4599. + if (pkg->tmp_unpack_dir == NULL) {
  4600. + unpack_pkg_control_files(conf, pkg);
  4601. + }
  4602. +
  4603. + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
  4604. +/* Pigi: check if it will pass from here when replacing. It seems to fail */
  4605. +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
  4606. + err = update_file_ownership(conf, pkg, old_pkg);
  4607. + if (err) { return err; }
  4608. +
  4609. + if (conf->nodeps == 0) {
  4610. + err = satisfy_dependencies_for(conf, pkg);
  4611. + if (err) { return err; }
  4612. + }
  4613. +
  4614. + replacees = pkg_vec_alloc();
  4615. + pkg_get_installed_replacees(pkg, replacees);
  4616. +
  4617. + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
  4618. + {
  4619. + sigset_t newset, oldset;
  4620. + sighandler_t old_handler = NULL;
  4621. + int use_signal = 0;
  4622. + caught_sigint = 0;
  4623. + if (use_signal) {
  4624. + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
  4625. + } else {
  4626. + sigemptyset(&newset);
  4627. + sigaddset(&newset, SIGINT);
  4628. + sigprocmask(SIG_BLOCK, &newset, &oldset);
  4629. + }
  4630. +
  4631. + ipkg_state_changed++;
  4632. + pkg->state_flag |= SF_FILELIST_CHANGED;
  4633. +
  4634. + /* XXX: BUG: we really should treat replacement more like an upgrade
  4635. + * Instead, we're going to remove the replacees
  4636. + */
  4637. + err = pkg_remove_installed_replacees(conf, replacees);
  4638. + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
  4639. +
  4640. + /*
  4641. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  4642. + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
  4643. +
  4644. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  4645. + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
  4646. + */
  4647. +
  4648. + err = preinst_configure(conf, pkg, old_pkg);
  4649. + /*
  4650. + if (err) goto UNWIND_PREINST_CONFIGURE;
  4651. + */
  4652. +
  4653. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  4654. + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
  4655. +
  4656. + err = check_data_file_clashes(conf, pkg, old_pkg);
  4657. + /*
  4658. + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
  4659. +
  4660. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  4661. + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
  4662. + */
  4663. +
  4664. + if (conf->noaction) return 0;
  4665. +
  4666. + /* point of no return: no unwinding after this */
  4667. + if (old_pkg && !conf->force_reinstall) {
  4668. + old_pkg->state_want = SW_DEINSTALL;
  4669. +
  4670. + if (old_pkg->state_flag & SF_NOPRUNE) {
  4671. + ipkg_message(conf, IPKG_INFO,
  4672. + " not removing obsolesced files because package marked noprune\n");
  4673. + } else {
  4674. + ipkg_message(conf, IPKG_INFO,
  4675. + " removing obsolesced files\n");
  4676. + remove_obsolesced_files(conf, pkg, old_pkg);
  4677. + }
  4678. + /* removing files from old package, to avoid ghost files */
  4679. + remove_data_files_and_list(conf, old_pkg);
  4680. +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
  4681. + remove_maintainer_scripts_except_postrm(conf, old_pkg);
  4682. + remove_postrm(conf, old_pkg);
  4683. +/* Pigi */
  4684. +
  4685. + }
  4686. +
  4687. +
  4688. + ipkg_message(conf, IPKG_INFO,
  4689. + " installing maintainer scripts\n");
  4690. + install_maintainer_scripts(conf, pkg, old_pkg);
  4691. +
  4692. + /* the following just returns 0
  4693. + remove_disappeared(conf, pkg);
  4694. + */
  4695. +
  4696. + ipkg_message(conf, IPKG_INFO,
  4697. + " installing data files\n");
  4698. + install_data_files(conf, pkg);
  4699. +
  4700. +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
  4701. + err = check_data_file_clashes_change(conf, pkg);
  4702. +
  4703. + ipkg_message(conf, IPKG_INFO,
  4704. + " resolving conf files\n");
  4705. + resolve_conffiles(conf, pkg);
  4706. +
  4707. + pkg->state_status = SS_UNPACKED;
  4708. + old_state_flag = pkg->state_flag;
  4709. + pkg->state_flag &= ~SF_PREFER;
  4710. + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
  4711. +
  4712. + if (old_pkg && !conf->force_reinstall) {
  4713. + old_pkg->state_status = SS_NOT_INSTALLED;
  4714. + }
  4715. +
  4716. + time(&pkg->installed_time);
  4717. +
  4718. + ipkg_message(conf, IPKG_INFO,
  4719. + " cleanup temp files\n");
  4720. + cleanup_temporary_files(conf, pkg);
  4721. +
  4722. + ab_pkg = pkg->parent;
  4723. + if (ab_pkg)
  4724. + ab_pkg->state_status = pkg->state_status;
  4725. +
  4726. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  4727. +
  4728. + if (use_signal)
  4729. + signal(SIGINT, old_handler);
  4730. + else
  4731. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4732. +
  4733. + return 0;
  4734. +
  4735. +
  4736. + /*
  4737. + UNWIND_POSTRM_UPGRADE_OLD_PKG:
  4738. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4739. + UNWIND_CHECK_DATA_FILE_CLASHES:
  4740. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  4741. + */
  4742. + UNWIND_BACKUP_MODIFIED_CONFFILES:
  4743. + backup_modified_conffiles_unwind(pkg, old_pkg);
  4744. + /*
  4745. + UNWIND_PREINST_CONFIGURE:
  4746. + preinst_configure_unwind(conf, pkg, old_pkg);
  4747. + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
  4748. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  4749. + UNWIND_PRERM_UPGRADE_OLD_PKG:
  4750. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4751. + */
  4752. + UNWIND_REMOVE_INSTALLED_REPLACEES:
  4753. + pkg_remove_installed_replacees_unwind(conf, replacees);
  4754. +
  4755. + ipkg_message(conf, IPKG_INFO,
  4756. + " cleanup temp files\n");
  4757. + cleanup_temporary_files(conf, pkg);
  4758. +
  4759. + ipkg_message(conf, IPKG_INFO,
  4760. + "Failed.\n");
  4761. + if (use_signal)
  4762. + signal(SIGINT, old_handler);
  4763. + else
  4764. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4765. +
  4766. + return err;
  4767. + }
  4768. +}
  4769. +
  4770. +/*
  4771. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4772. +{
  4773. + DPKG_INCOMPATIBILITY:
  4774. + dpkg does some things here that we don't do yet. Do we care?
  4775. +
  4776. + 1. If a version of the package is already installed, call
  4777. + old-prerm upgrade new-version
  4778. + 2. If the script runs but exits with a non-zero exit status
  4779. + new-prerm failed-upgrade old-version
  4780. + Error unwind, for both the above cases:
  4781. + old-postinst abort-upgrade new-version
  4782. + return 0;
  4783. +}
  4784. +*/
  4785. +
  4786. +/*
  4787. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4788. +{
  4789. + DPKG_INCOMPATIBILITY:
  4790. + dpkg does some things here that we don't do yet. Do we care?
  4791. + (See prerm_upgrade_old_package for details)
  4792. +
  4793. + return 0;
  4794. +}
  4795. +*/
  4796. +
  4797. +/*
  4798. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4799. +{
  4800. + DPKG_INCOMPATIBILITY:
  4801. + dpkg does some things here that we don't do yet. Do we care?
  4802. + 2. If a 'conflicting' package is being removed at the same time:
  4803. + 1. If any packages depended on that conflicting package and
  4804. + --auto-deconfigure is specified, call, for each such package:
  4805. + deconfigured's-prerm deconfigure \
  4806. + in-favour package-being-installed version \
  4807. + removing conflicting-package version
  4808. + Error unwind:
  4809. + deconfigured's-postinst abort-deconfigure \
  4810. + in-favour package-being-installed-but-failed version \
  4811. + removing conflicting-package version
  4812. +
  4813. + The deconfigured packages are marked as requiring
  4814. + configuration, so that if --install is used they will be
  4815. + configured again if possible.
  4816. + 2. To prepare for removal of the conflicting package, call:
  4817. + conflictor's-prerm remove in-favour package new-version
  4818. + Error unwind:
  4819. + conflictor's-postinst abort-remove in-favour package new-version
  4820. + return 0;
  4821. +}
  4822. +*/
  4823. +
  4824. +/*
  4825. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4826. +{
  4827. + DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
  4828. + do yet. Do we care? (See prerm_deconfigure_conflictors for
  4829. + details)
  4830. + return 0;
  4831. +}
  4832. +*/
  4833. +
  4834. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4835. +{
  4836. + int err;
  4837. + char *preinst_args;
  4838. +
  4839. + if (old_pkg) {
  4840. + char *old_version = pkg_version_str_alloc(old_pkg);
  4841. + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
  4842. + free(old_version);
  4843. + } else if (pkg->state_status == SS_CONFIG_FILES) {
  4844. + char *pkg_version = pkg_version_str_alloc(pkg);
  4845. + sprintf_alloc(&preinst_args, "install %s", pkg_version);
  4846. + free(pkg_version);
  4847. + } else {
  4848. + preinst_args = strdup("install");
  4849. + }
  4850. +
  4851. + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
  4852. + if (err) {
  4853. + ipkg_message(conf, IPKG_ERROR,
  4854. + "Aborting installation of %s\n", pkg->name);
  4855. + return 1;
  4856. + }
  4857. +
  4858. + free(preinst_args);
  4859. +
  4860. + return 0;
  4861. +}
  4862. +
  4863. +/*
  4864. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4865. +{
  4866. + DPKG_INCOMPATIBILITY:
  4867. + dpkg does the following error unwind, should we?
  4868. + pkg->postrm abort-upgrade old-version
  4869. + OR pkg->postrm abort-install old-version
  4870. + OR pkg->postrm abort-install
  4871. + return 0;
  4872. +}
  4873. +*/
  4874. +
  4875. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4876. +{
  4877. + int err;
  4878. + conffile_list_elt_t *iter;
  4879. + conffile_t *cf;
  4880. +
  4881. + if (conf->noaction) return 0;
  4882. +
  4883. + /* Backup all modified conffiles */
  4884. + if (old_pkg) {
  4885. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4886. + char *cf_name;
  4887. +
  4888. + cf = iter->data;
  4889. + cf_name = root_filename_alloc(conf, cf->name);
  4890. +
  4891. + /* Don't worry if the conffile is just plain gone */
  4892. + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
  4893. + err = backup_make_backup(conf, cf_name);
  4894. + if (err) {
  4895. + return err;
  4896. + }
  4897. + }
  4898. + free(cf_name);
  4899. + }
  4900. + }
  4901. +
  4902. + /* Backup all conffiles that were not conffiles in old_pkg */
  4903. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4904. + char *cf_name;
  4905. + cf = iter->data;
  4906. + cf_name = root_filename_alloc(conf, cf->name);
  4907. + /* Ignore if this was a conffile in old_pkg as well */
  4908. + if (pkg_get_conffile(old_pkg, cf->name)) {
  4909. + continue;
  4910. + }
  4911. +
  4912. + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
  4913. + err = backup_make_backup(conf, cf_name);
  4914. + if (err) {
  4915. + return err;
  4916. + }
  4917. + }
  4918. + free(cf_name);
  4919. + }
  4920. +
  4921. + return 0;
  4922. +}
  4923. +
  4924. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg)
  4925. +{
  4926. + conffile_list_elt_t *iter;
  4927. +
  4928. + if (old_pkg) {
  4929. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4930. + backup_remove(iter->data->name);
  4931. + }
  4932. + }
  4933. +
  4934. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4935. + backup_remove(iter->data->name);
  4936. + }
  4937. +
  4938. + return 0;
  4939. +}
  4940. +
  4941. +
  4942. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4943. +{
  4944. + /* DPKG_INCOMPATIBILITY:
  4945. + ipkg takes a slightly different approach than dpkg at this
  4946. + point. dpkg installs each file in the new package while
  4947. + creating a backup for any file that is replaced, (so that it
  4948. + can unwind if necessary). To avoid complexity and redundant
  4949. + storage, ipkg doesn't do any installation until later, (at the
  4950. + point at which dpkg removes the backups.
  4951. +
  4952. + But, we do have to check for data file clashes, since after
  4953. + installing a package with a file clash, removing either of the
  4954. + packages involved in the clash has the potential to break the
  4955. + other package.
  4956. + */
  4957. + str_list_t *files_list;
  4958. + str_list_elt_t *iter;
  4959. +
  4960. + int clashes = 0;
  4961. +
  4962. + files_list = pkg_get_installed_files(pkg);
  4963. + for (iter = files_list->head; iter; iter = iter->next) {
  4964. + char *root_filename;
  4965. + char *filename = iter->data;
  4966. + root_filename = root_filename_alloc(conf, filename);
  4967. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  4968. + pkg_t *owner;
  4969. + pkg_t *obs;
  4970. + /* Pre-existing conffiles are OK */
  4971. + /* @@@@ should have way to check that it is a conffile -Jamey */
  4972. + if (backup_exists_for(root_filename)) {
  4973. + continue;
  4974. + }
  4975. +
  4976. + /* Pre-existing files are OK if force-overwrite was asserted. */
  4977. + if (conf->force_overwrite) {
  4978. + /* but we need to change who owns this file */
  4979. + file_hash_set_file_owner(conf, filename, pkg);
  4980. + continue;
  4981. + }
  4982. +
  4983. + owner = file_hash_get_file_owner(conf, filename);
  4984. +
  4985. + /* Pre-existing files are OK if owned by the pkg being upgraded. */
  4986. + if (owner && old_pkg) {
  4987. + if (strcmp(owner->name, old_pkg->name) == 0) {
  4988. + continue;
  4989. + }
  4990. + }
  4991. +
  4992. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  4993. + if (owner) {
  4994. + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
  4995. + if (pkg_replaces(pkg, owner)) {
  4996. + continue;
  4997. + }
  4998. +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
  4999. + then it's ok to overwrite. */
  5000. + if (strcmp(owner->name,pkg->name)==0){
  5001. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  5002. + continue;
  5003. + }
  5004. + }
  5005. +
  5006. + /* Pre-existing files are OK if they are obsolete */
  5007. + obs = hash_table_get(&conf->obs_file_hash, filename);
  5008. + if (obs) {
  5009. + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
  5010. + continue;
  5011. + }
  5012. +
  5013. + /* We have found a clash. */
  5014. + ipkg_message(conf, IPKG_ERROR,
  5015. + "Package %s wants to install file %s\n"
  5016. + "\tBut that file is already provided by package ",
  5017. + pkg->name, filename);
  5018. + if (owner) {
  5019. + ipkg_message(conf, IPKG_ERROR,
  5020. + "%s\n", owner->name);
  5021. + } else {
  5022. + ipkg_message(conf, IPKG_ERROR,
  5023. + "<no package>\nPlease move this file out of the way and try again.\n");
  5024. + }
  5025. + clashes++;
  5026. + }
  5027. + free(root_filename);
  5028. + }
  5029. + pkg_free_installed_files(pkg);
  5030. +
  5031. + return clashes;
  5032. +}
  5033. +
  5034. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg)
  5035. +{
  5036. + /* Basically that's the worst hack I could do to be able to change ownership of
  5037. + file list, but, being that we have no way to unwind the mods, due to structure
  5038. + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
  5039. + What we do here is change the ownership of file in hash if a replace ( or similar events
  5040. + happens )
  5041. + Only the action that are needed to change name should be considered.
  5042. + @@@ To change after 1.0 release.
  5043. + */
  5044. + str_list_t *files_list;
  5045. + str_list_elt_t *iter;
  5046. +
  5047. + int clashes = 0;
  5048. +
  5049. + files_list = pkg_get_installed_files(pkg);
  5050. + for (iter = files_list->head; iter; iter = iter->next) {
  5051. + char *root_filename;
  5052. + char *filename = iter->data;
  5053. + root_filename = root_filename_alloc(conf, filename);
  5054. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  5055. + pkg_t *owner;
  5056. +
  5057. + if (conf->force_overwrite) {
  5058. + /* but we need to change who owns this file */
  5059. + file_hash_set_file_owner(conf, filename, pkg);
  5060. + continue;
  5061. + }
  5062. +
  5063. + owner = file_hash_get_file_owner(conf, filename);
  5064. +
  5065. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  5066. + if (owner) {
  5067. + if (pkg_replaces(pkg, owner)) {
  5068. +/* It's now time to change the owner of that file.
  5069. + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
  5070. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  5071. + file_hash_set_file_owner(conf, filename, pkg);
  5072. + continue;
  5073. + }
  5074. + }
  5075. +
  5076. + }
  5077. + free(root_filename);
  5078. + }
  5079. + pkg_free_installed_files(pkg);
  5080. +
  5081. + return clashes;
  5082. +}
  5083. +
  5084. +/*
  5085. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5086. +{
  5087. + Nothing to do since check_data_file_clashes doesn't change state
  5088. + return 0;
  5089. +}
  5090. +*/
  5091. +
  5092. +/*
  5093. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5094. +{
  5095. + DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
  5096. + 1. If the package is being upgraded, call
  5097. + old-postrm upgrade new-version
  5098. + 2. If this fails, attempt:
  5099. + new-postrm failed-upgrade old-version
  5100. + Error unwind, for both cases:
  5101. + old-preinst abort-upgrade new-version
  5102. + return 0;
  5103. +}
  5104. +*/
  5105. +
  5106. +/*
  5107. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5108. +{
  5109. + DPKG_INCOMPATIBILITY:
  5110. + dpkg does some things here that we don't do yet. Do we care?
  5111. + (See postrm_upgrade_old_pkg for details)
  5112. + return 0;
  5113. +}
  5114. +*/
  5115. +
  5116. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5117. +{
  5118. + int err;
  5119. + str_list_t *old_files;
  5120. + str_list_elt_t *of;
  5121. + str_list_t *new_files;
  5122. + str_list_elt_t *nf;
  5123. +
  5124. + if (old_pkg == NULL) {
  5125. + return 0;
  5126. + }
  5127. +
  5128. + old_files = pkg_get_installed_files(old_pkg);
  5129. + new_files = pkg_get_installed_files(pkg);
  5130. +
  5131. + for (of = old_files->head; of; of = of->next) {
  5132. + pkg_t *owner;
  5133. + char *old, *new;
  5134. + old = of->data;
  5135. + for (nf = new_files->head; nf; nf = nf->next) {
  5136. + new = nf->data;
  5137. + if (strcmp(old, new) == 0) {
  5138. + goto NOT_OBSOLETE;
  5139. + }
  5140. + }
  5141. + if (file_is_dir(old)) {
  5142. + continue;
  5143. + }
  5144. + owner = file_hash_get_file_owner(conf, old);
  5145. + if (owner != old_pkg) {
  5146. + /* in case obsolete file no longer belongs to old_pkg */
  5147. + continue;
  5148. + }
  5149. +
  5150. + /* old file is obsolete */
  5151. + ipkg_message(conf, IPKG_INFO,
  5152. + " removing obsolete file %s\n", old);
  5153. + if (!conf->noaction) {
  5154. + err = unlink(old);
  5155. + if (err) {
  5156. + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
  5157. + strerror(errno));
  5158. + }
  5159. + }
  5160. +
  5161. + NOT_OBSOLETE:
  5162. + ;
  5163. + }
  5164. +
  5165. + pkg_free_installed_files(old_pkg);
  5166. + pkg_free_installed_files(pkg);
  5167. +
  5168. + return 0;
  5169. +}
  5170. +
  5171. +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5172. +{
  5173. + int i;
  5174. + int err = 0;
  5175. + char *globpattern;
  5176. + glob_t globbuf;
  5177. + if (0) {
  5178. + if (!pkg->dest) {
  5179. + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
  5180. + return -1;
  5181. + }
  5182. + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
  5183. + err = glob(globpattern, 0, NULL, &globbuf);
  5184. + free(globpattern);
  5185. + if (err) {
  5186. + return err;
  5187. + }
  5188. + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
  5189. + for (i = 0; i < globbuf.gl_pathc; i++) {
  5190. + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
  5191. + globbuf.gl_pathv[i], old_pkg->name);
  5192. + if (!conf->noaction)
  5193. + unlink(globbuf.gl_pathv[i]);
  5194. + }
  5195. + globfree(&globbuf);
  5196. + }
  5197. + return err;
  5198. +}
  5199. +
  5200. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5201. +{
  5202. + int ret;
  5203. + char *prefix;
  5204. +
  5205. + if (old_pkg)
  5206. + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
  5207. + sprintf_alloc(&prefix, "%s.", pkg->name);
  5208. + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
  5209. + pkg->dest->info_dir,
  5210. + prefix);
  5211. + free(prefix);
  5212. + return ret;
  5213. +}
  5214. +
  5215. +/*
  5216. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
  5217. +{
  5218. + DPKG_INCOMPATIBILITY:
  5219. + This is a fairly sophisticated dpkg operation. Shall we
  5220. + skip it?
  5221. +
  5222. + Any packages all of whose files have been overwritten during the
  5223. + installation, and which aren't required for dependencies, are
  5224. + considered to have been removed. For each such package
  5225. + 1. disappearer's-postrm disappear overwriter overwriter-version
  5226. + 2. The package's maintainer scripts are removed
  5227. + 3. It is noted in the status database as being in a sane state,
  5228. + namely not installed (any conffiles it may have are ignored,
  5229. + rather than being removed by dpkg). Note that disappearing
  5230. + packages do not have their prerm called, because dpkg doesn't
  5231. + know in advance that the package is going to vanish.
  5232. +
  5233. +
  5234. + return 0;
  5235. +}
  5236. +*/
  5237. +
  5238. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
  5239. +{
  5240. + int err;
  5241. +
  5242. + /* ipkg takes a slightly different approach to data file backups
  5243. + than dpkg. Rather than removing backups at this point, we
  5244. + actually do the data file installation now. See comments in
  5245. + check_data_file_clashes() for more details. */
  5246. +
  5247. + ipkg_message(conf, IPKG_INFO,
  5248. + " extracting data files to %s\n", pkg->dest->root_dir);
  5249. + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
  5250. + if (err) {
  5251. + return err;
  5252. + }
  5253. +
  5254. + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
  5255. + so we can't save ourself from removing important packages
  5256. + At this point we (should) have extracted the .control file, so it
  5257. + would be a good idea to reload the data in it, and set the Essential
  5258. + state in *pkg. From now on the Essential is back in status file and
  5259. + we can protect again.
  5260. + We should operate this way:
  5261. + fopen the file ( pkg->dest->root_dir/pkg->name.control )
  5262. + check for "Essential" in it
  5263. + set the value in pkg->essential.
  5264. + This new routine could be useful also for every other flag
  5265. + Pigi: 16/03/2004 */
  5266. + set_flags_from_control(conf, pkg) ;
  5267. +
  5268. + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
  5269. + err = pkg_write_filelist(conf, pkg);
  5270. + if (err)
  5271. + return err;
  5272. +
  5273. + /* XXX: FEATURE: ipkg should identify any files which existed
  5274. + before installation and which were overwritten, (see
  5275. + check_data_file_clashes()). What it must do is remove any such
  5276. + files from the filelist of the old package which provided the
  5277. + file. Otherwise, if the old package were removed at some point
  5278. + it would break the new package. Removing the new package will
  5279. + also break the old one, but this cannot be helped since the old
  5280. + package's file has already been deleted. This is the importance
  5281. + of check_data_file_clashes(), and only allowing ipkg to install
  5282. + a clashing package with a user force. */
  5283. +
  5284. + return 0;
  5285. +}
  5286. +
  5287. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
  5288. +{
  5289. + conffile_list_elt_t *iter;
  5290. + conffile_t *cf;
  5291. + char *cf_backup;
  5292. + uint8_t *md5sum;
  5293. +
  5294. +
  5295. + if (conf->noaction) return 0;
  5296. +
  5297. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  5298. + char *root_filename;
  5299. + cf = iter->data;
  5300. + root_filename = root_filename_alloc(conf, cf->name);
  5301. +
  5302. + /* Might need to initialize the md5sum for each conffile */
  5303. + if (cf->value == NULL) {
  5304. + cf->value = (char *)file_md5sum_alloc(root_filename);
  5305. + }
  5306. +
  5307. + if (!file_exists(root_filename)) {
  5308. + free(root_filename);
  5309. + continue;
  5310. + }
  5311. +
  5312. + cf_backup = backup_filename_alloc(root_filename);
  5313. +
  5314. +
  5315. + if (file_exists(cf_backup)) {
  5316. + /* Let's compute md5 to test if files are changed */
  5317. + md5sum = file_md5sum_alloc(cf_backup);
  5318. + if (strcmp( cf->value, (char *)md5sum) != 0 ) {
  5319. + if (conf->force_defaults
  5320. + || user_prefers_old_conffile(cf->name, cf_backup) ) {
  5321. + rename(cf_backup, root_filename);
  5322. + }
  5323. + }
  5324. + unlink(cf_backup);
  5325. + free(md5sum);
  5326. + }
  5327. +
  5328. + free(cf_backup);
  5329. + free(root_filename);
  5330. + }
  5331. +
  5332. + return 0;
  5333. +}
  5334. +
  5335. +static int user_prefers_old_conffile(const char *file_name, const char *backup)
  5336. +{
  5337. + char *response;
  5338. + const char *short_file_name;
  5339. +
  5340. + short_file_name = strrchr(file_name, '/');
  5341. + if (short_file_name) {
  5342. + short_file_name++;
  5343. + } else {
  5344. + short_file_name = file_name;
  5345. + }
  5346. +
  5347. + while (1) {
  5348. + response = get_user_response(" Configuration file '%s'\n"
  5349. + " ==> File on system created by you or by a script.\n"
  5350. + " ==> File also in package provided by package maintainer.\n"
  5351. + " What would you like to do about it ? Your options are:\n"
  5352. + " Y or I : install the package maintainer's version\n"
  5353. + " N or O : keep your currently-installed version\n"
  5354. +#ifdef CONFIG_DIFF
  5355. + " D : show the differences between the versions\n"
  5356. +#endif
  5357. + " The default action is to keep your current version.\n"
  5358. + " *** %s (Y/I/N/O"
  5359. +#ifdef CONFIG_DIFF
  5360. + "/D"
  5361. +#endif
  5362. + ") [default=N] ? ", file_name, short_file_name);
  5363. + if (strcmp(response, "y") == 0
  5364. + || strcmp(response, "i") == 0
  5365. + || strcmp(response, "yes") == 0) {
  5366. + free(response);
  5367. + return 0;
  5368. + }
  5369. +
  5370. +#ifdef CONFIG_DIFF
  5371. + if (strcmp(response, "d") == 0) {
  5372. + char *cmd;
  5373. +
  5374. + free(response);
  5375. + /* XXX: BUG rewrite to use exec or busybox's internal diff */
  5376. + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
  5377. + xsystem(cmd);
  5378. + free(cmd);
  5379. + printf(" [Press ENTER to continue]\n");
  5380. + response = file_read_line_alloc(stdin);
  5381. + free(response);
  5382. + continue;
  5383. + }
  5384. +#endif
  5385. +
  5386. + free(response);
  5387. + return 1;
  5388. + }
  5389. +}
  5390. +
  5391. +/* XXX: CLEANUP: I'd like to move all of the code for
  5392. + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
  5393. + it would make sense to cleanup pkg->tmp_unpack_dir directly from
  5394. + pkg_deinit for example). */
  5395. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
  5396. +{
  5397. + DIR *tmp_dir;
  5398. + struct dirent *dirent;
  5399. + char *tmp_file;
  5400. +
  5401. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  5402. +#error
  5403. + ipkg_message(conf, IPKG_DEBUG,
  5404. + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  5405. + __FUNCTION__, pkg->tmp_unpack_dir);
  5406. + return 0;
  5407. +#endif
  5408. +
  5409. + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
  5410. + tmp_dir = opendir(pkg->tmp_unpack_dir);
  5411. + if (tmp_dir) {
  5412. + while (1) {
  5413. + dirent = readdir(tmp_dir);
  5414. + if (dirent == NULL) {
  5415. + break;
  5416. + }
  5417. + sprintf_alloc(&tmp_file, "%s/%s",
  5418. + pkg->tmp_unpack_dir, dirent->d_name);
  5419. + if (! file_is_dir(tmp_file)) {
  5420. + unlink(tmp_file);
  5421. + }
  5422. + free(tmp_file);
  5423. + }
  5424. + closedir(tmp_dir);
  5425. + rmdir(pkg->tmp_unpack_dir);
  5426. + free(pkg->tmp_unpack_dir);
  5427. + pkg->tmp_unpack_dir = NULL;
  5428. + }
  5429. + }
  5430. +
  5431. + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
  5432. + pkg->name, pkg->local_filename, conf->tmp_dir);
  5433. + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
  5434. + unlink(pkg->local_filename);
  5435. + free(pkg->local_filename);
  5436. + pkg->local_filename = NULL;
  5437. + }
  5438. +
  5439. + return 0;
  5440. +}
  5441. +
  5442. +static char *backup_filename_alloc(const char *file_name)
  5443. +{
  5444. + char *backup;
  5445. +
  5446. + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
  5447. +
  5448. + return backup;
  5449. +}
  5450. +
  5451. +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
  5452. +{
  5453. + int err;
  5454. + char *backup;
  5455. +
  5456. + backup = backup_filename_alloc(file_name);
  5457. + err = file_copy(file_name, backup);
  5458. + if (err) {
  5459. + ipkg_message(conf, IPKG_ERROR,
  5460. + "%s: Failed to copy %s to %s\n",
  5461. + __FUNCTION__, file_name, backup);
  5462. + }
  5463. +
  5464. + free(backup);
  5465. +
  5466. + return err;
  5467. +}
  5468. +
  5469. +static int backup_exists_for(const char *file_name)
  5470. +{
  5471. + int ret;
  5472. + char *backup;
  5473. +
  5474. + backup = backup_filename_alloc(file_name);
  5475. +
  5476. + ret = file_exists(backup);
  5477. +
  5478. + free(backup);
  5479. +
  5480. + return ret;
  5481. +}
  5482. +
  5483. +static int backup_remove(const char *file_name)
  5484. +{
  5485. + char *backup;
  5486. +
  5487. + backup = backup_filename_alloc(file_name);
  5488. + unlink(backup);
  5489. + free(backup);
  5490. +
  5491. + return 0;
  5492. +}
  5493. +
  5494. +
  5495. +
  5496. +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
  5497. +
  5498. +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
  5499. +{
  5500. + /* first, remove the packages that need removing */
  5501. + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
  5502. + pkg_t *pkg = pkgs_to_remove->pkgs[i];
  5503. + err = ipkg_remove_pkg(conf, pkg,0);
  5504. + if (err) return err;
  5505. + }
  5506. + return 0;
  5507. +}
  5508. +
  5509. +int ipkg_process_actions_sanity_check(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_superseded, pkg_vec_t *pkgs_to_install)
  5510. +{
  5511. + int i;
  5512. + /* now one more pass checking on the ones that need to be installed */
  5513. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5514. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5515. + if (pkg->dest == NULL)
  5516. + pkg->dest = conf->default_dest;
  5517. +
  5518. + pkg->state_want = SW_INSTALL;
  5519. +
  5520. + /* Abhaya: conflicts check */
  5521. + err = check_conflicts_for(conf, pkg);
  5522. + if (err) { return err; }
  5523. + }
  5524. + return 0;
  5525. +}
  5526. +
  5527. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5528. +{
  5529. + int i;
  5530. + /* now one more pass checking on the ones that need to be installed */
  5531. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5532. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5533. +
  5534. + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
  5535. + pkg_vec_t *replacees = pkg_vec_alloc();
  5536. + pkg_get_installed_replacees(pkg, replacees);
  5537. +
  5538. + /* XXX: BUG: we really should treat replacement more like an upgrade
  5539. + * Instead, we're going to remove the replacees
  5540. + */
  5541. + err = pkg_remove_installed_replacees(conf, replacees);
  5542. + if (err) return err;
  5543. + pkg->state_flag |= SF_REMOVED_REPLACEES;
  5544. + }
  5545. + return 0;
  5546. +}
  5547. +
  5548. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5549. +{
  5550. + int i;
  5551. + /* now one more pass checking on the ones that need to be installed */
  5552. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5553. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5554. + if (pkg->local_filename == NULL) {
  5555. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  5556. + if (err) {
  5557. + ipkg_message(conf, IPKG_ERROR,
  5558. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  5559. + pkg->name);
  5560. + return err;
  5561. + }
  5562. + }
  5563. + if (pkg->tmp_unpack_dir == NULL) {
  5564. + err = unpack_pkg_control_files(conf, pkg);
  5565. + if (err) return err;
  5566. + }
  5567. + }
  5568. + return 0;
  5569. +}
  5570. +
  5571. +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5572. +{
  5573. + int i;
  5574. + /* now one more pass checking on the ones that need to be installed */
  5575. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5576. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5577. + pkg_t *old_pkg = pkg->old_pkg;
  5578. +
  5579. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  5580. + if (err) return err;
  5581. +
  5582. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  5583. + if (err) return err;
  5584. +
  5585. + err = preinst_configure(conf, pkg, old_pkg);
  5586. + if (err) return err;
  5587. +
  5588. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  5589. + if (err) return err;
  5590. +
  5591. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  5592. + if (err) return err;
  5593. + }
  5594. + return 0;
  5595. +}
  5596. +
  5597. +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5598. +{
  5599. + int i;
  5600. + /* now one more pass checking on the ones that need to be installed */
  5601. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5602. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5603. + pkg_t *old_pkg = pkg->old_pkg;
  5604. +
  5605. + if (old_pkg) {
  5606. + old_pkg->state_want = SW_DEINSTALL;
  5607. +
  5608. + if (old_pkg->state_flag & SF_NOPRUNE) {
  5609. + ipkg_message(conf, IPKG_INFO,
  5610. + " not removing obsolesced files because package marked noprune\n");
  5611. + } else {
  5612. + ipkg_message(conf, IPKG_INFO,
  5613. + " removing obsolesced files\n");
  5614. + remove_obsolesced_files(conf, pkg, old_pkg);
  5615. + }
  5616. + }
  5617. +
  5618. + ipkg_message(conf, IPKG_INFO,
  5619. + " installing maintainer scripts\n");
  5620. + install_maintainer_scripts(conf, pkg, old_pkg);
  5621. +
  5622. + /* the following just returns 0 */
  5623. + remove_disappeared(conf, pkg);
  5624. +
  5625. + ipkg_message(conf, IPKG_INFO,
  5626. + " installing data files\n");
  5627. + install_data_files(conf, pkg);
  5628. +
  5629. + ipkg_message(conf, IPKG_INFO,
  5630. + " resolving conf files\n");
  5631. + resolve_conffiles(conf, pkg);
  5632. +
  5633. + pkg->state_status = SS_UNPACKED;
  5634. +
  5635. + if (old_pkg) {
  5636. + old_pkg->state_status = SS_NOT_INSTALLED;
  5637. + }
  5638. +
  5639. + time(&pkg->installed_time);
  5640. +
  5641. + ipkg_message(conf, IPKG_INFO,
  5642. + " cleanup temp files\n");
  5643. + cleanup_temporary_files(conf, pkg);
  5644. +
  5645. + if (pkg->parent)
  5646. + pkg->parent->state_status = pkg->state_status;
  5647. + }
  5648. + return 0;
  5649. +}
  5650. +
  5651. +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5652. +{
  5653. + int i;
  5654. + /* now one more pass checking on the ones that need to be installed */
  5655. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5656. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5657. + pkg_t *old_pkg = pkg->old_pkg;
  5658. +
  5659. + if (old_pkg) {
  5660. + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
  5661. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5662. + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
  5663. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  5664. + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
  5665. + backup_modified_conffiles_unwind(pkg, old_pkg);
  5666. + */
  5667. + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
  5668. + preinst_configure_unwind(conf, pkg, old_pkg);
  5669. + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
  5670. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  5671. + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
  5672. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5673. + */
  5674. +
  5675. + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
  5676. + remove_installed_replacees_unwind(conf, pkg, old_pkg);
  5677. +
  5678. + }
  5679. + }
  5680. + return 0;
  5681. +}
  5682. +
  5683. +/*
  5684. + * Perform all the actions.
  5685. + *
  5686. + * pkgs_to_remove are packages marked for removal.
  5687. + * pkgs_superseded are the old packages being replaced by upgrades.
  5688. + *
  5689. + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
  5690. + */
  5691. +int ipkg_process_actions(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_superseded, pkg_vec_t *pkgs_to_install)
  5692. +{
  5693. + int err;
  5694. + int i;
  5695. +
  5696. + err = ipkg_remove_packages(conf, pkgs_to_remove);
  5697. + if (err) return err;
  5698. +
  5699. + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
  5700. + if (err) return err;
  5701. +
  5702. + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
  5703. + if (err) goto UNWIND;
  5704. +
  5705. + /* @@@@ look at ipkg_install_pkg for handling replacements */
  5706. + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
  5707. + if (err) goto UNWIND;
  5708. +
  5709. + /*
  5710. + * Now that we have the packages unpacked, we can look for data
  5711. + * file clashes. First, we mark the files from the superseded
  5712. + * packages as obsolete. Then we scan the files in
  5713. + * pkgs_to_install, and only complain about clashes with
  5714. + * non-obsolete files.
  5715. + */
  5716. +
  5717. + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
  5718. + if (err) goto UNWIND;
  5719. +
  5720. + /* this was before checking data file clashes */
  5721. + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
  5722. + if (err) goto UNWIND;
  5723. +
  5724. + /* point of no return: no unwinding after this */
  5725. + err = ipkg_process_actions_install(conf, pkgs_to_install);
  5726. + if (err) return err;
  5727. +
  5728. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  5729. + return 0;
  5730. +
  5731. + UNWIND:
  5732. + ipkg_process_actions_unwind(conf, pkgs_to_install);
  5733. +
  5734. + ipkg_message(conf, IPKG_INFO,
  5735. + " cleanup temp files\n");
  5736. + cleanup_temporary_files(conf, pkg);
  5737. +
  5738. + ipkg_message(conf, IPKG_INFO,
  5739. + "Failed.\n");
  5740. + return err;
  5741. +}
  5742. +
  5743. +#endif
  5744. --- /dev/null
  5745. +++ busybox-1.18.1/archival/libipkg/ipkg_install.h
  5746. @@ -0,0 +1,35 @@
  5747. +/* ipkg_install.h - the itsy package management system
  5748. +
  5749. + Carl D. Worth
  5750. +
  5751. + Copyright (C) 2001 University of Southern California
  5752. +
  5753. + This program is free software; you can redistribute it and/or
  5754. + modify it under the terms of the GNU General Public License as
  5755. + published by the Free Software Foundation; either version 2, or (at
  5756. + your option) any later version.
  5757. +
  5758. + This program is distributed in the hope that it will be useful, but
  5759. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5760. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5761. + General Public License for more details.
  5762. +*/
  5763. +
  5764. +#ifndef IPKG_INSTALL_H
  5765. +#define IPKG_INSTALL_H
  5766. +
  5767. +#include "pkg.h"
  5768. +#include "ipkg_conf.h"
  5769. +
  5770. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5771. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5772. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
  5773. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
  5774. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  5775. +
  5776. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
  5777. +
  5778. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
  5779. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
  5780. +
  5781. +#endif
  5782. --- /dev/null
  5783. +++ busybox-1.18.1/archival/libipkg/ipkg_message.c
  5784. @@ -0,0 +1,35 @@
  5785. +/* ipkg_message.c - the itsy package management system
  5786. +
  5787. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5788. +
  5789. + This program is free software; you can redistribute it and/or
  5790. + modify it under the terms of the GNU General Public License as
  5791. + published by the Free Software Foundation; either version 2, or (at
  5792. + your option) any later version.
  5793. +
  5794. + This program is distributed in the hope that it will be useful, but
  5795. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5796. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5797. + General Public License for more details.
  5798. +*/
  5799. +
  5800. +
  5801. +#include "ipkg.h"
  5802. +#include "ipkg_conf.h"
  5803. +#include "ipkg_message.h"
  5804. +#include "libipkg.h"
  5805. +
  5806. +void
  5807. +ipkg_message (ipkg_conf_t * conf, message_level_t level, const char *fmt, ...)
  5808. +{
  5809. + va_list ap;
  5810. + char ts[256];
  5811. +
  5812. + if (ipkg_cb_message)
  5813. + {
  5814. + va_start (ap, fmt);
  5815. + vsnprintf (ts,256,fmt, ap);
  5816. + va_end (ap);
  5817. + ipkg_cb_message(conf,level,ts);
  5818. + }
  5819. +}
  5820. --- /dev/null
  5821. +++ busybox-1.18.1/archival/libipkg/ipkg_message.h
  5822. @@ -0,0 +1,32 @@
  5823. +/* ipkg_message.h - the itsy package management system
  5824. +
  5825. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5826. +
  5827. + This program is free software; you can redistribute it and/or
  5828. + modify it under the terms of the GNU General Public License as
  5829. + published by the Free Software Foundation; either version 2, or (at
  5830. + your option) any later version.
  5831. +
  5832. + This program is distributed in the hope that it will be useful, but
  5833. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5834. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5835. + General Public License for more details.
  5836. +*/
  5837. +
  5838. +#ifndef _IPKG_MESSAGE_H_
  5839. +#define _IPKG_MESSAGE_H_
  5840. +
  5841. +#include "ipkg.h"
  5842. +#include "ipkg_conf.h"
  5843. +
  5844. +typedef enum {
  5845. + IPKG_ERROR, /* error conditions */
  5846. + IPKG_NOTICE, /* normal but significant condition */
  5847. + IPKG_INFO, /* informational message */
  5848. + IPKG_DEBUG, /* debug level message */
  5849. + IPKG_DEBUG2, /* more debug level message */
  5850. +} message_level_t;
  5851. +
  5852. +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, const char *fmt, ...);
  5853. +
  5854. +#endif /* _IPKG_MESSAGE_H_ */
  5855. --- /dev/null
  5856. +++ busybox-1.18.1/archival/libipkg/ipkg_remove.c
  5857. @@ -0,0 +1,385 @@
  5858. +/* ipkg_remove.c - the itsy package management system
  5859. +
  5860. + Carl D. Worth
  5861. +
  5862. + Copyright (C) 2001 University of Southern California
  5863. +
  5864. + This program is free software; you can redistribute it and/or
  5865. + modify it under the terms of the GNU General Public License as
  5866. + published by the Free Software Foundation; either version 2, or (at
  5867. + your option) any later version.
  5868. +
  5869. + This program is distributed in the hope that it will be useful, but
  5870. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5871. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5872. + General Public License for more details.
  5873. +*/
  5874. +
  5875. +#include "ipkg.h"
  5876. +#include "ipkg_message.h"
  5877. +
  5878. +#include <glob.h>
  5879. +
  5880. +#include "ipkg_remove.h"
  5881. +
  5882. +#include "file_util.h"
  5883. +#include "sprintf_alloc.h"
  5884. +#include "str_util.h"
  5885. +
  5886. +#include "ipkg_cmd.h"
  5887. +
  5888. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents);
  5889. +
  5890. +/*
  5891. + * Returns number of the number of packages depending on the packages provided by this package.
  5892. + * Every package implicitly provides itself.
  5893. + */
  5894. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents)
  5895. +{
  5896. + int nprovides = pkg->provides_count;
  5897. + abstract_pkg_t **provides = pkg->provides;
  5898. + int n_installed_dependents = 0;
  5899. + int i;
  5900. + for (i = 0; i <= nprovides; i++) {
  5901. + abstract_pkg_t *providee = provides[i];
  5902. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5903. + abstract_pkg_t *dep_ab_pkg;
  5904. + if (dependers == NULL)
  5905. + continue;
  5906. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5907. + if (dep_ab_pkg->state_status == SS_INSTALLED){
  5908. + n_installed_dependents++;
  5909. + }
  5910. + }
  5911. +
  5912. + }
  5913. + /* if caller requested the set of installed dependents */
  5914. + if (pdependents) {
  5915. + int p = 0;
  5916. + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
  5917. +
  5918. + if ( dependents == NULL ){
  5919. + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
  5920. + return -1;
  5921. + }
  5922. +
  5923. + *pdependents = dependents;
  5924. + for (i = 0; i <= nprovides; i++) {
  5925. + abstract_pkg_t *providee = provides[i];
  5926. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5927. + abstract_pkg_t *dep_ab_pkg;
  5928. + if (dependers == NULL)
  5929. + continue;
  5930. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5931. + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
  5932. + dependents[p++] = dep_ab_pkg;
  5933. + dep_ab_pkg->state_flag |= SF_MARKED;
  5934. + }
  5935. + }
  5936. + }
  5937. + dependents[p] = NULL;
  5938. + /* now clear the marks */
  5939. + for (i = 0; i < p; i++) {
  5940. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  5941. + dep_ab_pkg->state_flag &= ~SF_MARKED;
  5942. + }
  5943. + }
  5944. + return n_installed_dependents;
  5945. +}
  5946. +
  5947. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  5948. +{
  5949. + int i;
  5950. + int a;
  5951. + int count;
  5952. + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
  5953. + abstract_pkg_t * ab_pkg;
  5954. +
  5955. + if((ab_pkg = pkg->parent) == NULL){
  5956. + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
  5957. + __FUNCTION__, pkg->name);
  5958. + return 0;
  5959. + }
  5960. +
  5961. + if (dependents == NULL)
  5962. + return 0;
  5963. +
  5964. + // here i am using the dependencies_checked
  5965. + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
  5966. + return 0; // has already been encountered in the process
  5967. + // of marking packages for removal - Karthik
  5968. + ab_pkg->dependencies_checked = 2;
  5969. +
  5970. + i = 0;
  5971. + count = 1;
  5972. + while (dependents [i] != NULL) {
  5973. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  5974. +
  5975. + if (dep_ab_pkg->dependencies_checked == 2){
  5976. + i++;
  5977. + continue;
  5978. + }
  5979. + if (dep_ab_pkg->state_status == SS_INSTALLED) {
  5980. + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
  5981. + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
  5982. + if (dep_pkg->state_status == SS_INSTALLED) {
  5983. + pkg_vec_insert(dependent_pkgs, dep_pkg);
  5984. + count++;
  5985. + }
  5986. + }
  5987. + }
  5988. + i++;
  5989. + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
  5990. + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
  5991. + }
  5992. +
  5993. + if (count == 1)
  5994. + return 0;
  5995. +
  5996. +
  5997. + for (i = 0; i < dependent_pkgs->len; i++) {
  5998. + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
  5999. + if (err)
  6000. + return err;
  6001. + }
  6002. + return 0;
  6003. +}
  6004. +
  6005. +static int user_prefers_removing_dependents(ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  6006. +{
  6007. + abstract_pkg_t *dep_ab_pkg;
  6008. + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
  6009. + while ((dep_ab_pkg = *dependents++) != NULL) {
  6010. + if (dep_ab_pkg->state_status == SS_INSTALLED)
  6011. + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
  6012. + }
  6013. + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
  6014. + ipkg_message(conf, IPKG_ERROR, "");
  6015. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
  6016. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
  6017. + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
  6018. + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
  6019. + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
  6020. + return 0;
  6021. +}
  6022. +
  6023. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
  6024. +{
  6025. +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
  6026. + thus I wan't check for essential, as I'm upgrading.
  6027. + I hope it won't break anything :)
  6028. +*/
  6029. + int err;
  6030. + abstract_pkg_t *parent_pkg = NULL;
  6031. +
  6032. + if (pkg->essential && !message) {
  6033. + if (conf->force_removal_of_essential_packages) {
  6034. + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
  6035. + "\tIf your system breaks, you get to keep both pieces\n",
  6036. + pkg->name);
  6037. + } else {
  6038. + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
  6039. + "\tRemoving an essential package may lead to an unusable system, but if\n"
  6040. + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
  6041. + "\tits will with the option: -force-removal-of-essential-packages\n",
  6042. + pkg->name);
  6043. + return IPKG_PKG_IS_ESSENTIAL;
  6044. + }
  6045. + }
  6046. +
  6047. + if ((parent_pkg = pkg->parent) == NULL)
  6048. + return 0;
  6049. +
  6050. + /* only attempt to remove dependent installed packages if
  6051. + * force_depends is not specified or the package is being
  6052. + * replaced.
  6053. + */
  6054. + if (!conf->force_depends
  6055. + && !(pkg->state_flag & SF_REPLACE)) {
  6056. + abstract_pkg_t **dependents;
  6057. + int has_installed_dependents =
  6058. + pkg_has_installed_dependents(pkg, &dependents);
  6059. +
  6060. + if (has_installed_dependents) {
  6061. + /*
  6062. + * if this package is depended up by others, then either we should
  6063. + * not remove it or we should remove it and all of its dependents
  6064. + */
  6065. +
  6066. + if (!conf->force_removal_of_dependent_packages
  6067. + && !user_prefers_removing_dependents(conf, pkg, dependents)) {
  6068. + return IPKG_PKG_HAS_DEPENDENTS;
  6069. + }
  6070. +
  6071. + /* remove packages depending on this package - Karthik */
  6072. + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
  6073. + free(dependents);
  6074. + if (err) return err;
  6075. + }
  6076. + }
  6077. +
  6078. + if ( message==0 ){
  6079. + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
  6080. + fflush(stdout);
  6081. + }
  6082. + pkg->state_flag |= SF_FILELIST_CHANGED;
  6083. +
  6084. + pkg->state_want = SW_DEINSTALL;
  6085. + ipkg_state_changed++;
  6086. +
  6087. + pkg_run_script(conf, pkg, "prerm", "remove");
  6088. +
  6089. + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
  6090. + maintains an empty filelist rather than deleting it. That seems
  6091. + like a big pain, and I don't see that that should make a big
  6092. + difference, but for anyone who wants tighter compatibility,
  6093. + feel free to fix this. */
  6094. + remove_data_files_and_list(conf, pkg);
  6095. +
  6096. + pkg_run_script(conf, pkg, "postrm", "remove");
  6097. +
  6098. + remove_maintainer_scripts_except_postrm(conf, pkg);
  6099. +
  6100. + /* Aman Gupta - Since ipkg is made for handheld devices with limited
  6101. + * space, it doesn't make sense to leave extra configurations, files,
  6102. + * and maintainer scripts left around. So, we make remove like purge,
  6103. + * and take out all the crap :) */
  6104. +
  6105. + remove_postrm(conf, pkg);
  6106. + pkg->state_status = SS_NOT_INSTALLED;
  6107. +
  6108. + if (parent_pkg)
  6109. + parent_pkg->state_status = SS_NOT_INSTALLED;
  6110. +
  6111. + return 0;
  6112. +}
  6113. +
  6114. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
  6115. +{
  6116. + ipkg_remove_pkg(conf, pkg,0);
  6117. + return 0;
  6118. +}
  6119. +
  6120. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
  6121. +{
  6122. + str_list_t installed_dirs;
  6123. + str_list_t *installed_files;
  6124. + str_list_elt_t *iter;
  6125. + char *file_name;
  6126. + conffile_t *conffile;
  6127. + int removed_a_dir;
  6128. + pkg_t *owner;
  6129. +
  6130. + str_list_init(&installed_dirs);
  6131. + installed_files = pkg_get_installed_files(pkg);
  6132. +
  6133. + for (iter = installed_files->head; iter; iter = iter->next) {
  6134. + file_name = iter->data;
  6135. +
  6136. + if (file_is_dir(file_name)) {
  6137. + str_list_append(&installed_dirs, strdup(file_name));
  6138. + continue;
  6139. + }
  6140. +
  6141. + conffile = pkg_get_conffile(pkg, file_name);
  6142. + if (conffile) {
  6143. + /* XXX: QUESTION: Is this right? I figure we only need to
  6144. + save the conffile if it has been modified. Is that what
  6145. + dpkg does? Or does dpkg preserve all conffiles? If so,
  6146. + this seems like a better thing to do to conserve
  6147. + space. */
  6148. + if (conffile_has_been_modified(conf, conffile)) {
  6149. + printf(" not deleting modified conffile %s\n", file_name);
  6150. + fflush(stdout);
  6151. + continue;
  6152. + }
  6153. + }
  6154. +
  6155. + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
  6156. + if (!conf->noaction)
  6157. + unlink(file_name);
  6158. + }
  6159. +
  6160. + if (!conf->noaction) {
  6161. + do {
  6162. + removed_a_dir = 0;
  6163. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6164. + file_name = iter->data;
  6165. +
  6166. + if (rmdir(file_name) == 0) {
  6167. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
  6168. + removed_a_dir = 1;
  6169. + str_list_remove(&installed_dirs, &iter);
  6170. + }
  6171. + }
  6172. + } while (removed_a_dir);
  6173. + }
  6174. +
  6175. + pkg_free_installed_files(pkg);
  6176. + /* We have to remove the file list now, so that
  6177. + find_pkg_owning_file does not always just report this package */
  6178. + pkg_remove_installed_files_list(conf, pkg);
  6179. +
  6180. + /* Don't print warning for dirs that are provided by other packages */
  6181. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6182. + file_name = iter->data;
  6183. +
  6184. + owner = file_hash_get_file_owner(conf, file_name);
  6185. + if (owner) {
  6186. + free(iter->data);
  6187. + iter->data = NULL;
  6188. + str_list_remove(&installed_dirs, &iter);
  6189. + }
  6190. + }
  6191. +
  6192. + /* cleanup */
  6193. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6194. + free(iter->data);
  6195. + iter->data = NULL;
  6196. + }
  6197. + str_list_deinit(&installed_dirs);
  6198. +
  6199. + return 0;
  6200. +}
  6201. +
  6202. +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6203. +{
  6204. + int i, err;
  6205. + char *globpattern;
  6206. + glob_t globbuf;
  6207. +
  6208. + if (conf->noaction) return 0;
  6209. +
  6210. + sprintf_alloc(&globpattern, "%s/%s.*",
  6211. + pkg->dest->info_dir, pkg->name);
  6212. + err = glob(globpattern, 0, NULL, &globbuf);
  6213. + free(globpattern);
  6214. + if (err) {
  6215. + return 0;
  6216. + }
  6217. +
  6218. + for (i = 0; i < globbuf.gl_pathc; i++) {
  6219. + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
  6220. + continue;
  6221. + }
  6222. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
  6223. + unlink(globbuf.gl_pathv[i]);
  6224. + }
  6225. + globfree(&globbuf);
  6226. +
  6227. + return 0;
  6228. +}
  6229. +
  6230. +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6231. +{
  6232. + char *postrm_file_name;
  6233. +
  6234. + if (conf->noaction) return 0;
  6235. +
  6236. + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
  6237. + pkg->dest->info_dir, pkg->name);
  6238. + unlink(postrm_file_name);
  6239. + free(postrm_file_name);
  6240. +
  6241. + return 0;
  6242. +}
  6243. --- /dev/null
  6244. +++ busybox-1.18.1/archival/libipkg/ipkg_remove.h
  6245. @@ -0,0 +1,33 @@
  6246. +/* ipkg_remove.h - the itsy package management system
  6247. +
  6248. + Carl D. Worth
  6249. +
  6250. + Copyright (C) 2001 University of Southern California
  6251. +
  6252. + This program is free software; you can redistribute it and/or
  6253. + modify it under the terms of the GNU General Public License as
  6254. + published by the Free Software Foundation; either version 2, or (at
  6255. + your option) any later version.
  6256. +
  6257. + This program is distributed in the hope that it will be useful, but
  6258. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6259. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6260. + General Public License for more details.
  6261. +*/
  6262. +
  6263. +#ifndef IPKG_REMOVE_H
  6264. +#define IPKG_REMOVE_H
  6265. +
  6266. +#include "pkg.h"
  6267. +#include "ipkg_conf.h"
  6268. +
  6269. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
  6270. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
  6271. +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
  6272. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents);
  6273. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
  6274. +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6275. +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6276. +
  6277. +
  6278. +#endif
  6279. --- /dev/null
  6280. +++ busybox-1.18.1/archival/libipkg/ipkg_upgrade.c
  6281. @@ -0,0 +1,79 @@
  6282. +/* ipkg_upgrade.c - the itsy package management system
  6283. +
  6284. + Carl D. Worth
  6285. + Copyright (C) 2001 University of Southern California
  6286. +
  6287. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6288. +
  6289. + This program is free software; you can redistribute it and/or
  6290. + modify it under the terms of the GNU General Public License as
  6291. + published by the Free Software Foundation; either version 2, or (at
  6292. + your option) any later version.
  6293. +
  6294. + This program is distributed in the hope that it will be useful, but
  6295. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6296. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6297. + General Public License for more details.
  6298. +*/
  6299. +
  6300. +#include "ipkg.h"
  6301. +#include "ipkg_install.h"
  6302. +#include "ipkg_message.h"
  6303. +
  6304. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6305. +
  6306. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
  6307. +{
  6308. + pkg_t *new;
  6309. + int cmp;
  6310. + char *old_version, *new_version;
  6311. +
  6312. + if (old->state_flag & SF_HOLD) {
  6313. + ipkg_message(conf, IPKG_NOTICE,
  6314. + "Not upgrading package %s which is marked "
  6315. + "hold (flags=%#x)\n", old->name, old->state_flag);
  6316. + return 0;
  6317. + }
  6318. +
  6319. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
  6320. + if (new == NULL) {
  6321. + old_version = pkg_version_str_alloc(old);
  6322. + ipkg_message(conf, IPKG_NOTICE,
  6323. + "Assuming locally installed package %s (%s) "
  6324. + "is up to date.\n", old->name, old_version);
  6325. + free(old_version);
  6326. + return 0;
  6327. + }
  6328. +
  6329. + old_version = pkg_version_str_alloc(old);
  6330. + new_version = pkg_version_str_alloc(new);
  6331. +
  6332. + cmp = pkg_compare_versions(old, new);
  6333. + ipkg_message(conf, IPKG_DEBUG,
  6334. + "comparing visible versions of pkg %s:"
  6335. + "\n\t%s is installed "
  6336. + "\n\t%s is available "
  6337. + "\n\t%d was comparison result\n",
  6338. + old->name, old_version, new_version, cmp);
  6339. + if (cmp == 0) {
  6340. + ipkg_message(conf, IPKG_INFO,
  6341. + "Package %s (%s) installed in %s is up to date.\n",
  6342. + old->name, old_version, old->dest->name);
  6343. + free(old_version);
  6344. + free(new_version);
  6345. + return 0;
  6346. + } else if (cmp > 0) {
  6347. + ipkg_message(conf, IPKG_NOTICE,
  6348. + "Not downgrading package %s on %s from %s to %s.\n",
  6349. + old->name, old->dest->name, old_version, new_version);
  6350. + free(old_version);
  6351. + free(new_version);
  6352. + return 0;
  6353. + } else if (cmp < 0) {
  6354. + new->dest = old->dest;
  6355. + old->state_want = SW_DEINSTALL;
  6356. + }
  6357. +
  6358. + new->state_flag |= SF_USER;
  6359. + return ipkg_install_pkg(conf, new,1);
  6360. +}
  6361. --- /dev/null
  6362. +++ busybox-1.18.1/archival/libipkg/ipkg_upgrade.h
  6363. @@ -0,0 +1,18 @@
  6364. +/* ipkg_upgrade.c - the itsy package management system
  6365. +
  6366. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6367. +
  6368. + This program is free software; you can redistribute it and/or
  6369. + modify it under the terms of the GNU General Public License as
  6370. + published by the Free Software Foundation; either version 2, or (at
  6371. + your option) any later version.
  6372. +
  6373. + This program is distributed in the hope that it will be useful, but
  6374. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6375. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6376. + General Public License for more details.
  6377. +*/
  6378. +
  6379. +#include "ipkg.h"
  6380. +
  6381. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6382. --- /dev/null
  6383. +++ busybox-1.18.1/archival/libipkg/ipkg_utils.c
  6384. @@ -0,0 +1,185 @@
  6385. +/* ipkg_utils.c - the itsy package management system
  6386. +
  6387. + Steven M. Ayer
  6388. +
  6389. + Copyright (C) 2002 Compaq Computer Corporation
  6390. +
  6391. + This program is free software; you can redistribute it and/or
  6392. + modify it under the terms of the GNU General Public License as
  6393. + published by the Free Software Foundation; either version 2, or (at
  6394. + your option) any later version.
  6395. +
  6396. + This program is distributed in the hope that it will be useful, but
  6397. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6398. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6399. + General Public License for more details.
  6400. +*/
  6401. +
  6402. +#include "ipkg.h"
  6403. +#include <errno.h>
  6404. +#include <ctype.h>
  6405. +#include <sys/vfs.h>
  6406. +
  6407. +#include "ipkg_utils.h"
  6408. +#include "pkg.h"
  6409. +#include "pkg_hash.h"
  6410. +
  6411. +void push_error_list(struct errlist ** errors, char * msg);
  6412. +void reverse_error_list(struct errlist **errors);
  6413. +void free_error_list(struct errlist **errors);
  6414. +
  6415. +struct errlist* error_list;
  6416. +
  6417. +int get_available_blocks(char * filesystem)
  6418. +{
  6419. + struct statfs sfs;
  6420. +
  6421. + if(statfs(filesystem, &sfs)){
  6422. + fprintf(stderr, "bad statfs\n");
  6423. + return 0;
  6424. + }
  6425. + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
  6426. + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
  6427. +}
  6428. +
  6429. +char **read_raw_pkgs_from_file(const char *file_name)
  6430. +{
  6431. + FILE *fp;
  6432. + char **ret;
  6433. +
  6434. + if(!(fp = fopen(file_name, "r"))){
  6435. + fprintf(stderr, "can't get %s open for read\n", file_name);
  6436. + return NULL;
  6437. + }
  6438. +
  6439. + ret = read_raw_pkgs_from_stream(fp);
  6440. +
  6441. + fclose(fp);
  6442. +
  6443. + return ret;
  6444. +}
  6445. +
  6446. +char **read_raw_pkgs_from_stream(FILE *fp)
  6447. +{
  6448. + char **raw = NULL, *buf, *scout;
  6449. + int count = 0;
  6450. + size_t size = 512;
  6451. +
  6452. + buf = malloc (size);
  6453. +
  6454. + while (fgets(buf, size, fp)) {
  6455. + while (strlen (buf) == (size - 1)
  6456. + && buf[size-2] != '\n') {
  6457. + size_t o = size - 1;
  6458. + size *= 2;
  6459. + buf = realloc (buf, size);
  6460. + if (fgets (buf + o, size - o, fp) == NULL)
  6461. + break;
  6462. + }
  6463. +
  6464. + if(!(count % 50))
  6465. + raw = realloc(raw, (count + 50) * sizeof(char *));
  6466. +
  6467. + if((scout = strchr(buf, '\n')))
  6468. + *scout = '\0';
  6469. +
  6470. + raw[count++] = strdup(buf);
  6471. + }
  6472. +
  6473. + raw = realloc(raw, (count + 1) * sizeof(char *));
  6474. + raw[count] = NULL;
  6475. +
  6476. + free (buf);
  6477. +
  6478. + return raw;
  6479. +}
  6480. +
  6481. +/* something to remove whitespace, a hash pooper */
  6482. +char *trim_alloc(char *line)
  6483. +{
  6484. + char *new;
  6485. + char *dest, *src, *end;
  6486. +
  6487. + new = malloc(strlen(line) + 1);
  6488. + if ( new == NULL ){
  6489. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  6490. + return NULL;
  6491. + }
  6492. + dest = new, src = line, end = line + (strlen(line) - 1);
  6493. +
  6494. + /* remove it from the front */
  6495. + while(src &&
  6496. + isspace(*src) &&
  6497. + *src)
  6498. + src++;
  6499. + /* and now from the back */
  6500. + while((end > src) &&
  6501. + isspace(*end))
  6502. + end--;
  6503. + end++;
  6504. + *end = '\0';
  6505. + strcpy(new, src);
  6506. + /* this does from the first space
  6507. + * blasting away any versions stuff in depends
  6508. + while(src &&
  6509. + !isspace(*src) &&
  6510. + *src)
  6511. + *dest++ = *src++;
  6512. + *dest = '\0';
  6513. + */
  6514. +
  6515. + return new;
  6516. +}
  6517. +
  6518. +int line_is_blank(const char *line)
  6519. +{
  6520. + const char *s;
  6521. +
  6522. + for (s = line; *s; s++) {
  6523. + if (!isspace(*s))
  6524. + return 0;
  6525. + }
  6526. + return 1;
  6527. +}
  6528. +
  6529. +void push_error_list(struct errlist ** errors, char * msg){
  6530. + struct errlist *err_lst_tmp;
  6531. +
  6532. +
  6533. + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
  6534. + err_lst_tmp->errmsg=strdup(msg) ;
  6535. + err_lst_tmp->next = *errors;
  6536. + *errors = err_lst_tmp;
  6537. +}
  6538. +
  6539. +
  6540. +void reverse_error_list(struct errlist **errors){
  6541. + struct errlist *result=NULL;
  6542. + struct errlist *current= *errors;
  6543. + struct errlist *next;
  6544. +
  6545. + while ( current != NULL ) {
  6546. + next = current->next;
  6547. + current->next=result;
  6548. + result=current;
  6549. + current=next;
  6550. + }
  6551. + *errors=result;
  6552. +
  6553. +}
  6554. +
  6555. +
  6556. +void free_error_list(struct errlist **errors){
  6557. + struct errlist *current = *errors;
  6558. +
  6559. + while (current != NULL) {
  6560. + free(current->errmsg);
  6561. + current = (*errors)->next;
  6562. + free(*errors);
  6563. + *errors = current;
  6564. + }
  6565. +
  6566. +
  6567. +}
  6568. +
  6569. +
  6570. --- /dev/null
  6571. +++ busybox-1.18.1/archival/libipkg/ipkg_utils.h
  6572. @@ -0,0 +1,29 @@
  6573. +/* ipkg_utils.h - the itsy package management system
  6574. +
  6575. + Steven M. Ayer
  6576. +
  6577. + Copyright (C) 2002 Compaq Computer Corporation
  6578. +
  6579. + This program is free software; you can redistribute it and/or
  6580. + modify it under the terms of the GNU General Public License as
  6581. + published by the Free Software Foundation; either version 2, or (at
  6582. + your option) any later version.
  6583. +
  6584. + This program is distributed in the hope that it will be useful, but
  6585. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6586. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6587. + General Public License for more details.
  6588. +*/
  6589. +
  6590. +#ifndef IPKG_UTILS_H
  6591. +#define IPKG_UTILS_H
  6592. +
  6593. +#include "pkg.h"
  6594. +
  6595. +int get_available_blocks(char * filesystem);
  6596. +char **read_raw_pkgs_from_file(const char *file_name);
  6597. +char **read_raw_pkgs_from_stream(FILE *fp);
  6598. +char *trim_alloc(char * line);
  6599. +int line_is_blank(const char *line);
  6600. +
  6601. +#endif
  6602. --- /dev/null
  6603. +++ busybox-1.18.1/archival/libipkg/libipkg.c
  6604. @@ -0,0 +1,583 @@
  6605. +/* ipkglib.c - the itsy package management system
  6606. +
  6607. + Florina Boor
  6608. +
  6609. + Copyright (C) 2003 kernel concepts
  6610. +
  6611. + This program is free software; you can redistribute it and/or
  6612. + modify it under the terms of the GNU General Public License as
  6613. + published by the Free Software Foundation; either version 2, or (at
  6614. + your option) any later version.
  6615. +
  6616. + This program is distributed in the hope that it will be useful, but
  6617. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6618. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6619. + General Public License for more details.
  6620. +*/
  6621. +
  6622. +#include "ipkg.h"
  6623. +#include "ipkg_includes.h"
  6624. +#include "libipkg.h"
  6625. +
  6626. +#include "args.h"
  6627. +#include "ipkg_conf.h"
  6628. +#include "ipkg_cmd.h"
  6629. +#include "file_util.h"
  6630. +
  6631. +int ipkg_file_what(args_t *args, const char *file, const char* command);
  6632. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  6633. + char *msg);
  6634. +int default_ipkg_list_callback(char *name, char *desc, char *version);
  6635. +int default_ipkg_files_callback(char *desc);
  6636. +int default_ipkg_status_callback(char *desc);
  6637. +char* default_ipkg_response_callback(char *question);
  6638. +
  6639. +
  6640. +ipkg_message_callback ipkg_cb_message = NULL;
  6641. +ipkg_response_callback ipkg_cb_response = NULL;
  6642. +ipkg_status_callback ipkg_cb_status = NULL;
  6643. +ipkg_list_callback ipkg_cb_list = NULL;
  6644. +
  6645. +
  6646. +int
  6647. +ipkg_init (ipkg_message_callback mcall,
  6648. + ipkg_response_callback rcall,
  6649. + args_t * args)
  6650. +{
  6651. + ipkg_cb_message = mcall;
  6652. + ipkg_cb_response = rcall;
  6653. +
  6654. + args_init (args);
  6655. +
  6656. + return 0;
  6657. +}
  6658. +
  6659. +
  6660. +int
  6661. +ipkg_deinit (args_t * args)
  6662. +{
  6663. + args_deinit (args);
  6664. + ipkg_cb_message = NULL;
  6665. + ipkg_cb_response = NULL;
  6666. +
  6667. + /* place other cleanup stuff here */
  6668. +
  6669. + return 0;
  6670. +}
  6671. +
  6672. +
  6673. +int
  6674. +ipkg_packages_list(args_t *args,
  6675. + const char *packages,
  6676. + ipkg_list_callback cblist,
  6677. + void *userdata)
  6678. +{
  6679. + ipkg_cmd_t *cmd;
  6680. + ipkg_conf_t ipkg_conf;
  6681. + int err;
  6682. +
  6683. + err = ipkg_conf_init (&ipkg_conf, args);
  6684. + if (err)
  6685. + {
  6686. + return err;
  6687. + }
  6688. +
  6689. + ipkg_cb_list = cblist;
  6690. + /* we need to do this because of static declarations,
  6691. + * maybe a good idea to change */
  6692. + cmd = ipkg_cmd_find ("list");
  6693. + if (packages)
  6694. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6695. + else
  6696. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6697. + ipkg_cb_list = NULL;
  6698. + ipkg_conf_deinit (&ipkg_conf);
  6699. + return (err);
  6700. +}
  6701. +
  6702. +
  6703. +int
  6704. +ipkg_packages_status(args_t *args,
  6705. + const char *packages,
  6706. + ipkg_status_callback cbstatus,
  6707. + void *userdata)
  6708. +{
  6709. + ipkg_cmd_t *cmd;
  6710. + ipkg_conf_t ipkg_conf;
  6711. + int err;
  6712. +
  6713. + err = ipkg_conf_init (&ipkg_conf, args);
  6714. + if (err)
  6715. + {
  6716. + return err;
  6717. + }
  6718. +
  6719. + ipkg_cb_status = cbstatus;
  6720. +
  6721. + /* we need to do this because of static declarations,
  6722. + * maybe a good idea to change */
  6723. + cmd = ipkg_cmd_find ("status");
  6724. + if (packages)
  6725. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6726. + else
  6727. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6728. +
  6729. + ipkg_cb_status = NULL;
  6730. + ipkg_conf_deinit (&ipkg_conf);
  6731. + return (err);
  6732. +}
  6733. +
  6734. +
  6735. +int
  6736. +ipkg_packages_info(args_t *args,
  6737. + const char *packages,
  6738. + ipkg_status_callback cbstatus,
  6739. + void *userdata)
  6740. +{
  6741. + ipkg_cmd_t *cmd;
  6742. + ipkg_conf_t ipkg_conf;
  6743. + int err;
  6744. +
  6745. + err = ipkg_conf_init (&ipkg_conf, args);
  6746. + if (err)
  6747. + {
  6748. + return err;
  6749. + }
  6750. +
  6751. + ipkg_cb_status = cbstatus;
  6752. +
  6753. + /* we need to do this because of static declarations,
  6754. + * maybe a good idea to change */
  6755. + cmd = ipkg_cmd_find ("info");
  6756. + if (packages)
  6757. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6758. + else
  6759. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6760. +
  6761. + ipkg_cb_status = NULL;
  6762. + ipkg_conf_deinit (&ipkg_conf);
  6763. + return (err);
  6764. +}
  6765. +
  6766. +
  6767. +int
  6768. +ipkg_packages_install (args_t * args, const char *name)
  6769. +{
  6770. + ipkg_cmd_t *cmd;
  6771. + ipkg_conf_t ipkg_conf;
  6772. + int err;
  6773. +
  6774. + /* this error should be handled in application */
  6775. + if (!name || !strlen (name))
  6776. + return (-1);
  6777. +
  6778. + err = ipkg_conf_init (&ipkg_conf, args);
  6779. + if (err)
  6780. + {
  6781. + return err;
  6782. + }
  6783. +
  6784. + /* we need to do this because of static declarations,
  6785. + * maybe a good idea to change */
  6786. + cmd = ipkg_cmd_find ("install");
  6787. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6788. +
  6789. + ipkg_conf_deinit(&ipkg_conf);
  6790. + return (err);
  6791. +}
  6792. +
  6793. +
  6794. +int
  6795. +ipkg_packages_remove(args_t *args, const char *name, int purge)
  6796. +{
  6797. + ipkg_cmd_t *cmd;
  6798. + ipkg_conf_t ipkg_conf;
  6799. + int err;
  6800. +
  6801. + /* this error should be handled in application */
  6802. + if (!name || !strlen (name))
  6803. + return (-1);
  6804. +
  6805. + err = ipkg_conf_init (&ipkg_conf, args);
  6806. + if (err)
  6807. + {
  6808. + return err;
  6809. + }
  6810. +
  6811. + /* we need to do this because of static declarations,
  6812. + * maybe a good idea to change */
  6813. + if (purge)
  6814. + cmd = ipkg_cmd_find ("purge");
  6815. + else
  6816. + cmd = ipkg_cmd_find ("remove");
  6817. +
  6818. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6819. +
  6820. + ipkg_conf_deinit(&ipkg_conf);
  6821. + return (err);
  6822. +}
  6823. +
  6824. +
  6825. +int
  6826. +ipkg_lists_update(args_t *args)
  6827. +{
  6828. + ipkg_cmd_t *cmd;
  6829. + ipkg_conf_t ipkg_conf;
  6830. + int err;
  6831. +
  6832. + err = ipkg_conf_init (&ipkg_conf, args);
  6833. + if (err)
  6834. + {
  6835. + return err;
  6836. + }
  6837. +
  6838. + /* we need to do this because of static declarations,
  6839. + * maybe a good idea to change */
  6840. + cmd = ipkg_cmd_find ("update");
  6841. +
  6842. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6843. +
  6844. + ipkg_conf_deinit(&ipkg_conf);
  6845. + return (err);
  6846. +}
  6847. +
  6848. +
  6849. +int
  6850. +ipkg_packages_upgrade(args_t *args)
  6851. +{
  6852. + ipkg_cmd_t *cmd;
  6853. + ipkg_conf_t ipkg_conf;
  6854. + int err;
  6855. +
  6856. + err = ipkg_conf_init (&ipkg_conf, args);
  6857. + if (err)
  6858. + {
  6859. + return err;
  6860. + }
  6861. +
  6862. + /* we need to do this because of static declarations,
  6863. + * maybe a good idea to change */
  6864. + cmd = ipkg_cmd_find ("upgrade");
  6865. +
  6866. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6867. +
  6868. + ipkg_conf_deinit(&ipkg_conf);
  6869. + return (err);
  6870. +}
  6871. +
  6872. +
  6873. +int
  6874. +ipkg_packages_download (args_t * args, const char *name)
  6875. +{
  6876. + ipkg_cmd_t *cmd;
  6877. + ipkg_conf_t ipkg_conf;
  6878. + int err;
  6879. +
  6880. + /* this error should be handled in application */
  6881. + if (!name || !strlen (name))
  6882. + return (-1);
  6883. +
  6884. + err = ipkg_conf_init (&ipkg_conf, args);
  6885. + if (err)
  6886. + {
  6887. + return err;
  6888. + }
  6889. +
  6890. + /* we need to do this because of static declarations,
  6891. + * maybe a good idea to change */
  6892. + cmd = ipkg_cmd_find ("download");
  6893. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6894. +
  6895. + ipkg_conf_deinit(&ipkg_conf);
  6896. + return (err);
  6897. +}
  6898. +
  6899. +
  6900. +int
  6901. +ipkg_package_files(args_t *args,
  6902. + const char *name,
  6903. + ipkg_list_callback cblist,
  6904. + void *userdata)
  6905. +{
  6906. + ipkg_cmd_t *cmd;
  6907. + ipkg_conf_t ipkg_conf;
  6908. + int err;
  6909. +
  6910. + /* this error should be handled in application */
  6911. + if (!name || !strlen (name))
  6912. + return (-1);
  6913. +
  6914. + err = ipkg_conf_init (&ipkg_conf, args);
  6915. + if (err)
  6916. + {
  6917. + return err;
  6918. + }
  6919. +
  6920. + ipkg_cb_list = cblist;
  6921. +
  6922. + /* we need to do this because of static declarations,
  6923. + * maybe a good idea to change */
  6924. + cmd = ipkg_cmd_find ("files");
  6925. +
  6926. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
  6927. +
  6928. + ipkg_cb_list = NULL;
  6929. + ipkg_conf_deinit(&ipkg_conf);
  6930. + return (err);
  6931. +}
  6932. +
  6933. +
  6934. +int
  6935. +ipkg_file_search(args_t *args,
  6936. + const char *file,
  6937. + ipkg_list_callback cblist,
  6938. + void *userdata)
  6939. +{
  6940. + ipkg_cmd_t *cmd;
  6941. + ipkg_conf_t ipkg_conf;
  6942. + int err;
  6943. +
  6944. + /* this error should be handled in application */
  6945. + if (!file || !strlen (file))
  6946. + return (-1);
  6947. +
  6948. + err = ipkg_conf_init (&ipkg_conf, args);
  6949. + if (err)
  6950. + {
  6951. + return err;
  6952. + }
  6953. +
  6954. + ipkg_cb_list = cblist;
  6955. +
  6956. + /* we need to do this because of static declarations,
  6957. + * maybe a good idea to change */
  6958. + cmd = ipkg_cmd_find ("search");
  6959. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
  6960. +
  6961. + ipkg_cb_list = NULL;
  6962. + ipkg_conf_deinit(&ipkg_conf);
  6963. + return(err);
  6964. +}
  6965. +
  6966. +
  6967. +int
  6968. +ipkg_file_what(args_t *args, const char *file, const char* command)
  6969. +{
  6970. + ipkg_cmd_t *cmd;
  6971. + ipkg_conf_t ipkg_conf;
  6972. + int err;
  6973. +
  6974. + /* this error should be handled in application */
  6975. + if (!file || !strlen (file))
  6976. + return (-1);
  6977. +
  6978. + err = ipkg_conf_init (&ipkg_conf, args);
  6979. + if (err)
  6980. + {
  6981. + return err;
  6982. + }
  6983. +
  6984. + /* we need to do this because of static declarations,
  6985. + * maybe a good idea to change */
  6986. + cmd = ipkg_cmd_find (command);
  6987. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
  6988. +
  6989. + ipkg_conf_deinit(&ipkg_conf);
  6990. + return(err);
  6991. +}
  6992. +
  6993. +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
  6994. +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
  6995. +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
  6996. +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
  6997. +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
  6998. +
  6999. +
  7000. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  7001. + char *msg)
  7002. +{
  7003. + if (conf && (conf->verbosity < level)) {
  7004. + return 0;
  7005. + } else {
  7006. + if ( level == IPKG_ERROR )
  7007. + push_error_list(&error_list, msg);
  7008. + else
  7009. + printf(msg);
  7010. + }
  7011. + return 0;
  7012. +}
  7013. +
  7014. +int default_ipkg_list_callback(char *name, char *desc, char *version)
  7015. +{
  7016. + if (desc)
  7017. + printf("%s - %s - %s\n", name, version, desc);
  7018. + else
  7019. + printf("%s - %s\n", name, version);
  7020. + return 0;
  7021. +}
  7022. +
  7023. +int default_ipkg_files_callback(char *desc)
  7024. +{
  7025. + if (desc)
  7026. + printf("%s\n", desc);
  7027. + return 0;
  7028. +}
  7029. +
  7030. +int default_ipkg_status_callback(char *desc)
  7031. +{
  7032. + printf("%s\n", desc);
  7033. + return 0;
  7034. +}
  7035. +
  7036. +char* default_ipkg_response_callback(char *question)
  7037. +{
  7038. + char *response = NULL;
  7039. + printf(question);
  7040. + fflush(stdout);
  7041. + do {
  7042. + response = (char *)file_read_line_alloc(stdin);
  7043. + } while (response == NULL);
  7044. + return response;
  7045. +}
  7046. +
  7047. +/* This is used for backward compatibility */
  7048. +int
  7049. +ipkg_op (int argc, char *argv[])
  7050. +{
  7051. + int err, optind_;
  7052. + args_t args;
  7053. + char *cmd_name;
  7054. + ipkg_cmd_t *cmd;
  7055. + ipkg_conf_t ipkg_conf;
  7056. + const char *message = "ipkg must have one sub-command argument";
  7057. + FILE *f;
  7058. + struct mntent *mnt;
  7059. + int remountroot;
  7060. +
  7061. + args_init (&args);
  7062. +
  7063. + optind_ = args_parse (&args, argc, argv);
  7064. + if (optind_ == argc || optind_ < 0)
  7065. + {
  7066. + args_usage(message);
  7067. + }
  7068. +
  7069. + cmd_name = argv[optind_++];
  7070. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  7071. + read anything from there.
  7072. +*/
  7073. + if ( !strcmp(cmd_name,"print-architecture") ||
  7074. + !strcmp(cmd_name,"print_architecture") ||
  7075. + !strcmp(cmd_name,"print-installation-architecture") ||
  7076. + !strcmp(cmd_name,"print_installation_architecture") )
  7077. + args.nocheckfordirorfile = 1;
  7078. +
  7079. +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
  7080. + read anything from there.
  7081. +*/
  7082. + if ( !strcmp(cmd_name,"flag") ||
  7083. + !strcmp(cmd_name,"configure") ||
  7084. + !strcmp(cmd_name,"remove") ||
  7085. + !strcmp(cmd_name,"files") ||
  7086. + !strcmp(cmd_name,"search") ||
  7087. + !strcmp(cmd_name,"compare_versions") ||
  7088. + !strcmp(cmd_name,"compare-versions") ||
  7089. + !strcmp(cmd_name,"list_installed") ||
  7090. + !strcmp(cmd_name,"list-installed") ||
  7091. + !strcmp(cmd_name,"status") )
  7092. + args.noreadfeedsfile = 1;
  7093. +
  7094. +
  7095. +
  7096. +
  7097. + err = ipkg_conf_init (&ipkg_conf, &args);
  7098. + if (err)
  7099. + {
  7100. + return err;
  7101. + }
  7102. +
  7103. + args_deinit (&args);
  7104. +
  7105. + ipkg_cb_message = default_ipkg_message_callback;
  7106. + ipkg_cb_response = default_ipkg_response_callback;
  7107. + ipkg_cb_status = (ipkg_status_callback)default_ipkg_status_callback;
  7108. + if ( strcmp(cmd_name, "files")==0)
  7109. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_files_callback;
  7110. + else
  7111. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_list_callback;
  7112. +
  7113. + cmd = ipkg_cmd_find (cmd_name);
  7114. + if (cmd == NULL)
  7115. + {
  7116. + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
  7117. + cmd_name);
  7118. + args_usage (NULL);
  7119. + }
  7120. +
  7121. + if (cmd->requires_args && optind_ == argc)
  7122. + {
  7123. + fprintf (stderr,
  7124. + "%s: the ``%s'' command requires at least one argument\n",
  7125. + __FUNCTION__, cmd_name);
  7126. + args_usage (NULL);
  7127. + }
  7128. +
  7129. + remountroot = 0;
  7130. + /* check if /dev/root is mounted read-only */
  7131. + if ((f = setmntent("/proc/mounts", "r")) == NULL)
  7132. + fprintf (stderr, "Checking /proc/mounts failed\n");
  7133. +
  7134. + while ((mnt = getmntent(f)) != NULL) {
  7135. + if (strcmp(mnt->mnt_fsname, "/dev/root") == 0 &&
  7136. + hasmntopt(mnt, MNTOPT_RO) != NULL) {
  7137. + remountroot = 1;
  7138. + }
  7139. + }
  7140. +
  7141. + endmntent(f);
  7142. +
  7143. + if (remountroot) {
  7144. + if ( !strcmp(cmd_name,"install") ||
  7145. + !strcmp(cmd_name,"update") ||
  7146. + !strcmp(cmd_name,"upgrade") ||
  7147. + !strcmp(cmd_name,"flag") ||
  7148. + !strcmp(cmd_name,"configure") ||
  7149. + !strcmp(cmd_name,"remove") ) {
  7150. + /* mount rootfs read-write */
  7151. + if (mount("","/",0,MS_REMOUNT,0)<0)
  7152. + fprintf (stderr, "Mounting rootfs read-write failed\n");
  7153. + }
  7154. + }
  7155. +
  7156. + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind_, (const char **) (argv + optind_), NULL);
  7157. +
  7158. + ipkg_conf_deinit (&ipkg_conf);
  7159. +
  7160. + if (remountroot) {
  7161. + if ( !strcmp(cmd_name,"install") ||
  7162. + !strcmp(cmd_name,"update") ||
  7163. + !strcmp(cmd_name,"upgrade") ||
  7164. + !strcmp(cmd_name,"flag") ||
  7165. + !strcmp(cmd_name,"configure") ||
  7166. + !strcmp(cmd_name,"remove") ) {
  7167. + sync();
  7168. + /* mount rootfs read-only */
  7169. + if (mount("","/",0,MS_REMOUNT|MS_RDONLY,0)<0)
  7170. + fprintf (stderr, "Mounting rootfs read-only failed\n");
  7171. + }
  7172. + }
  7173. +
  7174. + /* check if cfgfs exists */
  7175. + if (access("/sbin/cfgfs", X_OK) == 0) {
  7176. + if ( !strcmp(cmd_name,"install") ||
  7177. + !strcmp(cmd_name,"update") ||
  7178. + !strcmp(cmd_name,"upgrade")) {
  7179. + if (system("cfgfs status -q") != 0) {
  7180. + fprintf (stdout, "Updates in /etc, please review changes\n");
  7181. + fprintf (stdout, "You can check via cfgfs status\n");
  7182. + }
  7183. + }
  7184. + }
  7185. +
  7186. + return err;
  7187. +}
  7188. --- /dev/null
  7189. +++ busybox-1.18.1/archival/libipkg/libipkg.h
  7190. @@ -0,0 +1,78 @@
  7191. +/* ipkglib.h - the itsy package management system
  7192. +
  7193. + Florian Boor <florian.boor@kernelconcepts.de>
  7194. +
  7195. + This program is free software; you can redistribute it and/or
  7196. + modify it under the terms of the GNU General Public License as
  7197. + published by the Free Software Foundation; either version 2, or (at
  7198. + your option) any later version.
  7199. +
  7200. + This program is distributed in the hope that it will be useful, but
  7201. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7202. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7203. + General Public License for more details.
  7204. +*/
  7205. +
  7206. +#ifndef IPKGLIB_H
  7207. +#define IPKGLIB_H
  7208. +
  7209. +#include "ipkg_conf.h"
  7210. +#include "ipkg_message.h"
  7211. +
  7212. +#include "args.h"
  7213. +#include "pkg.h"
  7214. +
  7215. +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
  7216. + char *msg);
  7217. +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
  7218. + pkg_state_status_t status, void *userdata);
  7219. +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
  7220. + void *userdata);
  7221. +typedef char* (*ipkg_response_callback)(char *question);
  7222. +
  7223. +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
  7224. +extern int ipkg_init (ipkg_message_callback mcall,
  7225. + ipkg_response_callback rcall,
  7226. + args_t * args);
  7227. +
  7228. +extern int ipkg_deinit (args_t *args);
  7229. +extern int ipkg_packages_list(args_t *args,
  7230. + const char *packages,
  7231. + ipkg_list_callback cblist,
  7232. + void *userdata);
  7233. +extern int ipkg_packages_status(args_t *args,
  7234. + const char *packages,
  7235. + ipkg_status_callback cbstatus,
  7236. + void *userdata);
  7237. +extern int ipkg_packages_info(args_t *args,
  7238. + const char *packages,
  7239. + ipkg_status_callback cbstatus,
  7240. + void *userdata);
  7241. +extern int ipkg_packages_install(args_t *args, const char *name);
  7242. +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
  7243. +extern int ipkg_lists_update(args_t *args);
  7244. +extern int ipkg_packages_upgrade(args_t *args);
  7245. +extern int ipkg_packages_download(args_t *args, const char *name);
  7246. +extern int ipkg_package_files(args_t *args,
  7247. + const char *name,
  7248. + ipkg_list_callback cblist,
  7249. + void *userdata);
  7250. +extern int ipkg_file_search(args_t *args,
  7251. + const char *file,
  7252. + ipkg_list_callback cblist,
  7253. + void *userdata);
  7254. +extern int ipkg_package_whatdepends(args_t *args, const char *file);
  7255. +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
  7256. +extern int ipkg_package_whatprovides(args_t *args, const char *file);
  7257. +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
  7258. +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
  7259. +
  7260. +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
  7261. +extern ipkg_response_callback ipkg_cb_response;
  7262. +extern ipkg_status_callback ipkg_cb_status;
  7263. +extern ipkg_list_callback ipkg_cb_list;
  7264. +extern void push_error_list(struct errlist **errors,char * msg);
  7265. +extern void reverse_error_list(struct errlist **errors);
  7266. +extern void free_error_list(struct errlist **errors);
  7267. +
  7268. +#endif
  7269. --- /dev/null
  7270. +++ busybox-1.18.1/archival/libipkg/nv_pair.c
  7271. @@ -0,0 +1,40 @@
  7272. +/* nv_pair.c - the itsy package management system
  7273. +
  7274. + Carl D. Worth
  7275. +
  7276. + Copyright (C) 2001 University of Southern California
  7277. +
  7278. + This program is free software; you can redistribute it and/or
  7279. + modify it under the terms of the GNU General Public License as
  7280. + published by the Free Software Foundation; either version 2, or (at
  7281. + your option) any later version.
  7282. +
  7283. + This program is distributed in the hope that it will be useful, but
  7284. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7285. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7286. + General Public License for more details.
  7287. +*/
  7288. +
  7289. +#include "ipkg.h"
  7290. +
  7291. +#include "nv_pair.h"
  7292. +#include "str_util.h"
  7293. +
  7294. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
  7295. +{
  7296. + nv_pair->name = str_dup_safe(name);
  7297. + nv_pair->value = str_dup_safe(value);
  7298. +
  7299. + return 0;
  7300. +}
  7301. +
  7302. +void nv_pair_deinit(nv_pair_t *nv_pair)
  7303. +{
  7304. + free(nv_pair->name);
  7305. + nv_pair->name = NULL;
  7306. +
  7307. + free(nv_pair->value);
  7308. + nv_pair->value = NULL;
  7309. +}
  7310. +
  7311. +
  7312. --- /dev/null
  7313. +++ busybox-1.18.1/archival/libipkg/nv_pair.h
  7314. @@ -0,0 +1,32 @@
  7315. +/* nv_pair.h - the itsy package management system
  7316. +
  7317. + Carl D. Worth
  7318. +
  7319. + Copyright (C) 2001 University of Southern California
  7320. +
  7321. + This program is free software; you can redistribute it and/or
  7322. + modify it under the terms of the GNU General Public License as
  7323. + published by the Free Software Foundation; either version 2, or (at
  7324. + your option) any later version.
  7325. +
  7326. + This program is distributed in the hope that it will be useful, but
  7327. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7328. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7329. + General Public License for more details.
  7330. +*/
  7331. +
  7332. +#ifndef NV_PAIR_H
  7333. +#define NV_PAIR_H
  7334. +
  7335. +typedef struct nv_pair nv_pair_t;
  7336. +struct nv_pair
  7337. +{
  7338. + char *name;
  7339. + char *value;
  7340. +};
  7341. +
  7342. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
  7343. +void nv_pair_deinit(nv_pair_t *nv_pair);
  7344. +
  7345. +#endif
  7346. +
  7347. --- /dev/null
  7348. +++ busybox-1.18.1/archival/libipkg/nv_pair_list.c
  7349. @@ -0,0 +1,98 @@
  7350. +/* nv_pair_list.c - the itsy package management system
  7351. +
  7352. + Carl D. Worth
  7353. +
  7354. + Copyright (C) 2001 University of Southern California
  7355. +
  7356. + This program is free software; you can redistribute it and/or
  7357. + modify it under the terms of the GNU General Public License as
  7358. + published by the Free Software Foundation; either version 2, or (at
  7359. + your option) any later version.
  7360. +
  7361. + This program is distributed in the hope that it will be useful, but
  7362. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7363. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7364. + General Public License for more details.
  7365. +*/
  7366. +
  7367. +#include "ipkg.h"
  7368. +
  7369. +#include "nv_pair.h"
  7370. +#include "void_list.h"
  7371. +#include "nv_pair_list.h"
  7372. +
  7373. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
  7374. +{
  7375. + return void_list_elt_init((void_list_elt_t *) elt, data);
  7376. +}
  7377. +
  7378. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
  7379. +{
  7380. + void_list_elt_deinit((void_list_elt_t *) elt);
  7381. +}
  7382. +
  7383. +int nv_pair_list_init(nv_pair_list_t *list)
  7384. +{
  7385. + return void_list_init((void_list_t *) list);
  7386. +}
  7387. +
  7388. +void nv_pair_list_deinit(nv_pair_list_t *list)
  7389. +{
  7390. + nv_pair_list_elt_t *iter;
  7391. + nv_pair_t *nv_pair;
  7392. +
  7393. + for (iter = list->head; iter; iter = iter->next) {
  7394. + nv_pair = iter->data;
  7395. + nv_pair_deinit(nv_pair);
  7396. +
  7397. + /* malloced in nv_pair_list_append */
  7398. + free(nv_pair);
  7399. + iter->data = NULL;
  7400. + }
  7401. + void_list_deinit((void_list_t *) list);
  7402. +}
  7403. +
  7404. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
  7405. +{
  7406. + int err;
  7407. +
  7408. + /* freed in nv_pair_list_deinit */
  7409. + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
  7410. +
  7411. + if (nv_pair == NULL) {
  7412. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7413. + return NULL;
  7414. + }
  7415. + nv_pair_init(nv_pair, name, value);
  7416. +
  7417. + err = void_list_append((void_list_t *) list, nv_pair);
  7418. + if (err) {
  7419. + return NULL;
  7420. + }
  7421. +
  7422. + return nv_pair;
  7423. +}
  7424. +
  7425. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
  7426. +{
  7427. + return void_list_push((void_list_t *) list, data);
  7428. +}
  7429. +
  7430. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
  7431. +{
  7432. + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
  7433. +}
  7434. +
  7435. +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
  7436. +{
  7437. + nv_pair_list_elt_t *iter;
  7438. + nv_pair_t *nv_pair;
  7439. +
  7440. + for (iter = list->head; iter; iter = iter->next) {
  7441. + nv_pair = iter->data;
  7442. + if (strcmp(nv_pair->name, name) == 0) {
  7443. + return nv_pair->value;
  7444. + }
  7445. + }
  7446. + return NULL;
  7447. +}
  7448. --- /dev/null
  7449. +++ busybox-1.18.1/archival/libipkg/nv_pair_list.h
  7450. @@ -0,0 +1,60 @@
  7451. +/* nv_pair_list.h - the itsy package management system
  7452. +
  7453. + Carl D. Worth
  7454. +
  7455. + Copyright (C) 2001 University of Southern California
  7456. +
  7457. + This program is free software; you can redistribute it and/or
  7458. + modify it under the terms of the GNU General Public License as
  7459. + published by the Free Software Foundation; either version 2, or (at
  7460. + your option) any later version.
  7461. +
  7462. + This program is distributed in the hope that it will be useful, but
  7463. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7464. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7465. + General Public License for more details.
  7466. +*/
  7467. +
  7468. +#ifndef NV_PAIR_LIST_H
  7469. +#define NV_PAIR_LIST_H
  7470. +
  7471. +#include "nv_pair.h"
  7472. +#include "void_list.h"
  7473. +
  7474. +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
  7475. +struct nv_pair_list_elt
  7476. +{
  7477. + nv_pair_list_elt_t *next;
  7478. + nv_pair_t *data;
  7479. +};
  7480. +
  7481. +typedef struct nv_pair_list nv_pair_list_t;
  7482. +struct nv_pair_list
  7483. +{
  7484. + nv_pair_list_elt_t pre_head;
  7485. + nv_pair_list_elt_t *head;
  7486. + nv_pair_list_elt_t *tail;
  7487. +};
  7488. +
  7489. +static inline int nv_pair_list_empty(nv_pair_list_t *list)
  7490. +{
  7491. + if (list->head == NULL)
  7492. + return 1;
  7493. + else
  7494. + return 0;
  7495. +}
  7496. +
  7497. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
  7498. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
  7499. +
  7500. +int nv_pair_list_init(nv_pair_list_t *list);
  7501. +void nv_pair_list_deinit(nv_pair_list_t *list);
  7502. +
  7503. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
  7504. + const char *name, const char *value);
  7505. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
  7506. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
  7507. +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
  7508. +
  7509. +#endif
  7510. +
  7511. --- /dev/null
  7512. +++ busybox-1.18.1/archival/libipkg/pkg.c
  7513. @@ -0,0 +1,1757 @@
  7514. +/* pkg.c - the itsy package management system
  7515. +
  7516. + Carl D. Worth
  7517. +
  7518. + Copyright (C) 2001 University of Southern California
  7519. +
  7520. + This program is free software; you can redistribute it and/or
  7521. + modify it under the terms of the GNU General Public License as
  7522. + published by the Free Software Foundation; either version 2, or (at
  7523. + your option) any later version.
  7524. +
  7525. + This program is distributed in the hope that it will be useful, but
  7526. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7527. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7528. + General Public License for more details.
  7529. +*/
  7530. +
  7531. +#include "ipkg.h"
  7532. +#include <ctype.h>
  7533. +#include <string.h>
  7534. +#include <errno.h>
  7535. +
  7536. +#include "pkg.h"
  7537. +
  7538. +#include "pkg_parse.h"
  7539. +#include "pkg_extract.h"
  7540. +#include "ipkg_message.h"
  7541. +#include "ipkg_utils.h"
  7542. +
  7543. +#include "sprintf_alloc.h"
  7544. +#include "file_util.h"
  7545. +#include "str_util.h"
  7546. +#include "xsystem.h"
  7547. +#include "ipkg_conf.h"
  7548. +
  7549. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname);
  7550. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_);
  7551. +
  7552. +typedef struct enum_map enum_map_t;
  7553. +struct enum_map
  7554. +{
  7555. + int value;
  7556. + const char *str;
  7557. +};
  7558. +
  7559. +static const enum_map_t pkg_state_want_map[] = {
  7560. + { SW_UNKNOWN, "unknown"},
  7561. + { SW_INSTALL, "install"},
  7562. + { SW_DEINSTALL, "deinstall"},
  7563. + { SW_PURGE, "purge"}
  7564. +};
  7565. +
  7566. +static const enum_map_t pkg_state_flag_map[] = {
  7567. + { SF_OK, "ok"},
  7568. + { SF_REINSTREQ, "reinstreq"},
  7569. + { SF_HOLD, "hold"},
  7570. + { SF_REPLACE, "replace"},
  7571. + { SF_NOPRUNE, "noprune"},
  7572. + { SF_PREFER, "prefer"},
  7573. + { SF_OBSOLETE, "obsolete"},
  7574. + { SF_USER, "user"},
  7575. +};
  7576. +
  7577. +static const enum_map_t pkg_state_status_map[] = {
  7578. + { SS_NOT_INSTALLED, "not-installed" },
  7579. + { SS_UNPACKED, "unpacked" },
  7580. + { SS_HALF_CONFIGURED, "half-configured" },
  7581. + { SS_INSTALLED, "installed" },
  7582. + { SS_HALF_INSTALLED, "half-installed" },
  7583. + { SS_CONFIG_FILES, "config-files" },
  7584. + { SS_POST_INST_FAILED, "post-inst-failed" },
  7585. + { SS_REMOVAL_FAILED, "removal-failed" }
  7586. +};
  7587. +
  7588. +static int verrevcmp(const char *val, const char *ref);
  7589. +
  7590. +
  7591. +pkg_t *pkg_new(void)
  7592. +{
  7593. + pkg_t *pkg;
  7594. +
  7595. + pkg = malloc(sizeof(pkg_t));
  7596. + if (pkg == NULL) {
  7597. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7598. + return NULL;
  7599. + }
  7600. +
  7601. + pkg_init(pkg);
  7602. +
  7603. + return pkg;
  7604. +}
  7605. +
  7606. +int pkg_init(pkg_t *pkg)
  7607. +{
  7608. + memset(pkg, 0, sizeof(pkg_t));
  7609. + pkg->name = NULL;
  7610. + pkg->epoch = 0;
  7611. + pkg->version = NULL;
  7612. + pkg->revision = NULL;
  7613. + pkg->familiar_revision = NULL;
  7614. + pkg->dest = NULL;
  7615. + pkg->src = NULL;
  7616. + pkg->architecture = NULL;
  7617. + pkg->maintainer = NULL;
  7618. + pkg->section = NULL;
  7619. + pkg->description = NULL;
  7620. + pkg->state_want = SW_UNKNOWN;
  7621. + pkg->state_flag = SF_OK;
  7622. + pkg->state_status = SS_NOT_INSTALLED;
  7623. + pkg->depends_str = NULL;
  7624. + pkg->provides_str = NULL;
  7625. + pkg->depends_count = 0;
  7626. + pkg->depends = NULL;
  7627. + pkg->suggests_str = NULL;
  7628. + pkg->recommends_str = NULL;
  7629. + pkg->suggests_count = 0;
  7630. + pkg->recommends_count = 0;
  7631. +
  7632. + /* Abhaya: added init for conflicts fields */
  7633. + pkg->conflicts = NULL;
  7634. + pkg->conflicts_count = 0;
  7635. +
  7636. + /* added for replaces. Jamey 7/23/2002 */
  7637. + pkg->replaces = NULL;
  7638. + pkg->replaces_count = 0;
  7639. +
  7640. + pkg->pre_depends_count = 0;
  7641. + pkg->pre_depends_str = NULL;
  7642. + pkg->provides_count = 0;
  7643. + pkg->provides = NULL;
  7644. + pkg->filename = NULL;
  7645. + pkg->local_filename = NULL;
  7646. + pkg->tmp_unpack_dir = NULL;
  7647. + pkg->md5sum = NULL;
  7648. + pkg->size = NULL;
  7649. + pkg->installed_size = NULL;
  7650. + pkg->priority = NULL;
  7651. + pkg->source = NULL;
  7652. + conffile_list_init(&pkg->conffiles);
  7653. + pkg->installed_files = NULL;
  7654. + pkg->installed_files_ref_cnt = 0;
  7655. + pkg->essential = 0;
  7656. + pkg->provided_by_hand = 0;
  7657. +
  7658. + return 0;
  7659. +}
  7660. +
  7661. +void pkg_deinit(pkg_t *pkg)
  7662. +{
  7663. + free(pkg->name);
  7664. + pkg->name = NULL;
  7665. + pkg->epoch = 0;
  7666. + free(pkg->version);
  7667. + pkg->version = NULL;
  7668. + /* revision and familiar_revision share storage with version, so
  7669. + don't free */
  7670. + pkg->revision = NULL;
  7671. + pkg->familiar_revision = NULL;
  7672. + /* owned by ipkg_conf_t */
  7673. + pkg->dest = NULL;
  7674. + /* owned by ipkg_conf_t */
  7675. + pkg->src = NULL;
  7676. + free(pkg->architecture);
  7677. + pkg->architecture = NULL;
  7678. + free(pkg->maintainer);
  7679. + pkg->maintainer = NULL;
  7680. + free(pkg->section);
  7681. + pkg->section = NULL;
  7682. + free(pkg->description);
  7683. + pkg->description = NULL;
  7684. + pkg->state_want = SW_UNKNOWN;
  7685. + pkg->state_flag = SF_OK;
  7686. + pkg->state_status = SS_NOT_INSTALLED;
  7687. + free(pkg->depends_str);
  7688. + pkg->depends_str = NULL;
  7689. + free(pkg->provides_str);
  7690. + pkg->provides_str = NULL;
  7691. + pkg->depends_count = 0;
  7692. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
  7693. + pkg->pre_depends_count = 0;
  7694. + free(pkg->pre_depends_str);
  7695. + pkg->pre_depends_str = NULL;
  7696. + pkg->provides_count = 0;
  7697. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
  7698. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
  7699. + free(pkg->filename);
  7700. + pkg->filename = NULL;
  7701. + free(pkg->local_filename);
  7702. + pkg->local_filename = NULL;
  7703. + /* CLEANUP: It'd be nice to pullin the cleanup function from
  7704. + ipkg_install.c here. See comment in
  7705. + ipkg_install.c:cleanup_temporary_files */
  7706. + free(pkg->tmp_unpack_dir);
  7707. + pkg->tmp_unpack_dir = NULL;
  7708. + free(pkg->md5sum);
  7709. + pkg->md5sum = NULL;
  7710. + free(pkg->size);
  7711. + pkg->size = NULL;
  7712. + free(pkg->installed_size);
  7713. + pkg->installed_size = NULL;
  7714. + free(pkg->priority);
  7715. + pkg->priority = NULL;
  7716. + free(pkg->source);
  7717. + pkg->source = NULL;
  7718. + conffile_list_deinit(&pkg->conffiles);
  7719. + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
  7720. + since if they are calling deinit, they should know. Maybe do an
  7721. + assertion here instead? */
  7722. + pkg->installed_files_ref_cnt = 1;
  7723. + pkg_free_installed_files(pkg);
  7724. + pkg->essential = 0;
  7725. +}
  7726. +
  7727. +int pkg_init_from_file(pkg_t *pkg, const char *filename)
  7728. +{
  7729. + int err;
  7730. + char **raw;
  7731. + FILE *control_file;
  7732. +
  7733. + err = pkg_init(pkg);
  7734. + if (err) { return err; }
  7735. +
  7736. + pkg->local_filename = strdup(filename);
  7737. +
  7738. + control_file = tmpfile();
  7739. + err = pkg_extract_control_file_to_stream(pkg, control_file);
  7740. + if (err) { return err; }
  7741. +
  7742. + rewind(control_file);
  7743. + raw = read_raw_pkgs_from_stream(control_file);
  7744. + pkg_parse_raw(pkg, &raw, NULL, NULL);
  7745. +
  7746. + fclose(control_file);
  7747. +
  7748. + return 0;
  7749. +}
  7750. +
  7751. +/* Merge any new information in newpkg into oldpkg */
  7752. +/* XXX: CLEANUP: This function shouldn't actually modify anything in
  7753. + newpkg, but should leave it usable. This rework is so that
  7754. + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
  7755. +/*
  7756. + * uh, i thought that i had originally written this so that it took
  7757. + * two pkgs and returned a new one? we can do that again... -sma
  7758. + */
  7759. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
  7760. +{
  7761. + if (oldpkg == newpkg) {
  7762. + return 0;
  7763. + }
  7764. +
  7765. + if (!oldpkg->src)
  7766. + oldpkg->src = newpkg->src;
  7767. + if (!oldpkg->dest)
  7768. + oldpkg->dest = newpkg->dest;
  7769. + if (!oldpkg->architecture)
  7770. + oldpkg->architecture = str_dup_safe(newpkg->architecture);
  7771. + if (!oldpkg->arch_priority)
  7772. + oldpkg->arch_priority = newpkg->arch_priority;
  7773. + if (!oldpkg->section)
  7774. + oldpkg->section = str_dup_safe(newpkg->section);
  7775. + if(!oldpkg->maintainer)
  7776. + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
  7777. + if(!oldpkg->description)
  7778. + oldpkg->description = str_dup_safe(newpkg->description);
  7779. + if (set_status) {
  7780. + /* merge the state_flags from the new package */
  7781. + oldpkg->state_want = newpkg->state_want;
  7782. + oldpkg->state_status = newpkg->state_status;
  7783. + oldpkg->state_flag = newpkg->state_flag;
  7784. + } else {
  7785. + if (oldpkg->state_want == SW_UNKNOWN)
  7786. + oldpkg->state_want = newpkg->state_want;
  7787. + if (oldpkg->state_status == SS_NOT_INSTALLED)
  7788. + oldpkg->state_status = newpkg->state_status;
  7789. + oldpkg->state_flag |= newpkg->state_flag;
  7790. + }
  7791. +
  7792. + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
  7793. + oldpkg->depends_str = newpkg->depends_str;
  7794. + newpkg->depends_str = NULL;
  7795. + oldpkg->depends_count = newpkg->depends_count;
  7796. + newpkg->depends_count = 0;
  7797. +
  7798. + oldpkg->depends = newpkg->depends;
  7799. + newpkg->depends = NULL;
  7800. +
  7801. + oldpkg->pre_depends_str = newpkg->pre_depends_str;
  7802. + newpkg->pre_depends_str = NULL;
  7803. + oldpkg->pre_depends_count = newpkg->pre_depends_count;
  7804. + newpkg->pre_depends_count = 0;
  7805. +
  7806. + oldpkg->recommends_str = newpkg->recommends_str;
  7807. + newpkg->recommends_str = NULL;
  7808. + oldpkg->recommends_count = newpkg->recommends_count;
  7809. + newpkg->recommends_count = 0;
  7810. +
  7811. + oldpkg->suggests_str = newpkg->suggests_str;
  7812. + newpkg->suggests_str = NULL;
  7813. + oldpkg->suggests_count = newpkg->suggests_count;
  7814. + newpkg->suggests_count = 0;
  7815. + }
  7816. +
  7817. + if (!oldpkg->provides_str) {
  7818. + oldpkg->provides_str = newpkg->provides_str;
  7819. + newpkg->provides_str = NULL;
  7820. + oldpkg->provides_count = newpkg->provides_count;
  7821. + newpkg->provides_count = 0;
  7822. +
  7823. + oldpkg->provides = newpkg->provides;
  7824. + newpkg->provides = NULL;
  7825. + }
  7826. +
  7827. + if (!oldpkg->conflicts_str) {
  7828. + oldpkg->conflicts_str = newpkg->conflicts_str;
  7829. + newpkg->conflicts_str = NULL;
  7830. + oldpkg->conflicts_count = newpkg->conflicts_count;
  7831. + newpkg->conflicts_count = 0;
  7832. +
  7833. + oldpkg->conflicts = newpkg->conflicts;
  7834. + newpkg->conflicts = NULL;
  7835. + }
  7836. +
  7837. + if (!oldpkg->replaces_str) {
  7838. + oldpkg->replaces_str = newpkg->replaces_str;
  7839. + newpkg->replaces_str = NULL;
  7840. + oldpkg->replaces_count = newpkg->replaces_count;
  7841. + newpkg->replaces_count = 0;
  7842. +
  7843. + oldpkg->replaces = newpkg->replaces;
  7844. + newpkg->replaces = NULL;
  7845. + }
  7846. +
  7847. + if (!oldpkg->filename)
  7848. + oldpkg->filename = str_dup_safe(newpkg->filename);
  7849. + if (0)
  7850. + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
  7851. + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
  7852. + if (!oldpkg->local_filename)
  7853. + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
  7854. + if (!oldpkg->tmp_unpack_dir)
  7855. + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
  7856. + if (!oldpkg->md5sum)
  7857. + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
  7858. + if (!oldpkg->size)
  7859. + oldpkg->size = str_dup_safe(newpkg->size);
  7860. + if (!oldpkg->installed_size)
  7861. + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
  7862. + if (!oldpkg->priority)
  7863. + oldpkg->priority = str_dup_safe(newpkg->priority);
  7864. + if (!oldpkg->source)
  7865. + oldpkg->source = str_dup_safe(newpkg->source);
  7866. + if (oldpkg->conffiles.head == NULL){
  7867. + oldpkg->conffiles = newpkg->conffiles;
  7868. + conffile_list_init(&newpkg->conffiles);
  7869. + }
  7870. + if (!oldpkg->installed_files){
  7871. + oldpkg->installed_files = newpkg->installed_files;
  7872. + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
  7873. + newpkg->installed_files = NULL;
  7874. + }
  7875. + if (!oldpkg->essential)
  7876. + oldpkg->essential = newpkg->essential;
  7877. +
  7878. + return 0;
  7879. +}
  7880. +
  7881. +abstract_pkg_t *abstract_pkg_new(void)
  7882. +{
  7883. + abstract_pkg_t * ab_pkg;
  7884. +
  7885. + ab_pkg = malloc(sizeof(abstract_pkg_t));
  7886. +
  7887. + if (ab_pkg == NULL) {
  7888. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7889. + return NULL;
  7890. + }
  7891. +
  7892. + if ( abstract_pkg_init(ab_pkg) < 0 )
  7893. + return NULL;
  7894. +
  7895. + return ab_pkg;
  7896. +}
  7897. +
  7898. +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
  7899. +{
  7900. + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
  7901. +
  7902. + ab_pkg->provided_by = abstract_pkg_vec_alloc();
  7903. + if (ab_pkg->provided_by==NULL){
  7904. + return -1;
  7905. + }
  7906. + ab_pkg->dependencies_checked = 0;
  7907. + ab_pkg->state_status = SS_NOT_INSTALLED;
  7908. +
  7909. + return 0;
  7910. +}
  7911. +
  7912. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
  7913. + char * temp_str;
  7914. + char **raw =NULL;
  7915. + char **raw_start=NULL;
  7916. +
  7917. + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
  7918. + if (temp_str == NULL ){
  7919. + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
  7920. + return;
  7921. + }
  7922. + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
  7923. +
  7924. + raw = raw_start = read_raw_pkgs_from_file(temp_str);
  7925. + if (raw == NULL ){
  7926. + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
  7927. + return;
  7928. + }
  7929. +
  7930. + while(*raw){
  7931. + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
  7932. + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
  7933. + }
  7934. + }
  7935. + raw = raw_start;
  7936. + while (*raw) {
  7937. + if (raw!=NULL)
  7938. + free(*raw++);
  7939. + }
  7940. +
  7941. + free(raw_start);
  7942. + free(temp_str);
  7943. +
  7944. + return ;
  7945. +
  7946. +}
  7947. +
  7948. +char * pkg_formatted_info(pkg_t *pkg )
  7949. +{
  7950. + char *line;
  7951. + char * buff;
  7952. +
  7953. + buff = malloc(8192);
  7954. + if (buff == NULL) {
  7955. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7956. + return NULL;
  7957. + }
  7958. +
  7959. + buff[0] = '\0';
  7960. +
  7961. + line = pkg_formatted_field(pkg, "Package");
  7962. + strncat(buff ,line, strlen(line));
  7963. + free(line);
  7964. +
  7965. + line = pkg_formatted_field(pkg, "Version");
  7966. + strncat(buff ,line, strlen(line));
  7967. + free(line);
  7968. +
  7969. + line = pkg_formatted_field(pkg, "Depends");
  7970. + strncat(buff ,line, strlen(line));
  7971. + free(line);
  7972. +
  7973. + line = pkg_formatted_field(pkg, "Recommends");
  7974. + strncat(buff ,line, strlen(line));
  7975. + free(line);
  7976. +
  7977. + line = pkg_formatted_field(pkg, "Suggests");
  7978. + strncat(buff ,line, strlen(line));
  7979. + free(line);
  7980. +
  7981. + line = pkg_formatted_field(pkg, "Provides");
  7982. + strncat(buff ,line, strlen(line));
  7983. + free(line);
  7984. +
  7985. + line = pkg_formatted_field(pkg, "Replaces");
  7986. + strncat(buff ,line, strlen(line));
  7987. + free(line);
  7988. +
  7989. + line = pkg_formatted_field(pkg, "Conflicts");
  7990. + strncat(buff ,line, strlen(line));
  7991. + free(line);
  7992. +
  7993. + line = pkg_formatted_field(pkg, "Status");
  7994. + strncat(buff ,line, strlen(line));
  7995. + free(line);
  7996. +
  7997. + line = pkg_formatted_field(pkg, "Section");
  7998. + strncat(buff ,line, strlen(line));
  7999. + free(line);
  8000. +
  8001. + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
  8002. + strncat(buff ,line, strlen(line));
  8003. + free(line);
  8004. +
  8005. + line = pkg_formatted_field(pkg, "Architecture");
  8006. + strncat(buff ,line, strlen(line));
  8007. + free(line);
  8008. +
  8009. + line = pkg_formatted_field(pkg, "Maintainer");
  8010. + strncat(buff ,line, strlen(line));
  8011. + free(line);
  8012. +
  8013. + line = pkg_formatted_field(pkg, "MD5sum");
  8014. + strncat(buff ,line, strlen(line));
  8015. + free(line);
  8016. +
  8017. + line = pkg_formatted_field(pkg, "Size");
  8018. + strncat(buff ,line, strlen(line));
  8019. + free(line);
  8020. +
  8021. + line = pkg_formatted_field(pkg, "Filename");
  8022. + strncat(buff ,line, strlen(line));
  8023. + free(line);
  8024. +
  8025. + line = pkg_formatted_field(pkg, "Conffiles");
  8026. + strncat(buff ,line, strlen(line));
  8027. + free(line);
  8028. +
  8029. + line = pkg_formatted_field(pkg, "Source");
  8030. + strncat(buff ,line, strlen(line));
  8031. + free(line);
  8032. +
  8033. + line = pkg_formatted_field(pkg, "Description");
  8034. + strncat(buff ,line, strlen(line));
  8035. + free(line);
  8036. +
  8037. + line = pkg_formatted_field(pkg, "Installed-Time");
  8038. + strncat(buff ,line, strlen(line));
  8039. + free(line);
  8040. +
  8041. + return buff;
  8042. +}
  8043. +
  8044. +char * pkg_formatted_field(pkg_t *pkg, const char *field )
  8045. +{
  8046. + static size_t LINE_LEN = 128;
  8047. + char * temp = (char *)malloc(1);
  8048. + int len = 0;
  8049. + int flag_provide_false = 0;
  8050. +
  8051. +/*
  8052. + Pigi: After some discussion with Florian we decided to modify the full procedure in
  8053. + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
  8054. +*/
  8055. +
  8056. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8057. + goto UNKNOWN_FMT_FIELD;
  8058. + }
  8059. +
  8060. + temp[0]='\0';
  8061. +
  8062. + switch (field[0])
  8063. + {
  8064. + case 'a':
  8065. + case 'A':
  8066. + if (strcasecmp(field, "Architecture") == 0) {
  8067. + /* Architecture */
  8068. + if (pkg->architecture) {
  8069. + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
  8070. + if ( temp == NULL ){
  8071. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8072. + return NULL;
  8073. + }
  8074. + temp[0]='\0';
  8075. + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
  8076. + }
  8077. + } else {
  8078. + goto UNKNOWN_FMT_FIELD;
  8079. + }
  8080. + break;
  8081. + case 'c':
  8082. + case 'C':
  8083. + if (strcasecmp(field, "Conffiles") == 0) {
  8084. + /* Conffiles */
  8085. + conffile_list_elt_t *iter;
  8086. + char confstr_[LINE_LEN];
  8087. +
  8088. + if (pkg->conffiles.head == NULL) {
  8089. + return temp;
  8090. + }
  8091. +
  8092. + len = 14 ;
  8093. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8094. + if (iter->data->name && iter->data->value) {
  8095. + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
  8096. + }
  8097. + }
  8098. + temp = (char *)realloc(temp,len);
  8099. + if ( temp == NULL ){
  8100. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8101. + return NULL;
  8102. + }
  8103. + temp[0]='\0';
  8104. + strncpy(temp, "Conffiles:\n", 12);
  8105. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8106. + if (iter->data->name && iter->data->value) {
  8107. + snprintf(confstr_, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
  8108. + strncat(temp, confstr_, strlen(confstr_));
  8109. + }
  8110. + }
  8111. + } else if (strcasecmp(field, "Conflicts") == 0) {
  8112. + int i;
  8113. +
  8114. + if (pkg->conflicts_count) {
  8115. + char conflictstr[LINE_LEN];
  8116. + len = 14 ;
  8117. + for(i = 0; i < pkg->conflicts_count; i++) {
  8118. + len = len + (strlen(pkg->conflicts_str[i])+5);
  8119. + }
  8120. + temp = (char *)realloc(temp,len);
  8121. + if ( temp == NULL ){
  8122. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8123. + return NULL;
  8124. + }
  8125. + temp[0]='\0';
  8126. + strncpy(temp, "Conflicts:", 11);
  8127. + for(i = 0; i < pkg->conflicts_count; i++) {
  8128. + snprintf(conflictstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
  8129. + strncat(temp, conflictstr, strlen(conflictstr));
  8130. + }
  8131. + strncat(temp, "\n", strlen("\n"));
  8132. + }
  8133. + } else {
  8134. + goto UNKNOWN_FMT_FIELD;
  8135. + }
  8136. + break;
  8137. + case 'd':
  8138. + case 'D':
  8139. + if (strcasecmp(field, "Depends") == 0) {
  8140. + /* Depends */
  8141. + int i;
  8142. +
  8143. + if (pkg->depends_count) {
  8144. + char depstr[LINE_LEN];
  8145. + len = 14 ;
  8146. + for(i = 0; i < pkg->depends_count; i++) {
  8147. + len = len + (strlen(pkg->depends_str[i])+4);
  8148. + }
  8149. + temp = (char *)realloc(temp,len);
  8150. + if ( temp == NULL ){
  8151. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8152. + return NULL;
  8153. + }
  8154. + temp[0]='\0';
  8155. + strncpy(temp, "Depends:", 10);
  8156. + for(i = 0; i < pkg->depends_count; i++) {
  8157. + snprintf(depstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
  8158. + strncat(temp, depstr, strlen(depstr));
  8159. + }
  8160. + strncat(temp, "\n", strlen("\n"));
  8161. + }
  8162. + } else if (strcasecmp(field, "Description") == 0) {
  8163. + /* Description */
  8164. + if (pkg->description) {
  8165. + temp = (char *)realloc(temp,strlen(pkg->description)+16);
  8166. + if ( temp == NULL ){
  8167. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8168. + return NULL;
  8169. + }
  8170. + temp[0]='\0';
  8171. + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
  8172. + }
  8173. + } else {
  8174. + goto UNKNOWN_FMT_FIELD;
  8175. + }
  8176. + break;
  8177. + case 'e':
  8178. + case 'E': {
  8179. + /* Essential */
  8180. + if (pkg->essential) {
  8181. + temp = (char *)realloc(temp,16);
  8182. + if ( temp == NULL ){
  8183. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8184. + return NULL;
  8185. + }
  8186. + temp[0]='\0';
  8187. + snprintf(temp, (16), "Essential: yes\n");
  8188. + }
  8189. + }
  8190. + break;
  8191. + case 'f':
  8192. + case 'F': {
  8193. + /* Filename */
  8194. + if (pkg->filename) {
  8195. + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
  8196. + if ( temp == NULL ){
  8197. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8198. + return NULL;
  8199. + }
  8200. + temp[0]='\0';
  8201. + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
  8202. + }
  8203. + }
  8204. + break;
  8205. + case 'i':
  8206. + case 'I': {
  8207. + if (strcasecmp(field, "Installed-Size") == 0) {
  8208. + /* Installed-Size */
  8209. + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
  8210. + if ( temp == NULL ){
  8211. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8212. + return NULL;
  8213. + }
  8214. + temp[0]='\0';
  8215. + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
  8216. + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
  8217. + temp = (char *)realloc(temp,29);
  8218. + if ( temp == NULL ){
  8219. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8220. + return NULL;
  8221. + }
  8222. + temp[0]='\0';
  8223. + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
  8224. + }
  8225. + }
  8226. + break;
  8227. + case 'm':
  8228. + case 'M': {
  8229. + /* Maintainer | MD5sum */
  8230. + if (strcasecmp(field, "Maintainer") == 0) {
  8231. + /* Maintainer */
  8232. + if (pkg->maintainer) {
  8233. + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
  8234. + if ( temp == NULL ){
  8235. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8236. + return NULL;
  8237. + }
  8238. + temp[0]='\0';
  8239. + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
  8240. + }
  8241. + } else if (strcasecmp(field, "MD5sum") == 0) {
  8242. + /* MD5sum */
  8243. + if (pkg->md5sum) {
  8244. + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
  8245. + if ( temp == NULL ){
  8246. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8247. + return NULL;
  8248. + }
  8249. + temp[0]='\0';
  8250. + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
  8251. + }
  8252. + } else {
  8253. + goto UNKNOWN_FMT_FIELD;
  8254. + }
  8255. + }
  8256. + break;
  8257. + case 'p':
  8258. + case 'P': {
  8259. + if (strcasecmp(field, "Package") == 0) {
  8260. + /* Package */
  8261. + temp = (char *)realloc(temp,strlen(pkg->name)+11);
  8262. + if ( temp == NULL ){
  8263. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8264. + return NULL;
  8265. + }
  8266. + temp[0]='\0';
  8267. + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
  8268. + } else if (strcasecmp(field, "Priority") == 0) {
  8269. + /* Priority */
  8270. + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
  8271. + if ( temp == NULL ){
  8272. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8273. + return NULL;
  8274. + }
  8275. + temp[0]='\0';
  8276. + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
  8277. + } else if (strcasecmp(field, "Provides") == 0) {
  8278. + /* Provides */
  8279. + int i;
  8280. +
  8281. + if (pkg->provides_count) {
  8282. + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
  8283. + for ( i=0; i < pkg->provides_count; i++ ){
  8284. + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
  8285. + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
  8286. + flag_provide_false = 1;
  8287. + }
  8288. + }
  8289. + if ( !flag_provide_false || /* Pigi there is not my trick flag */
  8290. + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
  8291. + char provstr[LINE_LEN];
  8292. + len = 15;
  8293. + for(i = 0; i < pkg->provides_count; i++) {
  8294. + len = len + (strlen(pkg->provides_str[i])+5);
  8295. + }
  8296. + temp = (char *)realloc(temp,len);
  8297. + if ( temp == NULL ){
  8298. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8299. + return NULL;
  8300. + }
  8301. + temp[0]='\0';
  8302. + strncpy(temp, "Provides:", 12);
  8303. + for(i = 0; i < pkg->provides_count; i++) {
  8304. + if (strlen(pkg->provides_str[i])>0){;
  8305. + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
  8306. + strncat(temp, provstr, strlen(provstr));
  8307. + }
  8308. + }
  8309. + strncat(temp, "\n", strlen("\n"));
  8310. + }
  8311. + }
  8312. + } else {
  8313. + goto UNKNOWN_FMT_FIELD;
  8314. + }
  8315. + }
  8316. + break;
  8317. + case 'r':
  8318. + case 'R': {
  8319. + int i;
  8320. + /* Replaces | Recommends*/
  8321. + if (strcasecmp (field, "Replaces") == 0) {
  8322. + if (pkg->replaces_count) {
  8323. + char replstr[LINE_LEN];
  8324. + len = 14;
  8325. + for (i = 0; i < pkg->replaces_count; i++) {
  8326. + len = len + (strlen(pkg->replaces_str[i])+5);
  8327. + }
  8328. + temp = (char *)realloc(temp,len);
  8329. + if ( temp == NULL ){
  8330. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8331. + return NULL;
  8332. + }
  8333. + temp[0]='\0';
  8334. + strncpy(temp, "Replaces:", 12);
  8335. + for (i = 0; i < pkg->replaces_count; i++) {
  8336. + snprintf(replstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
  8337. + strncat(temp, replstr, strlen(replstr));
  8338. + }
  8339. + strncat(temp, "\n", strlen("\n"));
  8340. + }
  8341. + } else if (strcasecmp (field, "Recommends") == 0) {
  8342. + if (pkg->recommends_count) {
  8343. + char recstr[LINE_LEN];
  8344. + len = 15;
  8345. + for(i = 0; i < pkg->recommends_count; i++) {
  8346. + len = len + (strlen( pkg->recommends_str[i])+5);
  8347. + }
  8348. + temp = (char *)realloc(temp,len);
  8349. + if ( temp == NULL ){
  8350. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8351. + return NULL;
  8352. + }
  8353. + temp[0]='\0';
  8354. + strncpy(temp, "Recommends:", 13);
  8355. + for(i = 0; i < pkg->recommends_count; i++) {
  8356. + snprintf(recstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
  8357. + strncat(temp, recstr, strlen(recstr));
  8358. + }
  8359. + strncat(temp, "\n", strlen("\n"));
  8360. + }
  8361. + } else {
  8362. + goto UNKNOWN_FMT_FIELD;
  8363. + }
  8364. + }
  8365. + break;
  8366. + case 's':
  8367. + case 'S': {
  8368. + /* Section | Size | Source | Status | Suggests */
  8369. + if (strcasecmp(field, "Section") == 0) {
  8370. + /* Section */
  8371. + if (pkg->section) {
  8372. + temp = (char *)realloc(temp,strlen(pkg->section)+11);
  8373. + if ( temp == NULL ){
  8374. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8375. + return NULL;
  8376. + }
  8377. + temp[0]='\0';
  8378. + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
  8379. + }
  8380. + } else if (strcasecmp(field, "Size") == 0) {
  8381. + /* Size */
  8382. + if (pkg->size) {
  8383. + temp = (char *)realloc(temp,strlen(pkg->size)+8);
  8384. + if ( temp == NULL ){
  8385. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8386. + return NULL;
  8387. + }
  8388. + temp[0]='\0';
  8389. + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
  8390. + }
  8391. + } else if (strcasecmp(field, "Source") == 0) {
  8392. + /* Source */
  8393. + if (pkg->source) {
  8394. + temp = (char *)realloc(temp,strlen(pkg->source)+10);
  8395. + if ( temp == NULL ){
  8396. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8397. + return NULL;
  8398. + }
  8399. + temp[0]='\0';
  8400. + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
  8401. + }
  8402. + } else if (strcasecmp(field, "Status") == 0) {
  8403. + /* Status */
  8404. + /* Benjamin Pineau note: we should avoid direct usage of
  8405. + * strlen(arg) without keeping "arg" for later free()
  8406. + */
  8407. + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
  8408. + char *pstat=pkg_state_status_to_str(pkg->state_status);
  8409. + char *pwant=pkg_state_want_to_str(pkg->state_want);
  8410. +
  8411. + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
  8412. + temp = (char *)realloc(temp,sum_of_sizes);
  8413. + if ( temp == NULL ){
  8414. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8415. + return NULL;
  8416. + }
  8417. + temp[0]='\0';
  8418. + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
  8419. + free(pflag);
  8420. + free(pwant);
  8421. + if(pstat) /* pfstat can be NULL if ENOMEM */
  8422. + free(pstat);
  8423. + } else if (strcasecmp(field, "Suggests") == 0) {
  8424. + if (pkg->suggests_count) {
  8425. + int i;
  8426. + char sugstr[LINE_LEN];
  8427. + len = 13;
  8428. + for(i = 0; i < pkg->suggests_count; i++) {
  8429. + len = len + (strlen(pkg->suggests_str[i])+5);
  8430. + }
  8431. + temp = (char *)realloc(temp,len);
  8432. + if ( temp == NULL ){
  8433. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8434. + return NULL;
  8435. + }
  8436. + temp[0]='\0';
  8437. + strncpy(temp, "Suggests:", 10);
  8438. + for(i = 0; i < pkg->suggests_count; i++) {
  8439. + snprintf(sugstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
  8440. + strncat(temp, sugstr, strlen(sugstr));
  8441. + }
  8442. + strncat(temp, "\n", strlen("\n"));
  8443. + }
  8444. + } else {
  8445. + goto UNKNOWN_FMT_FIELD;
  8446. + }
  8447. + }
  8448. + break;
  8449. + case 'v':
  8450. + case 'V': {
  8451. + /* Version */
  8452. + char *version = pkg_version_str_alloc(pkg);
  8453. + temp = (char *)realloc(temp,strlen(version)+14);
  8454. + if ( temp == NULL ){
  8455. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8456. + return NULL;
  8457. + }
  8458. + temp[0]='\0';
  8459. + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
  8460. + free(version);
  8461. + }
  8462. + break;
  8463. + default:
  8464. + goto UNKNOWN_FMT_FIELD;
  8465. + }
  8466. +
  8467. + if ( strlen(temp)<2 ) {
  8468. + temp[0]='\0';
  8469. + }
  8470. + return temp;
  8471. +
  8472. + UNKNOWN_FMT_FIELD:
  8473. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
  8474. + if ( strlen(temp)<2 ) {
  8475. + temp[0]='\0';
  8476. + }
  8477. +
  8478. + return temp;
  8479. +}
  8480. +
  8481. +void pkg_print_info(pkg_t *pkg, FILE *file)
  8482. +{
  8483. + char * buff;
  8484. + if (pkg == NULL) {
  8485. + return;
  8486. + }
  8487. +
  8488. + buff = pkg_formatted_info(pkg);
  8489. + if ( buff == NULL )
  8490. + return;
  8491. + if (strlen(buff)>2){
  8492. + fwrite(buff, 1, strlen(buff), file);
  8493. + }
  8494. + free(buff);
  8495. +}
  8496. +
  8497. +void pkg_print_status(pkg_t * pkg, FILE * file)
  8498. +{
  8499. + if (pkg == NULL) {
  8500. + return;
  8501. + }
  8502. +
  8503. + /* XXX: QUESTION: Do we actually want more fields here? The
  8504. + original idea was to save space by installing only what was
  8505. + needed for actual computation, (package, version, status,
  8506. + essential, conffiles). The assumption is that all other fields
  8507. + can be found in th available file.
  8508. +
  8509. + But, someone proposed the idea to make it possible to
  8510. + reconstruct a .ipk from an installed package, (ie. for beaming
  8511. + from one handheld to another). So, maybe we actually want a few
  8512. + more fields here, (depends, suggests, etc.), so that that would
  8513. + be guaranteed to work even in the absence of more information
  8514. + from the available file.
  8515. +
  8516. + 28-MAR-03: kergoth and I discussed this yesterday. We think
  8517. + the essential info needs to be here for all installed packages
  8518. + because they may not appear in the Packages files on various
  8519. + feeds. Furthermore, one should be able to install from URL or
  8520. + local storage without requiring a Packages file from any feed.
  8521. + -Jamey
  8522. + */
  8523. + pkg_print_field(pkg, file, "Package");
  8524. + pkg_print_field(pkg, file, "Version");
  8525. + pkg_print_field(pkg, file, "Depends");
  8526. + pkg_print_field(pkg, file, "Recommends");
  8527. + pkg_print_field(pkg, file, "Suggests");
  8528. + pkg_print_field(pkg, file, "Provides");
  8529. + pkg_print_field(pkg, file, "Replaces");
  8530. + pkg_print_field(pkg, file, "Conflicts");
  8531. + pkg_print_field(pkg, file, "Status");
  8532. + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
  8533. + pkg_print_field(pkg, file, "Architecture");
  8534. + pkg_print_field(pkg, file, "Conffiles");
  8535. + pkg_print_field(pkg, file, "Installed-Time");
  8536. + fputs("\n", file);
  8537. +}
  8538. +
  8539. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
  8540. +{
  8541. + char *buff;
  8542. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8543. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
  8544. + __FUNCTION__, field);
  8545. + }
  8546. + buff = pkg_formatted_field(pkg, field);
  8547. + if (strlen(buff)>2) {
  8548. + fprintf(file, "%s", buff);
  8549. + fflush(file);
  8550. + }
  8551. + free(buff);
  8552. + return;
  8553. +}
  8554. +
  8555. +/*
  8556. + * libdpkg - Debian packaging suite library routines
  8557. + * vercmp.c - comparison of version numbers
  8558. + *
  8559. + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
  8560. + */
  8561. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
  8562. +{
  8563. + int r;
  8564. +
  8565. + if (pkg->epoch > ref_pkg->epoch) {
  8566. + return 1;
  8567. + }
  8568. +
  8569. + if (pkg->epoch < ref_pkg->epoch) {
  8570. + return -1;
  8571. + }
  8572. +
  8573. + r = verrevcmp(pkg->version, ref_pkg->version);
  8574. + if (r) {
  8575. + return r;
  8576. + }
  8577. +
  8578. +#ifdef USE_DEBVERSION
  8579. + r = verrevcmp(pkg->revision, ref_pkg->revision);
  8580. + if (r) {
  8581. + return r;
  8582. + }
  8583. +
  8584. + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
  8585. +#endif
  8586. +
  8587. + return r;
  8588. +}
  8589. +
  8590. +int verrevcmp(const char *val, const char *ref)
  8591. +{
  8592. + int vc, rc;
  8593. + long vl, rl;
  8594. + const char *vp, *rp;
  8595. + const char *vsep, *rsep;
  8596. +
  8597. + if (!val) val= "";
  8598. + if (!ref) ref= "";
  8599. + for (;;) {
  8600. + vp= val; while (*vp && !isdigit(*vp)) vp++;
  8601. + rp= ref; while (*rp && !isdigit(*rp)) rp++;
  8602. + for (;;) {
  8603. + vc= (val == vp) ? 0 : *val++;
  8604. + rc= (ref == rp) ? 0 : *ref++;
  8605. + if (!rc && !vc) break;
  8606. + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
  8607. + if (rc && !isalpha(rc)) rc += 256;
  8608. + if (vc != rc) return vc - rc;
  8609. + }
  8610. + val= vp;
  8611. + ref= rp;
  8612. + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
  8613. + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
  8614. + if (vl != rl) return vl - rl;
  8615. +
  8616. + vc = *val;
  8617. + rc = *ref;
  8618. + vsep = strchr(".-", vc);
  8619. + rsep = strchr(".-", rc);
  8620. + if (vsep && !rsep) return -1;
  8621. + if (!vsep && rsep) return +1;
  8622. +
  8623. + if (!*val && !*ref) return 0;
  8624. + if (!*val) return -1;
  8625. + if (!*ref) return +1;
  8626. + }
  8627. +}
  8628. +
  8629. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
  8630. +{
  8631. + int r;
  8632. +
  8633. + r = pkg_compare_versions(it, ref);
  8634. +
  8635. + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
  8636. + return r <= 0;
  8637. + }
  8638. +
  8639. + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
  8640. + return r >= 0;
  8641. + }
  8642. +
  8643. + if (strcmp(op, "<<") == 0) {
  8644. + return r < 0;
  8645. + }
  8646. +
  8647. + if (strcmp(op, ">>") == 0) {
  8648. + return r > 0;
  8649. + }
  8650. +
  8651. + if (strcmp(op, "=") == 0) {
  8652. + return r == 0;
  8653. + }
  8654. +
  8655. + fprintf(stderr, "unknown operator: %s", op);
  8656. + return 0;
  8657. +}
  8658. +
  8659. +int pkg_name_version_and_architecture_compare(pkg_t *p1, pkg_t *p2)
  8660. +{
  8661. + const pkg_t *a = *(const pkg_t **)p1;
  8662. + const pkg_t *b = *(const pkg_t **)p2;
  8663. + int namecmp;
  8664. + int vercmp;
  8665. + if (!a->name || !b->name) {
  8666. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8667. + a, a->name, b, b->name);
  8668. + return 0;
  8669. + }
  8670. +
  8671. + namecmp = strcmp(a->name, b->name);
  8672. + if (namecmp)
  8673. + return namecmp;
  8674. + vercmp = pkg_compare_versions(a, b);
  8675. + if (vercmp)
  8676. + return vercmp;
  8677. + if (!a->arch_priority || !b->arch_priority) {
  8678. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
  8679. + a, a->arch_priority, b, b->arch_priority);
  8680. + return 0;
  8681. + }
  8682. + if (a->arch_priority > b->arch_priority)
  8683. + return 1;
  8684. + if (a->arch_priority < b->arch_priority)
  8685. + return -1;
  8686. + return 0;
  8687. +}
  8688. +
  8689. +int abstract_pkg_name_compare(abstract_pkg_t *p1, abstract_pkg_t *p2)
  8690. +{
  8691. + const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
  8692. + const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
  8693. + if (!a->name || !b->name) {
  8694. + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8695. + a, a->name, b, b->name);
  8696. + return 0;
  8697. + }
  8698. + return strcmp(a->name, b->name);
  8699. +}
  8700. +
  8701. +
  8702. +char *pkg_version_str_alloc(pkg_t *pkg)
  8703. +{
  8704. + char *complete_version;
  8705. + char *epoch_str;
  8706. +#ifdef USE_DEBVERSION
  8707. + char *revision_str;
  8708. + char *familiar_revision_str;
  8709. +#endif
  8710. +
  8711. + if (pkg->epoch) {
  8712. + sprintf_alloc(&epoch_str, "%lu:", (unsigned long)pkg->epoch);
  8713. + } else {
  8714. + epoch_str = strdup("");
  8715. + }
  8716. +
  8717. +#ifdef USE_DEBVERSION
  8718. + if (pkg->revision && strlen(pkg->revision)) {
  8719. + sprintf_alloc(&revision_str, "-%s", pkg->revision);
  8720. + } else {
  8721. + revision_str = strdup("");
  8722. + }
  8723. +
  8724. + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
  8725. + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
  8726. + } else {
  8727. + familiar_revision_str = strdup("");
  8728. + }
  8729. +#endif
  8730. +
  8731. +#ifdef USE_DEBVERSION
  8732. + sprintf_alloc(&complete_version, "%s%s%s%s",
  8733. + epoch_str, pkg->version, revision_str, familiar_revision_str);
  8734. +#else
  8735. + sprintf_alloc(&complete_version, "%s%s",
  8736. + epoch_str, pkg->version);
  8737. +#endif
  8738. +
  8739. + free(epoch_str);
  8740. +#ifdef USE_DEBVERSION
  8741. + free(revision_str);
  8742. + free(familiar_revision_str);
  8743. +#endif
  8744. +
  8745. + return complete_version;
  8746. +}
  8747. +
  8748. +str_list_t *pkg_get_installed_files(pkg_t *pkg)
  8749. +{
  8750. + int err;
  8751. + char *list_file_name = NULL;
  8752. + FILE *list_file = NULL;
  8753. + char *line;
  8754. + char *installed_file_name;
  8755. + int rootdirlen;
  8756. +
  8757. + pkg->installed_files_ref_cnt++;
  8758. +
  8759. + if (pkg->installed_files) {
  8760. + return pkg->installed_files;
  8761. + }
  8762. +
  8763. + pkg->installed_files = str_list_alloc();
  8764. + if (pkg->installed_files == NULL) {
  8765. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8766. + return NULL;
  8767. + }
  8768. +
  8769. + /* For uninstalled packages, get the file list firectly from the package.
  8770. + For installed packages, look at the package.list file in the database.
  8771. + */
  8772. + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
  8773. + if (pkg->local_filename == NULL) {
  8774. + return pkg->installed_files;
  8775. + }
  8776. + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
  8777. + file. In other words, change deb_extract so that it can
  8778. + simply return the file list as a char *[] rather than
  8779. + insisting on writing in to a FILE * as it does now. */
  8780. + list_file = tmpfile();
  8781. + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
  8782. + if (err) {
  8783. + fclose(list_file);
  8784. + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
  8785. + __FUNCTION__, pkg->local_filename, strerror(err));
  8786. + return pkg->installed_files;
  8787. + }
  8788. + rewind(list_file);
  8789. + } else {
  8790. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8791. + pkg->dest->info_dir, pkg->name);
  8792. + if (! file_exists(list_file_name)) {
  8793. + free(list_file_name);
  8794. + return pkg->installed_files;
  8795. + }
  8796. +
  8797. + list_file = fopen(list_file_name, "r");
  8798. + if (list_file == NULL) {
  8799. + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
  8800. + list_file_name, strerror(errno));
  8801. + free(list_file_name);
  8802. + return pkg->installed_files;
  8803. + }
  8804. + free(list_file_name);
  8805. + }
  8806. +
  8807. + rootdirlen = strlen( pkg->dest->root_dir );
  8808. + while (1) {
  8809. + char *file_name;
  8810. +
  8811. + line = file_read_line_alloc(list_file);
  8812. + if (line == NULL) {
  8813. + break;
  8814. + }
  8815. + str_chomp(line);
  8816. + file_name = line;
  8817. +
  8818. + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
  8819. + if( strncmp( pkg->dest->root_dir,
  8820. + file_name,
  8821. + rootdirlen ) ) {
  8822. + if (*file_name == '.') {
  8823. + file_name++;
  8824. + }
  8825. + if (*file_name == '/') {
  8826. + file_name++;
  8827. + }
  8828. +
  8829. + /* Freed in pkg_free_installed_files */
  8830. + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
  8831. + } else {
  8832. + // already contains root_dir as header -> ABSOLUTE
  8833. + sprintf_alloc(&installed_file_name, "%s", file_name);
  8834. + }
  8835. + str_list_append(pkg->installed_files, installed_file_name);
  8836. + free(line);
  8837. + }
  8838. +
  8839. + fclose(list_file);
  8840. +
  8841. + return pkg->installed_files;
  8842. +}
  8843. +
  8844. +/* XXX: CLEANUP: This function and it's counterpart,
  8845. + (pkg_get_installed_files), do not match our init/deinit naming
  8846. + convention. Nor the alloc/free convention. But, then again, neither
  8847. + of these conventions currrently fit the way these two functions
  8848. + work. */
  8849. +int pkg_free_installed_files(pkg_t *pkg)
  8850. +{
  8851. + str_list_elt_t *iter;
  8852. +
  8853. + pkg->installed_files_ref_cnt--;
  8854. + if (pkg->installed_files_ref_cnt > 0) {
  8855. + return 0;
  8856. + }
  8857. +
  8858. + if (pkg->installed_files) {
  8859. +
  8860. + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
  8861. + /* malloced in pkg_get_installed_files */
  8862. + free (iter->data);
  8863. + iter->data = NULL;
  8864. + }
  8865. +
  8866. + str_list_deinit(pkg->installed_files);
  8867. + }
  8868. +
  8869. + pkg->installed_files = NULL;
  8870. +
  8871. + return 0;
  8872. +}
  8873. +
  8874. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
  8875. +{
  8876. + int err;
  8877. + char *list_file_name;
  8878. +
  8879. + //I don't think pkg_free_installed_files should be called here. Jamey
  8880. + //pkg_free_installed_files(pkg);
  8881. +
  8882. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8883. + pkg->dest->info_dir, pkg->name);
  8884. + if (!conf->noaction) {
  8885. + err = unlink(list_file_name);
  8886. + free(list_file_name);
  8887. +
  8888. + if (err) {
  8889. + return errno;
  8890. + }
  8891. + }
  8892. + return 0;
  8893. +}
  8894. +
  8895. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
  8896. +{
  8897. + conffile_list_elt_t *iter;
  8898. + conffile_t *conffile;
  8899. +
  8900. + if (pkg == NULL) {
  8901. + return NULL;
  8902. + }
  8903. +
  8904. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8905. + conffile = iter->data;
  8906. +
  8907. + if (strcmp(conffile->name, file_name) == 0) {
  8908. + return conffile;
  8909. + }
  8910. + }
  8911. +
  8912. + return NULL;
  8913. +}
  8914. +
  8915. +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
  8916. + const char *script, const char *args)
  8917. +{
  8918. + int err;
  8919. + char *path;
  8920. + char *cmd;
  8921. +
  8922. + /* XXX: FEATURE: When conf->offline_root is set, we should run the
  8923. + maintainer script within a chroot environment. */
  8924. +
  8925. + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
  8926. + have scripts in pkg->tmp_unpack_dir. */
  8927. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  8928. + if (pkg->dest == NULL) {
  8929. + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
  8930. + __FUNCTION__, pkg->name);
  8931. + return EINVAL;
  8932. + }
  8933. + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
  8934. + } else {
  8935. + if (pkg->tmp_unpack_dir == NULL) {
  8936. + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
  8937. + __FUNCTION__, pkg->name);
  8938. + return EINVAL;
  8939. + }
  8940. + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
  8941. + }
  8942. +
  8943. + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
  8944. + if (conf->noaction) return 0;
  8945. +
  8946. + /* XXX: CLEANUP: There must be a better way to handle maintainer
  8947. + scripts when running with offline_root mode and/or a dest other
  8948. + than '/'. I've been playing around with some clever chroot
  8949. + tricks and I might come up with something workable. */
  8950. + if (conf->offline_root) {
  8951. + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
  8952. + }
  8953. +
  8954. + setenv("PKG_ROOT",
  8955. + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
  8956. +
  8957. + if (! file_exists(path)) {
  8958. + free(path);
  8959. + return 0;
  8960. + }
  8961. +
  8962. + if (conf->offline_root) {
  8963. + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
  8964. + free(path);
  8965. + return 0;
  8966. + }
  8967. +
  8968. + sprintf_alloc(&cmd, "%s %s", path, args);
  8969. + free(path);
  8970. +
  8971. + err = xsystem(cmd);
  8972. + free(cmd);
  8973. +
  8974. + if (err) {
  8975. + fprintf(stderr, "%s script returned status %d\n", script, err);
  8976. + return err;
  8977. + }
  8978. +
  8979. + return 0;
  8980. +}
  8981. +
  8982. +char *pkg_state_want_to_str(pkg_state_want_t sw)
  8983. +{
  8984. + int i;
  8985. +
  8986. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  8987. + if (pkg_state_want_map[i].value == sw) {
  8988. + return strdup(pkg_state_want_map[i].str);
  8989. + }
  8990. + }
  8991. +
  8992. + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
  8993. + __FUNCTION__, sw);
  8994. + return strdup("<STATE_WANT_UNKNOWN>");
  8995. +}
  8996. +
  8997. +pkg_state_want_t pkg_state_want_from_str(char *str)
  8998. +{
  8999. + int i;
  9000. +
  9001. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  9002. + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
  9003. + return pkg_state_want_map[i].value;
  9004. + }
  9005. + }
  9006. +
  9007. + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
  9008. + __FUNCTION__, str);
  9009. + return SW_UNKNOWN;
  9010. +}
  9011. +
  9012. +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
  9013. +{
  9014. + int i;
  9015. + int len = 3; /* ok\000 is minimum */
  9016. + char *str = NULL;
  9017. +
  9018. + /* clear the temporary flags before converting to string */
  9019. + sf &= SF_NONVOLATILE_FLAGS;
  9020. +
  9021. + if (sf == 0) {
  9022. + return strdup("ok");
  9023. + } else {
  9024. +
  9025. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9026. + if (sf & pkg_state_flag_map[i].value) {
  9027. + len += strlen(pkg_state_flag_map[i].str) + 1;
  9028. + }
  9029. + }
  9030. + str = malloc(len);
  9031. + if ( str == NULL ) {
  9032. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9033. + return NULL;
  9034. + }
  9035. + str[0] = 0;
  9036. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9037. + if (sf & pkg_state_flag_map[i].value) {
  9038. + strcat(str, pkg_state_flag_map[i].str);
  9039. + strcat(str, ",");
  9040. + }
  9041. + }
  9042. + len = strlen(str);
  9043. + str[len-1] = 0; /* squash last comma */
  9044. + return str;
  9045. + }
  9046. +}
  9047. +
  9048. +pkg_state_flag_t pkg_state_flag_from_str(char *str)
  9049. +{
  9050. + int i;
  9051. + int sf = SF_OK;
  9052. +
  9053. + if (strcmp(str, "ok") == 0) {
  9054. + return SF_OK;
  9055. + }
  9056. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9057. + const char *sfname = pkg_state_flag_map[i].str;
  9058. + int sfname_len = strlen(sfname);
  9059. + if (strncmp(str, sfname, sfname_len) == 0) {
  9060. + sf |= pkg_state_flag_map[i].value;
  9061. + str += sfname_len;
  9062. + if (str[0] == ',') {
  9063. + str++;
  9064. + } else {
  9065. + break;
  9066. + }
  9067. + }
  9068. + }
  9069. +
  9070. + return sf;
  9071. +}
  9072. +
  9073. +char *pkg_state_status_to_str(pkg_state_status_t ss)
  9074. +{
  9075. + int i;
  9076. +
  9077. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9078. + if (pkg_state_status_map[i].value == ss) {
  9079. + return strdup(pkg_state_status_map[i].str);
  9080. + }
  9081. + }
  9082. +
  9083. + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
  9084. + __FUNCTION__, ss);
  9085. + return strdup("<STATE_STATUS_UNKNOWN>");
  9086. +}
  9087. +
  9088. +pkg_state_status_t pkg_state_status_from_str(char *str)
  9089. +{
  9090. + int i;
  9091. +
  9092. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9093. + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
  9094. + return pkg_state_status_map[i].value;
  9095. + }
  9096. + }
  9097. +
  9098. + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
  9099. + __FUNCTION__, str);
  9100. + return SS_NOT_INSTALLED;
  9101. +}
  9102. +
  9103. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
  9104. +{
  9105. + nv_pair_list_elt_t *l;
  9106. +
  9107. + if (!pkg->architecture)
  9108. + return 1;
  9109. +
  9110. + l = conf->arch_list.head;
  9111. +
  9112. + while (l) {
  9113. + nv_pair_t *nv = l->data;
  9114. + if (strcmp(nv->name, pkg->architecture) == 0) {
  9115. + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
  9116. + return 1;
  9117. + }
  9118. + l = l->next;
  9119. + }
  9120. +
  9121. + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
  9122. + return 0;
  9123. +}
  9124. +
  9125. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
  9126. +{
  9127. + nv_pair_list_elt_t *l;
  9128. +
  9129. + l = conf->arch_list.head;
  9130. +
  9131. + while (l) {
  9132. + nv_pair_t *nv = l->data;
  9133. + if (strcmp(nv->name, archname) == 0) {
  9134. + int priority = strtol(nv->value, NULL, 0);
  9135. + return priority;
  9136. + }
  9137. + l = l->next;
  9138. + }
  9139. + return 0;
  9140. +}
  9141. +
  9142. +int pkg_info_preinstall_check(ipkg_conf_t *conf)
  9143. +{
  9144. + int i;
  9145. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9146. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  9147. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9148. +
  9149. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
  9150. + pkg_hash_fetch_available(pkg_hash, available_pkgs);
  9151. + /* update arch_priority for each package */
  9152. + for (i = 0; i < available_pkgs->len; i++) {
  9153. + pkg_t *pkg = available_pkgs->pkgs[i];
  9154. + int arch_priority = 1;
  9155. + if (!pkg)
  9156. + continue;
  9157. + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
  9158. + if (pkg->architecture)
  9159. + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
  9160. + else
  9161. + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
  9162. + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
  9163. + pkg->arch_priority = arch_priority;
  9164. + }
  9165. +
  9166. + for (i = 0; i < available_pkgs->len; i++) {
  9167. + pkg_t *pkg = available_pkgs->pkgs[i];
  9168. + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
  9169. + /* clear flags and want for any uninstallable package */
  9170. + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
  9171. + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
  9172. + pkg->state_want = SW_UNKNOWN;
  9173. + pkg->state_flag = 0;
  9174. + }
  9175. + }
  9176. + pkg_vec_free(available_pkgs);
  9177. +
  9178. + /* update the file owner data structure */
  9179. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
  9180. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9181. + for (i = 0; i < installed_pkgs->len; i++) {
  9182. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9183. + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
  9184. + str_list_elt_t *iter;
  9185. + if (installed_files == NULL) {
  9186. + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
  9187. + break;
  9188. + }
  9189. + for (iter = installed_files->head; iter; iter = iter->next) {
  9190. + char *installed_file = iter->data;
  9191. + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
  9192. + file_hash_set_file_owner(conf, installed_file, pkg);
  9193. + }
  9194. + }
  9195. + pkg_vec_free(installed_pkgs);
  9196. +
  9197. + return 0;
  9198. +}
  9199. +
  9200. +struct pkg_write_filelist_data {
  9201. + ipkg_conf_t *conf;
  9202. + pkg_t *pkg;
  9203. + FILE *stream;
  9204. +};
  9205. +
  9206. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
  9207. +{
  9208. + struct pkg_write_filelist_data *data = data_;
  9209. + pkg_t *entry = entry_;
  9210. + if (entry == data->pkg) {
  9211. + fprintf(data->stream, "%s\n", key);
  9212. + }
  9213. +}
  9214. +
  9215. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
  9216. +{
  9217. + struct pkg_write_filelist_data data;
  9218. + char *list_file_name = NULL;
  9219. + int err = 0;
  9220. +
  9221. + if (!pkg) {
  9222. + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
  9223. + return -EINVAL;
  9224. + }
  9225. + ipkg_message(conf, IPKG_INFO,
  9226. + " creating %s.list file\n", pkg->name);
  9227. + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
  9228. + if (!list_file_name) {
  9229. + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
  9230. + return -ENOMEM;
  9231. + }
  9232. + ipkg_message(conf, IPKG_INFO,
  9233. + " creating %s file for pkg %s\n", list_file_name, pkg->name);
  9234. + data.stream = fopen(list_file_name, "w");
  9235. + if (!data.stream) {
  9236. + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
  9237. + list_file_name, strerror(errno));
  9238. + return errno;
  9239. + }
  9240. + data.pkg = pkg;
  9241. + data.conf = conf;
  9242. + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
  9243. + fclose(data.stream);
  9244. + free(list_file_name);
  9245. +
  9246. + return err;
  9247. +}
  9248. +
  9249. +int pkg_write_changed_filelists(ipkg_conf_t *conf)
  9250. +{
  9251. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9252. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9253. + int i;
  9254. + int err;
  9255. + if (conf->noaction)
  9256. + return 0;
  9257. +
  9258. + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
  9259. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9260. + for (i = 0; i < installed_pkgs->len; i++) {
  9261. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9262. + if (pkg->state_flag & SF_FILELIST_CHANGED) {
  9263. + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
  9264. + err = pkg_write_filelist(conf, pkg);
  9265. + if (err)
  9266. + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
  9267. + }
  9268. + }
  9269. + return 0;
  9270. +}
  9271. --- /dev/null
  9272. +++ busybox-1.18.1/archival/libipkg/pkg.h
  9273. @@ -0,0 +1,229 @@
  9274. +/* pkg.h - the itsy package management system
  9275. +
  9276. + Carl D. Worth
  9277. +
  9278. + Copyright (C) 2001 University of Southern California
  9279. +
  9280. + This program is free software; you can redistribute it and/or
  9281. + modify it under the terms of the GNU General Public License as
  9282. + published by the Free Software Foundation; either version 2, or (at
  9283. + your option) any later version.
  9284. +
  9285. + This program is distributed in the hope that it will be useful, but
  9286. + WITHOUT ANY WARRANTY; without even the implied warranty of
  9287. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9288. + General Public License for more details.
  9289. +*/
  9290. +
  9291. +#ifndef PKG_H
  9292. +#define PKG_H
  9293. +
  9294. +#include <sys/types.h>
  9295. +#include <sys/stat.h>
  9296. +#include <unistd.h>
  9297. +
  9298. +#include "pkg_vec.h"
  9299. +#include "str_list.h"
  9300. +#include "pkg_src.h"
  9301. +#include "pkg_dest.h"
  9302. +#include "ipkg_conf.h"
  9303. +#include "conffile_list.h"
  9304. +
  9305. +struct ipkg_conf;
  9306. +
  9307. +/* I think "Size" is currently the shortest field name */
  9308. +#define PKG_MINIMUM_FIELD_NAME_LEN 4
  9309. +
  9310. +enum pkg_state_want
  9311. +{
  9312. + SW_UNKNOWN = 1,
  9313. + SW_INSTALL,
  9314. + SW_DEINSTALL,
  9315. + SW_PURGE,
  9316. + SW_LAST_STATE_WANT
  9317. +};
  9318. +typedef enum pkg_state_want pkg_state_want_t;
  9319. +
  9320. +enum pkg_state_flag
  9321. +{
  9322. + SF_OK = 0,
  9323. + SF_REINSTREQ = 1,
  9324. + SF_HOLD = 2, /* do not upgrade version */
  9325. + SF_REPLACE = 4, /* replace this package */
  9326. + SF_NOPRUNE = 8, /* do not remove obsolete files */
  9327. + SF_PREFER = 16, /* prefer this version */
  9328. + SF_OBSOLETE = 32, /* old package in upgrade pair */
  9329. + SF_MARKED = 64, /* temporary mark */
  9330. + SF_FILELIST_CHANGED = 128, /* needs filelist written */
  9331. + SF_USER = 256,
  9332. + SF_LAST_STATE_FLAG
  9333. +};
  9334. +typedef enum pkg_state_flag pkg_state_flag_t;
  9335. +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
  9336. +
  9337. +enum pkg_state_status
  9338. +{
  9339. + SS_NOT_INSTALLED = 1,
  9340. + SS_UNPACKED,
  9341. + SS_HALF_CONFIGURED,
  9342. + SS_INSTALLED,
  9343. + SS_HALF_INSTALLED,
  9344. + SS_CONFIG_FILES,
  9345. + SS_POST_INST_FAILED,
  9346. + SS_REMOVAL_FAILED,
  9347. + SS_LAST_STATE_STATUS
  9348. +};
  9349. +typedef enum pkg_state_status pkg_state_status_t;
  9350. +
  9351. +struct abstract_pkg{
  9352. + char * name;
  9353. + int dependencies_checked;
  9354. + pkg_vec_t * pkgs;
  9355. + pkg_state_status_t state_status;
  9356. + pkg_state_flag_t state_flag;
  9357. + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
  9358. + abstract_pkg_vec_t * provided_by;
  9359. + abstract_pkg_vec_t * replaced_by;
  9360. +};
  9361. +
  9362. +#include "pkg_depends.h"
  9363. +
  9364. +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
  9365. +
  9366. + The 3 version fields should go into a single version struct. (This
  9367. + is especially important since, currently, pkg->version can easily
  9368. + be mistaken for pkg_verson_str_alloc(pkg) although they are very
  9369. + distinct. This has been the source of multiple bugs.
  9370. +
  9371. + The 3 state fields could possibly also go into their own struct.
  9372. +
  9373. + All fields which deal with lists of packages, (Depends,
  9374. + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
  9375. + be handled by a single struct in pkg_t
  9376. +
  9377. + All string fields for which there is a small set of possible
  9378. + values, (section, maintainer, architecture, maybe version?), that
  9379. + are reused among different packages -- for all such packages we
  9380. + should move from "char *"s to some atom datatype to share data
  9381. + storage and use less memory. We might even do reference counting,
  9382. + but probably not since most often we only create new pkg_t structs,
  9383. + we don't often free them. */
  9384. +struct pkg
  9385. +{
  9386. + char *name;
  9387. + unsigned long epoch;
  9388. + char *version;
  9389. + char *revision;
  9390. + char *familiar_revision;
  9391. + pkg_src_t *src;
  9392. + pkg_dest_t *dest;
  9393. + char *architecture;
  9394. + char *section;
  9395. + char *maintainer;
  9396. + char *description;
  9397. + pkg_state_want_t state_want;
  9398. + pkg_state_flag_t state_flag;
  9399. + pkg_state_status_t state_status;
  9400. + char **depends_str;
  9401. + int depends_count;
  9402. + char **pre_depends_str;
  9403. + int pre_depends_count;
  9404. + char **recommends_str;
  9405. + int recommends_count;
  9406. + char **suggests_str;
  9407. + int suggests_count;
  9408. + compound_depend_t * depends;
  9409. +
  9410. + /* Abhaya: new conflicts */
  9411. + char **conflicts_str;
  9412. + compound_depend_t * conflicts;
  9413. + int conflicts_count;
  9414. +
  9415. + char **replaces_str;
  9416. + int replaces_count;
  9417. + abstract_pkg_t ** replaces;
  9418. +
  9419. + char **provides_str;
  9420. + int provides_count;
  9421. + abstract_pkg_t ** provides;
  9422. +
  9423. + abstract_pkg_t *parent;
  9424. +
  9425. + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
  9426. +
  9427. + char *filename;
  9428. + char *local_filename;
  9429. + char *url;
  9430. + char *tmp_unpack_dir;
  9431. + char *md5sum;
  9432. + char *size;
  9433. + char *installed_size;
  9434. + char *priority;
  9435. + char *source;
  9436. + conffile_list_t conffiles;
  9437. + time_t installed_time;
  9438. + /* As pointer for lazy evaluation */
  9439. + str_list_t *installed_files;
  9440. + /* XXX: CLEANUP: I'd like to perhaps come up with a better
  9441. + mechanism to avoid the problem here, (which is that the
  9442. + installed_files list was being freed from an inner loop while
  9443. + still being used within an outer loop. */
  9444. + int installed_files_ref_cnt;
  9445. + int essential;
  9446. + int arch_priority;
  9447. +/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */
  9448. + int provided_by_hand;
  9449. +};
  9450. +
  9451. +pkg_t *pkg_new(void);
  9452. +int pkg_init(pkg_t *pkg);
  9453. +void pkg_deinit(pkg_t *pkg);
  9454. +int pkg_init_from_file(pkg_t *pkg, const char *filename);
  9455. +abstract_pkg_t *abstract_pkg_new(void);
  9456. +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
  9457. +
  9458. +/*
  9459. + * merges fields from newpkg into oldpkg.
  9460. + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
  9461. + */
  9462. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
  9463. +
  9464. +char *pkg_version_str_alloc(pkg_t *pkg);
  9465. +
  9466. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
  9467. +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b);
  9468. +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b);
  9469. +
  9470. +char * pkg_formatted_info(pkg_t *pkg );
  9471. +char * pkg_formatted_field(pkg_t *pkg, const char *field );
  9472. +
  9473. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
  9474. +
  9475. +void pkg_print_info(pkg_t *pkg, FILE *file);
  9476. +void pkg_print_status(pkg_t * pkg, FILE * file);
  9477. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
  9478. +str_list_t *pkg_get_installed_files(pkg_t *pkg);
  9479. +int pkg_free_installed_files(pkg_t *pkg);
  9480. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
  9481. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
  9482. +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
  9483. + const char *script, const char *args);
  9484. +
  9485. +/* enum mappings */
  9486. +char *pkg_state_want_to_str(pkg_state_want_t sw);
  9487. +pkg_state_want_t pkg_state_want_from_str(char *str);
  9488. +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
  9489. +pkg_state_flag_t pkg_state_flag_from_str(char *str);
  9490. +char *pkg_state_status_to_str(pkg_state_status_t ss);
  9491. +pkg_state_status_t pkg_state_status_from_str(char *str);
  9492. +
  9493. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
  9494. +
  9495. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
  9496. +int pkg_info_preinstall_check(ipkg_conf_t *conf);
  9497. +int pkg_free_installed_files(pkg_t *pkg);
  9498. +
  9499. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
  9500. +int pkg_write_changed_filelists(ipkg_conf_t *conf);
  9501. +
  9502. +#endif
  9503. --- /dev/null
  9504. +++ busybox-1.18.1/archival/libipkg/pkg_depends.c
  9505. @@ -0,0 +1,1032 @@
  9506. +/* pkg_depends.c - the itsy package management system
  9507. +
  9508. + Steven M. Ayer
  9509. +
  9510. + Copyright (C) 2002 Compaq Computer Corporation
  9511. +
  9512. + This program is free software; you can redistribute it and/or
  9513. + modify it under the terms of the GNU General Public License as
  9514. + published by the Free Software Foundation; either version 2, or (at
  9515. + your option) any later version.
  9516. +
  9517. + This program is distributed in the hope that it will be useful, but
  9518. + WITHOUT ANY WARRANTY; without even the implied warranty of
  9519. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9520. + General Public License for more details.
  9521. +*/
  9522. +
  9523. +#include "ipkg.h"
  9524. +#include <errno.h>
  9525. +#include <ctype.h>
  9526. +
  9527. +#include "pkg.h"
  9528. +#include "ipkg_utils.h"
  9529. +#include "pkg_hash.h"
  9530. +#include "ipkg_message.h"
  9531. +#include "pkg_parse.h"
  9532. +#include "hash_table.h"
  9533. +
  9534. +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
  9535. +static depend_t * depend_init(void);
  9536. +static void depend_deinit(depend_t *d);
  9537. +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
  9538. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
  9539. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
  9540. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg);
  9541. +
  9542. +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
  9543. +{
  9544. + depend_t *depend = (depend_t *)cdata;
  9545. + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
  9546. + return 1;
  9547. + else
  9548. + return 0;
  9549. +}
  9550. +
  9551. +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
  9552. +{
  9553. + depend_t *depend = (depend_t *)cdata;
  9554. +#if 0
  9555. + pkg_t * temp = pkg_new();
  9556. + int comparison;
  9557. + parseVersion(temp, depend->version);
  9558. + comparison = pkg_compare_versions(pkg, temp);
  9559. + free(temp);
  9560. +
  9561. + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
  9562. + __FUNCTION__, pkg->name, pkg->version,
  9563. + depend, depend->constraint, depend->version,
  9564. + comparison, version_constraints_satisfied(depend, pkg));
  9565. +#endif
  9566. + if (version_constraints_satisfied(depend, pkg))
  9567. + return 1;
  9568. + else
  9569. + return 0;
  9570. +}
  9571. +
  9572. +/* returns ndependences or negative error value */
  9573. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
  9574. + pkg_vec_t *unsatisfied, char *** unresolved)
  9575. +{
  9576. + pkg_t * satisfier_entry_pkg;
  9577. + register int i, j, k, l;
  9578. + int count, found;
  9579. + char ** the_lost;
  9580. + abstract_pkg_t * ab_pkg;
  9581. +
  9582. + /*
  9583. + * this is a setup to check for redundant/cyclic dependency checks,
  9584. + * which are marked at the abstract_pkg level
  9585. + */
  9586. + if (!(ab_pkg = pkg->parent)) {
  9587. + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
  9588. + *unresolved = NULL;
  9589. + return 0;
  9590. + }
  9591. + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
  9592. + *unresolved = NULL;
  9593. + return 0;
  9594. + } else {
  9595. + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
  9596. + }
  9597. + /**/
  9598. +
  9599. + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
  9600. + if (!count){
  9601. + *unresolved = NULL;
  9602. + return 0;
  9603. + }
  9604. +
  9605. + the_lost = NULL;
  9606. +
  9607. + /* foreach dependency */
  9608. + for (i = 0; i < count; i++) {
  9609. + compound_depend_t * compound_depend = &pkg->depends[i];
  9610. + depend_t ** possible_satisfiers = compound_depend->possibilities;;
  9611. + found = 0;
  9612. + satisfier_entry_pkg = NULL;
  9613. +
  9614. + if (compound_depend->type == GREEDY_DEPEND) {
  9615. + /* foreach possible satisfier */
  9616. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9617. + /* foreach provided_by, which includes the abstract_pkg itself */
  9618. + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
  9619. + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
  9620. + int nposs = ab_provider_vec->len;
  9621. + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
  9622. + for (l = 0; l < nposs; l++) {
  9623. + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
  9624. + /* if no depends on this one, try the first package that Provides this one */
  9625. + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
  9626. + continue;
  9627. + }
  9628. +
  9629. + /* cruise this possiblity's pkg_vec looking for an installed version */
  9630. + for (k = 0; k < test_vec->len; k++) {
  9631. + pkg_t *pkg_scout = test_vec->pkgs[k];
  9632. + /* not installed, and not already known about? */
  9633. + if ((pkg_scout->state_want != SW_INSTALL)
  9634. + && !pkg_scout->parent->dependencies_checked
  9635. + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
  9636. + char ** newstuff = NULL;
  9637. + int rc;
  9638. + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
  9639. + /* check for not-already-installed dependencies */
  9640. + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
  9641. + pkg_scout,
  9642. + tmp_vec,
  9643. + &newstuff);
  9644. + if (newstuff == NULL) {
  9645. + int ok = 1;
  9646. + for (i = 0; i < rc; i++) {
  9647. + pkg_t *p = tmp_vec->pkgs[i];
  9648. + if (p->state_want == SW_INSTALL)
  9649. + continue;
  9650. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
  9651. + ok = 0;
  9652. + break;
  9653. + }
  9654. + pkg_vec_free (tmp_vec);
  9655. + if (ok) {
  9656. + /* mark this one for installation */
  9657. + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
  9658. + pkg_vec_insert(unsatisfied, pkg_scout);
  9659. + }
  9660. + } else {
  9661. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
  9662. + free (newstuff);
  9663. + }
  9664. + }
  9665. + }
  9666. + }
  9667. + }
  9668. +
  9669. + continue;
  9670. + }
  9671. +
  9672. + /* foreach possible satisfier, look for installed package */
  9673. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9674. + /* foreach provided_by, which includes the abstract_pkg itself */
  9675. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9676. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9677. + pkg_t *satisfying_pkg =
  9678. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9679. + pkg_installed_and_constraint_satisfied,
  9680. + dependence_to_satisfy, 1);
  9681. + /* Being that I can't test constraing in pkg_hash, I will test it here */
  9682. + if (satisfying_pkg != NULL) {
  9683. + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9684. + satisfying_pkg = NULL;
  9685. + }
  9686. + }
  9687. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
  9688. + if (satisfying_pkg != NULL) {
  9689. + found = 1;
  9690. + break;
  9691. + }
  9692. +
  9693. + }
  9694. + /* if nothing installed matches, then look for uninstalled satisfier */
  9695. + if (!found) {
  9696. + /* foreach possible satisfier, look for installed package */
  9697. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9698. + /* foreach provided_by, which includes the abstract_pkg itself */
  9699. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9700. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9701. + pkg_t *satisfying_pkg =
  9702. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9703. + pkg_constraint_satisfied,
  9704. + dependence_to_satisfy, 1);
  9705. + /* Being that I can't test constraing in pkg_hash, I will test it here too */
  9706. + if (satisfying_pkg != NULL) {
  9707. + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9708. + satisfying_pkg = NULL;
  9709. + }
  9710. + }
  9711. +
  9712. + /* user request overrides package recommendation */
  9713. + if (satisfying_pkg != NULL
  9714. + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
  9715. + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
  9716. + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
  9717. + pkg->name, satisfying_pkg->name);
  9718. + continue;
  9719. + }
  9720. +
  9721. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
  9722. + if (satisfying_pkg != NULL) {
  9723. + satisfier_entry_pkg = satisfying_pkg;
  9724. + break;
  9725. + }
  9726. + }
  9727. + }
  9728. +
  9729. + /* we didn't find one, add something to the unsatisfied vector */
  9730. + if (!found) {
  9731. + if (!satisfier_entry_pkg) {
  9732. + /* failure to meet recommendations is not an error */
  9733. + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
  9734. + the_lost = add_unresolved_dep(pkg, the_lost, i);
  9735. + else
  9736. + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
  9737. + pkg->name, compound_depend->possibilities[0]->pkg->name);
  9738. + }
  9739. + else {
  9740. + if (compound_depend->type == SUGGEST) {
  9741. + /* just mention it politely */
  9742. + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
  9743. + pkg->name, satisfier_entry_pkg->name);
  9744. + } else {
  9745. + char ** newstuff = NULL;
  9746. +
  9747. + if (satisfier_entry_pkg != pkg &&
  9748. + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
  9749. + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
  9750. + pkg_hash_fetch_unsatisfied_dependencies(conf,
  9751. + satisfier_entry_pkg,
  9752. + unsatisfied,
  9753. + &newstuff);
  9754. + the_lost = merge_unresolved(the_lost, newstuff);
  9755. + }
  9756. + }
  9757. + }
  9758. + }
  9759. + }
  9760. + *unresolved = the_lost;
  9761. +
  9762. + return unsatisfied->len;
  9763. +}
  9764. +
  9765. +/*checking for conflicts !in replaces
  9766. + If a packages conflicts with another but is also replacing it, I should not consider it a
  9767. + really conflicts
  9768. + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
  9769. +*/
  9770. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
  9771. +{
  9772. + int i ;
  9773. + int replaces_count = pkg->replaces_count;
  9774. + abstract_pkg_t **replaces;
  9775. +
  9776. + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
  9777. + return 0;
  9778. +
  9779. + replaces = pkg->replaces;
  9780. +
  9781. + for (i = 0; i < replaces_count; i++) {
  9782. + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
  9783. + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
  9784. + return 1;
  9785. + }
  9786. + }
  9787. + return 0;
  9788. +
  9789. +}
  9790. +
  9791. +
  9792. +/* Abhaya: added support for conflicts */
  9793. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg)
  9794. +{
  9795. + pkg_vec_t * installed_conflicts, * test_vec;
  9796. + compound_depend_t * conflicts;
  9797. + depend_t ** possible_satisfiers;
  9798. + depend_t * possible_satisfier;
  9799. + register int i, j, k;
  9800. + int count;
  9801. + abstract_pkg_t * ab_pkg;
  9802. + pkg_t **pkg_scouts;
  9803. + pkg_t *pkg_scout;
  9804. +
  9805. + /*
  9806. + * this is a setup to check for redundant/cyclic dependency checks,
  9807. + * which are marked at the abstract_pkg level
  9808. + */
  9809. + if(!(ab_pkg = pkg->parent)){
  9810. + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
  9811. + return (pkg_vec_t *)NULL;
  9812. + }
  9813. +
  9814. + conflicts = pkg->conflicts;
  9815. + if(!conflicts){
  9816. + return (pkg_vec_t *)NULL;
  9817. + }
  9818. + installed_conflicts = pkg_vec_alloc();
  9819. +
  9820. + count = pkg->conflicts_count;
  9821. +
  9822. +
  9823. +
  9824. + /* foreach conflict */
  9825. + for(i = 0; i < pkg->conflicts_count; i++){
  9826. +
  9827. + possible_satisfiers = conflicts->possibilities;
  9828. +
  9829. + /* foreach possible satisfier */
  9830. + for(j = 0; j < conflicts->possibility_count; j++){
  9831. + possible_satisfier = possible_satisfiers[j];
  9832. + if (!possible_satisfier)
  9833. + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
  9834. + if (!possible_satisfier->pkg)
  9835. + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
  9836. + test_vec = possible_satisfier->pkg->pkgs;
  9837. + if (test_vec) {
  9838. + /* pkg_vec found, it is an actual package conflict
  9839. + * cruise this possiblity's pkg_vec looking for an installed version */
  9840. + pkg_scouts = test_vec->pkgs;
  9841. + for(k = 0; k < test_vec->len; k++){
  9842. + pkg_scout = pkg_scouts[k];
  9843. + if (!pkg_scout) {
  9844. + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
  9845. + continue;
  9846. + }
  9847. + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
  9848. + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
  9849. + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
  9850. + pkg_vec_insert(installed_conflicts, pkg_scout);
  9851. + }
  9852. + }
  9853. + }
  9854. + }
  9855. + }
  9856. + conflicts++;
  9857. + }
  9858. +
  9859. + if (installed_conflicts->len)
  9860. + return installed_conflicts;
  9861. + pkg_vec_free(installed_conflicts);
  9862. + return (pkg_vec_t *)NULL;
  9863. +}
  9864. +
  9865. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
  9866. +{
  9867. + pkg_t * temp;
  9868. + int comparison;
  9869. +
  9870. + if(depends->constraint == NONE)
  9871. + return 1;
  9872. +
  9873. + temp = pkg_new();
  9874. +
  9875. + parseVersion(temp, depends->version);
  9876. +
  9877. + comparison = pkg_compare_versions(pkg, temp);
  9878. +
  9879. + free(temp);
  9880. +
  9881. + if((depends->constraint == EARLIER) &&
  9882. + (comparison < 0))
  9883. + return 1;
  9884. + else if((depends->constraint == LATER) &&
  9885. + (comparison > 0))
  9886. + return 1;
  9887. + else if(comparison == 0)
  9888. + return 1;
  9889. + else if((depends->constraint == LATER_EQUAL) &&
  9890. + (comparison >= 0))
  9891. + return 1;
  9892. + else if((depends->constraint == EARLIER_EQUAL) &&
  9893. + (comparison <= 0))
  9894. + return 1;
  9895. +
  9896. + return 0;
  9897. +}
  9898. +
  9899. +int pkg_dependence_satisfiable(depend_t *depend)
  9900. +{
  9901. + abstract_pkg_t *apkg = depend->pkg;
  9902. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9903. + int n_providers = provider_apkgs->len;
  9904. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9905. + pkg_vec_t *pkg_vec;
  9906. + int n_pkgs ;
  9907. + int i;
  9908. + int j;
  9909. +
  9910. + for (i = 0; i < n_providers; i++) {
  9911. + abstract_pkg_t *papkg = apkgs[i];
  9912. + pkg_vec = papkg->pkgs;
  9913. + if (pkg_vec) {
  9914. + n_pkgs = pkg_vec->len;
  9915. + for (j = 0; j < n_pkgs; j++) {
  9916. + pkg_t *pkg = pkg_vec->pkgs[j];
  9917. + if (version_constraints_satisfied(depend, pkg)) {
  9918. + return 1;
  9919. + }
  9920. + }
  9921. + }
  9922. + }
  9923. + return 0;
  9924. +}
  9925. +
  9926. +int pkg_dependence_satisfied(depend_t *depend)
  9927. +{
  9928. + abstract_pkg_t *apkg = depend->pkg;
  9929. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9930. + int n_providers = provider_apkgs->len;
  9931. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9932. + int i;
  9933. + int n_pkgs;
  9934. + int j;
  9935. +
  9936. + for (i = 0; i < n_providers; i++) {
  9937. + abstract_pkg_t *papkg = apkgs[i];
  9938. + pkg_vec_t *pkg_vec = papkg->pkgs;
  9939. + if (pkg_vec) {
  9940. + n_pkgs = pkg_vec->len;
  9941. + for (j = 0; j < n_pkgs; j++) {
  9942. + pkg_t *pkg = pkg_vec->pkgs[j];
  9943. + if (version_constraints_satisfied(depend, pkg)) {
  9944. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
  9945. + return 1;
  9946. + }
  9947. + }
  9948. + }
  9949. + }
  9950. + return 0;
  9951. +}
  9952. +
  9953. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
  9954. +{
  9955. + register int i;
  9956. + pkg_t ** pkgs = vec->pkgs;
  9957. +
  9958. + for(i = 0; i < vec->len; i++)
  9959. + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
  9960. + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
  9961. + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
  9962. + return 1;
  9963. + return 0;
  9964. +}
  9965. +
  9966. +
  9967. +#ifdef DeadCode
  9968. +/**
  9969. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  9970. + * the same abstract package and 0 otherwise.
  9971. + */
  9972. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
  9973. +{
  9974. + abstract_pkg_t **provides = pkg->provides;
  9975. + int provides_count = pkg->provides_count;
  9976. + abstract_pkg_t **replacee_provides = replacee->provides;
  9977. + int replacee_provides_count = replacee->provides_count;
  9978. + int i, j;
  9979. + for (i = 0; i < provides_count; i++) {
  9980. + abstract_pkg_t *apkg = provides[i];
  9981. + for (j = 0; j < replacee_provides_count; j++) {
  9982. + abstract_pkg_t *replacee_apkg = replacee_provides[i];
  9983. + if (apkg == replacee_apkg)
  9984. + return 1;
  9985. + }
  9986. + }
  9987. + return 0;
  9988. +}
  9989. +#endif
  9990. +
  9991. +/**
  9992. + * pkg_provides_abstract returns 1 if pkg->provides contains providee
  9993. + * and 0 otherwise.
  9994. + */
  9995. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
  9996. +{
  9997. + abstract_pkg_t **provides = pkg->provides;
  9998. + int provides_count = pkg->provides_count;
  9999. + int i;
  10000. + for (i = 0; i < provides_count; i++) {
  10001. + if (provides[i] == providee)
  10002. + return 1;
  10003. + }
  10004. + return 0;
  10005. +}
  10006. +
  10007. +/**
  10008. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  10009. + * otherwise.
  10010. + */
  10011. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
  10012. +{
  10013. + abstract_pkg_t **replaces = pkg->replaces;
  10014. + int replaces_count = pkg->replaces_count;
  10015. + /* abstract_pkg_t **replacee_provides = pkg->provides;
  10016. + int replacee_provides_count = pkg->provides_count; */
  10017. + int i, j;
  10018. + for (i = 0; i < replaces_count; i++) {
  10019. + abstract_pkg_t *abstract_replacee = replaces[i];
  10020. + for (j = 0; j < replaces_count; j++) {
  10021. + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
  10022. + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
  10023. + if (replacee->provides[j] == abstract_replacee)
  10024. + return 1;
  10025. + }
  10026. + }
  10027. + return 0;
  10028. +}
  10029. +
  10030. +
  10031. +/**
  10032. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
  10033. + * otherwise.
  10034. + */
  10035. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
  10036. +{
  10037. + compound_depend_t *conflicts = pkg->conflicts;
  10038. + int conflicts_count = pkg->conflicts_count;
  10039. + int i, j;
  10040. + for (i = 0; i < conflicts_count; i++) {
  10041. + int possibility_count = conflicts[i].possibility_count;
  10042. + struct depend **possibilities = conflicts[i].possibilities;
  10043. + for (j = 0; j < possibility_count; j++) {
  10044. + if (possibilities[j]->pkg == conflictee) {
  10045. + return 1;
  10046. + }
  10047. + }
  10048. + }
  10049. + return 0;
  10050. +}
  10051. +
  10052. +/**
  10053. + * pkg_conflicts returns 1 if pkg->conflicts contains one of
  10054. + * conflictee's provides and 0 otherwise.
  10055. + */
  10056. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
  10057. +{
  10058. + compound_depend_t *conflicts = pkg->conflicts;
  10059. + int conflicts_count = pkg->conflicts_count;
  10060. + abstract_pkg_t **conflictee_provides = conflictee->provides;
  10061. + int conflictee_provides_count = conflictee->provides_count;
  10062. + int i, j, k;
  10063. + int possibility_count;
  10064. + struct depend **possibilities;
  10065. + abstract_pkg_t *possibility ;
  10066. +
  10067. + for (i = 0; i < conflicts_count; i++) {
  10068. + possibility_count = conflicts[i].possibility_count;
  10069. + possibilities = conflicts[i].possibilities;
  10070. + for (j = 0; j < possibility_count; j++) {
  10071. + possibility = possibilities[j]->pkg;
  10072. + for (k = 0; k < conflictee_provides_count; k++) {
  10073. + if (possibility == conflictee_provides[k]) {
  10074. + return 1;
  10075. + }
  10076. + }
  10077. + }
  10078. + }
  10079. + return 0;
  10080. +}
  10081. +
  10082. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
  10083. +{
  10084. + int oldlen = 0, newlen = 0;
  10085. + char ** result;
  10086. + register int i, j;
  10087. +
  10088. + if(!newstuff)
  10089. + return oldstuff;
  10090. +
  10091. + while(oldstuff && oldstuff[oldlen]) oldlen++;
  10092. + while(newstuff && newstuff[newlen]) newlen++;
  10093. +
  10094. + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
  10095. + if (result == NULL) {
  10096. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10097. + return NULL;
  10098. + }
  10099. +
  10100. + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
  10101. + *(result + i) = *(newstuff + j);
  10102. +
  10103. + *(result + i) = NULL;
  10104. +
  10105. + return result;
  10106. +}
  10107. +
  10108. +/*
  10109. + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
  10110. + * this is null terminated, no count is carried around
  10111. + */
  10112. +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
  10113. +{
  10114. + int count;
  10115. + char ** resized;
  10116. + char *depend_str = pkg_depend_str(pkg, ref_ndx);
  10117. +
  10118. + count = 0;
  10119. + while(the_lost && the_lost[count]) count++;
  10120. +
  10121. + count++; /* need one to hold the null */
  10122. + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
  10123. + if (resized == NULL) {
  10124. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10125. + return NULL;
  10126. + }
  10127. + resized[count - 1] = strdup(depend_str);
  10128. + resized[count] = NULL;
  10129. +
  10130. + return resized;
  10131. +}
  10132. +
  10133. +void printDepends(pkg_t * pkg)
  10134. +{
  10135. + register int i, j;
  10136. + compound_depend_t * depend;
  10137. + int count;
  10138. +
  10139. + count = pkg->pre_depends_count + pkg->depends_count;
  10140. +
  10141. + depend = pkg->depends;
  10142. + if(!depend){
  10143. + fprintf(stderr, "Depends pointer is NULL\n");
  10144. + return;
  10145. + }
  10146. + for(i = 0; i < count; i++){
  10147. + fprintf(stderr, "%s has %d possibilities:\n",
  10148. + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
  10149. + depend->possibility_count);
  10150. + for(j = 0; j < depend->possibility_count; j++)
  10151. + fprintf(stderr, "\t%s version %s (%d)\n",
  10152. + depend->possibilities[j]->pkg->name,
  10153. + depend->possibilities[j]->version,
  10154. + depend->possibilities[j]->constraint);
  10155. + depend++;
  10156. + }
  10157. +}
  10158. +
  10159. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  10160. +{
  10161. + register int i, j;
  10162. +
  10163. + /* every pkg provides itself */
  10164. + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
  10165. +
  10166. + if (!pkg->provides_count)
  10167. + return 0;
  10168. +
  10169. + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
  10170. + if (pkg->provides == NULL) {
  10171. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10172. + return -1 ;
  10173. + }
  10174. + pkg->provides[0] = ab_pkg;
  10175. +
  10176. + // if (strcmp(ab_pkg->name, pkg->name))
  10177. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  10178. +
  10179. + for(i = 0; i < pkg->provides_count; i++){
  10180. + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
  10181. +
  10182. + pkg->provides[i+1] = provided_abpkg;
  10183. +
  10184. + j = 0;
  10185. + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
  10186. + }
  10187. + return 0;
  10188. +}
  10189. +
  10190. +/* Abhaya: added conflicts support */
  10191. +int buildConflicts(hash_table_t * hash, pkg_t * pkg)
  10192. +{
  10193. + register int i;
  10194. + compound_depend_t * conflicts;
  10195. +
  10196. + if (!pkg->conflicts_count)
  10197. + return 0;
  10198. +
  10199. + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
  10200. + pkg->conflicts_count);
  10201. + if (conflicts == NULL) {
  10202. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10203. + return -1;
  10204. + }
  10205. + for (i = 0; i < pkg->conflicts_count; i++) {
  10206. + conflicts->type = CONFLICTS;
  10207. + parseDepends(conflicts, hash,
  10208. + pkg->conflicts_str[i]);
  10209. +#if 0
  10210. + for (j = 0; j < conflicts->possibility_count; j++) {
  10211. + depend_t *possibility = conflicts->possibilities[j];
  10212. + abstract_pkg_t *conflicting_apkg = possibility->pkg;
  10213. + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
  10214. + }
  10215. +#endif
  10216. + conflicts++;
  10217. + }
  10218. + return 0;
  10219. +}
  10220. +
  10221. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  10222. +{
  10223. + register int i, j;
  10224. +
  10225. + if (!pkg->replaces_count)
  10226. + return 0;
  10227. +
  10228. + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
  10229. + if (pkg->replaces == NULL) {
  10230. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10231. + return -1;
  10232. + }
  10233. +
  10234. + // if (strcmp(ab_pkg->name, pkg->name))
  10235. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  10236. +
  10237. + for(i = 0; i < pkg->replaces_count; i++){
  10238. + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
  10239. +
  10240. + pkg->replaces[i] = old_abpkg;
  10241. +
  10242. + j = 0;
  10243. + if (!old_abpkg->replaced_by)
  10244. + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
  10245. + if ( old_abpkg->replaced_by == NULL ){
  10246. + return -1;
  10247. + }
  10248. + /* if a package pkg both replaces and conflicts old_abpkg,
  10249. + * then add it to the replaced_by vector so that old_abpkg
  10250. + * will be upgraded to ab_pkg automatically */
  10251. + if (pkg_conflicts_abstract(pkg, old_abpkg))
  10252. + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
  10253. + }
  10254. + return 0;
  10255. +}
  10256. +
  10257. +int buildDepends(hash_table_t * hash, pkg_t * pkg)
  10258. +{
  10259. + int count;
  10260. + register int i;
  10261. + compound_depend_t * depends;
  10262. +
  10263. + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
  10264. + return 0;
  10265. +
  10266. + if (0 && pkg->pre_depends_count)
  10267. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10268. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10269. + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
  10270. + if (depends == NULL) {
  10271. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10272. + return -1;
  10273. + }
  10274. +
  10275. +
  10276. + for(i = 0; i < pkg->pre_depends_count; i++){
  10277. + parseDepends(depends, hash, pkg->pre_depends_str[i]);
  10278. + if (0 && pkg->pre_depends_count)
  10279. + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
  10280. + pkg->pre_depends_str[i], depends, depends->possibility_count);
  10281. + depends->type = PREDEPEND;
  10282. + depends++;
  10283. + }
  10284. +
  10285. + for(i = 0; i < pkg->recommends_count; i++){
  10286. + parseDepends(depends, hash, pkg->recommends_str[i]);
  10287. + if (0 && pkg->recommends_count)
  10288. + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
  10289. + pkg->recommends_str[i], depends, depends->possibility_count);
  10290. + depends->type = RECOMMEND;
  10291. + depends++;
  10292. + }
  10293. +
  10294. + for(i = 0; i < pkg->suggests_count; i++){
  10295. + parseDepends(depends, hash, pkg->suggests_str[i]);
  10296. + if (0 && pkg->suggests_count)
  10297. + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
  10298. + pkg->suggests_str[i], depends, depends->possibility_count);
  10299. + depends->type = SUGGEST;
  10300. + depends++;
  10301. + }
  10302. +
  10303. + for(i = 0; i < pkg->depends_count; i++){
  10304. + parseDepends(depends, hash, pkg->depends_str[i]);
  10305. + if (0 && pkg->depends_count)
  10306. + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
  10307. + pkg->depends_str[i], depends, depends->possibility_count);
  10308. + depends++;
  10309. + }
  10310. + return 0;
  10311. +}
  10312. +
  10313. +/*
  10314. + * pkg_depend_string: returns the depends string specified by index_.
  10315. + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
  10316. + * [0,npredepends) -> returns pre_depends_str[index_]
  10317. + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index_]
  10318. + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index_]
  10319. + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index_]
  10320. + */
  10321. +char *pkg_depend_str(pkg_t *pkg, int index_)
  10322. +{
  10323. + if (index_ < pkg->pre_depends_count) {
  10324. + return pkg->pre_depends_str[index_];
  10325. + }
  10326. + index_ -= pkg->pre_depends_count;
  10327. +
  10328. + if (index_ < pkg->recommends_count) {
  10329. + return pkg->recommends_str[index_];
  10330. + }
  10331. + index_ -= pkg->recommends_count;
  10332. +
  10333. + if (index_ < pkg->suggests_count) {
  10334. + return pkg->suggests_str[index_];
  10335. + }
  10336. + index_ -= pkg->suggests_count;
  10337. +
  10338. + if (index_ < pkg->depends_count) {
  10339. + return pkg->depends_str[index_];
  10340. + }
  10341. + fprintf(stderr, "pkg_depend_str: index_ %d out of range for pkg=%s\n", index_, pkg->name);
  10342. + return NULL;
  10343. +}
  10344. +
  10345. +void freeDepends(pkg_t *pkg)
  10346. +{
  10347. + int i;
  10348. +
  10349. + if (pkg == NULL || pkg->depends == NULL) {
  10350. + return;
  10351. + }
  10352. +
  10353. + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
  10354. + for (i=0; i < pkg->depends->possibility_count; i++) {
  10355. + depend_deinit(pkg->depends->possibilities[i]);
  10356. + }
  10357. + free(pkg->depends->possibilities);
  10358. + free(pkg->depends);
  10359. + pkg->depends = NULL;
  10360. +}
  10361. +
  10362. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
  10363. +{
  10364. + compound_depend_t * depends;
  10365. + int count, othercount;
  10366. + register int i, j;
  10367. + abstract_pkg_t * ab_depend;
  10368. + abstract_pkg_t ** temp;
  10369. +
  10370. + count = pkg->pre_depends_count + pkg->depends_count;
  10371. + depends = pkg->depends;
  10372. +
  10373. + if (0 && pkg->pre_depends_count)
  10374. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10375. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10376. + for (i = 0; i < count; i++) {
  10377. + if (0 && pkg->pre_depends_count)
  10378. + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
  10379. + for (j = 0; j < depends->possibility_count; j++){
  10380. + ab_depend = depends->possibilities[j]->pkg;
  10381. + if(!ab_depend->depended_upon_by)
  10382. + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
  10383. +
  10384. + temp = ab_depend->depended_upon_by;
  10385. + othercount = 1;
  10386. + while(*temp){
  10387. + temp++;
  10388. + othercount++;
  10389. + }
  10390. + *temp = ab_pkg;
  10391. +
  10392. + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
  10393. + (othercount + 1) * sizeof(abstract_pkg_t *));
  10394. + /* the array may have moved */
  10395. + temp = ab_depend->depended_upon_by + othercount;
  10396. + *temp = NULL;
  10397. + }
  10398. + depends++;
  10399. + }
  10400. +}
  10401. +
  10402. +static depend_t * depend_init(void)
  10403. +{
  10404. + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
  10405. + if ( d==NULL ){
  10406. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10407. + return NULL;
  10408. + }
  10409. + d->constraint = NONE;
  10410. + d->version = NULL;
  10411. + d->pkg = NULL;
  10412. +
  10413. + return d;
  10414. +}
  10415. +
  10416. +static void depend_deinit(depend_t *d)
  10417. +{
  10418. + free(d);
  10419. +}
  10420. +
  10421. +static int parseDepends(compound_depend_t *compound_depend,
  10422. + hash_table_t * hash, char * depend_str)
  10423. +{
  10424. + char * pkg_name, buffer[2048];
  10425. + int num_of_ors = 0;
  10426. + register int i;
  10427. + register char * src, * dest;
  10428. + depend_t ** possibilities;
  10429. +
  10430. + /* first count the number of ored possibilities for satisfying dependency */
  10431. + src = depend_str;
  10432. + while(*src)
  10433. + if(*src++ == '|')
  10434. + num_of_ors++;
  10435. +
  10436. + compound_depend->type = DEPEND;
  10437. +
  10438. + compound_depend->possibility_count = num_of_ors + 1;
  10439. + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
  10440. + if (!possibilities)
  10441. + return -ENOMEM;
  10442. + compound_depend->possibilities = possibilities;
  10443. +
  10444. + src = depend_str;
  10445. + for(i = 0; i < num_of_ors + 1; i++){
  10446. + possibilities[i] = depend_init();
  10447. + if (!possibilities[i])
  10448. + return -ENOMEM;
  10449. + /* gobble up just the name first */
  10450. + dest = buffer;
  10451. + while(*src &&
  10452. + !isspace(*src) &&
  10453. + (*src != '(') &&
  10454. + (*src != '*') &&
  10455. + (*src != '|'))
  10456. + *dest++ = *src++;
  10457. + *dest = '\0';
  10458. + pkg_name = trim_alloc(buffer);
  10459. + if (pkg_name == NULL )
  10460. + return -ENOMEM;
  10461. +
  10462. + /* now look at possible version info */
  10463. +
  10464. + /* skip to next chars */
  10465. + if(isspace(*src))
  10466. + while(*src && isspace(*src)) src++;
  10467. +
  10468. + /* extract constraint and version */
  10469. + if(*src == '('){
  10470. + src++;
  10471. + if(!strncmp(src, "<<", 2)){
  10472. + possibilities[i]->constraint = EARLIER;
  10473. + src += 2;
  10474. + }
  10475. + else if(!strncmp(src, "<=", 2)){
  10476. + possibilities[i]->constraint = EARLIER_EQUAL;
  10477. + src += 2;
  10478. + }
  10479. + else if(!strncmp(src, ">=", 2)){
  10480. + possibilities[i]->constraint = LATER_EQUAL;
  10481. + src += 2;
  10482. + }
  10483. + else if(!strncmp(src, ">>", 2)){
  10484. + possibilities[i]->constraint = LATER;
  10485. + src += 2;
  10486. + }
  10487. + else if(!strncmp(src, "=", 1)){
  10488. + possibilities[i]->constraint = EQUAL;
  10489. + src++;
  10490. + }
  10491. + /* should these be here to support deprecated designations; dpkg does */
  10492. + else if(!strncmp(src, "<", 1)){
  10493. + possibilities[i]->constraint = EARLIER_EQUAL;
  10494. + src++;
  10495. + }
  10496. + else if(!strncmp(src, ">", 1)){
  10497. + possibilities[i]->constraint = LATER_EQUAL;
  10498. + src++;
  10499. + }
  10500. +
  10501. + /* now we have any constraint, pass space to version string */
  10502. + while(isspace(*src)) src++;
  10503. +
  10504. + /* this would be the version string */
  10505. + dest = buffer;
  10506. + while(*src && *src != ')')
  10507. + *dest++ = *src++;
  10508. + *dest = '\0';
  10509. +
  10510. + possibilities[i]->version = trim_alloc(buffer);
  10511. + /* fprintf(stderr, "let's print the depends version string:");
  10512. + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
  10513. + if (possibilities[i]->version == NULL )
  10514. + return -ENOMEM;
  10515. +
  10516. +
  10517. + }
  10518. + /* hook up the dependency to its abstract pkg */
  10519. + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
  10520. +
  10521. + free(pkg_name);
  10522. +
  10523. + /* now get past the ) and any possible | chars */
  10524. + while(*src &&
  10525. + (isspace(*src) ||
  10526. + (*src == ')') ||
  10527. + (*src == '|')))
  10528. + src++;
  10529. + if (*src == '*')
  10530. + {
  10531. + compound_depend->type = GREEDY_DEPEND;
  10532. + src++;
  10533. + }
  10534. + }
  10535. +
  10536. + return 0;
  10537. +}
  10538. --- /dev/null
  10539. +++ busybox-1.18.1/archival/libipkg/pkg_depends.h
  10540. @@ -0,0 +1,105 @@
  10541. +/* pkg_depends.h - the itsy package management system
  10542. +
  10543. + Steven M. Ayer
  10544. +
  10545. + Copyright (C) 2002 Compaq Computer Corporation
  10546. +
  10547. + This program is free software; you can redistribute it and/or
  10548. + modify it under the terms of the GNU General Public License as
  10549. + published by the Free Software Foundation; either version 2, or (at
  10550. + your option) any later version.
  10551. +
  10552. + This program is distributed in the hope that it will be useful, but
  10553. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10554. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10555. + General Public License for more details.
  10556. +*/
  10557. +
  10558. +#ifndef PKG_DEPENDS_H
  10559. +#define PKG_DEPENDS_H
  10560. +
  10561. +#include "pkg.h"
  10562. +#include "pkg_hash.h"
  10563. +
  10564. +enum depend_type {
  10565. + PREDEPEND,
  10566. + DEPEND,
  10567. + CONFLICTS,
  10568. + GREEDY_DEPEND,
  10569. + RECOMMEND,
  10570. + SUGGEST
  10571. +};
  10572. +typedef enum depend_type depend_type_t;
  10573. +
  10574. +enum version_constraint {
  10575. + NONE,
  10576. + EARLIER,
  10577. + EARLIER_EQUAL,
  10578. + EQUAL,
  10579. + LATER_EQUAL,
  10580. + LATER
  10581. +};
  10582. +typedef enum version_constraint version_constraint_t;
  10583. +
  10584. +struct depend{
  10585. + version_constraint_t constraint;
  10586. + char * version;
  10587. + abstract_pkg_t * pkg;
  10588. +};
  10589. +typedef struct depend depend_t;
  10590. +
  10591. +struct compound_depend{
  10592. + depend_type_t type;
  10593. + int possibility_count;
  10594. + struct depend ** possibilities;
  10595. +};
  10596. +typedef struct compound_depend compound_depend_t;
  10597. +
  10598. +#include "hash_table.h"
  10599. +
  10600. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10601. +int buildConflicts(hash_table_t * hash, pkg_t * pkg);
  10602. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10603. +int buildDepends(hash_table_t * hash, pkg_t * pkg);
  10604. +
  10605. +/**
  10606. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  10607. + * the same abstract package and 0 otherwise.
  10608. + */
  10609. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
  10610. +
  10611. +/**
  10612. + * pkg_provides returns 1 if pkg->provides contains providee and 0
  10613. + * otherwise.
  10614. + */
  10615. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
  10616. +
  10617. +/**
  10618. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  10619. + * otherwise.
  10620. + */
  10621. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
  10622. +
  10623. +/**
  10624. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
  10625. + * otherwise.
  10626. + */
  10627. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
  10628. +
  10629. +/**
  10630. + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
  10631. + * otherwise.
  10632. + */
  10633. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
  10634. +
  10635. +char *pkg_depend_str(pkg_t *pkg, int index_);
  10636. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
  10637. +void freeDepends(pkg_t *pkg);
  10638. +void printDepends(pkg_t * pkg);
  10639. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
  10640. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
  10641. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg);
  10642. +int pkg_dependence_satisfiable(depend_t *depend);
  10643. +int pkg_dependence_satisfied(depend_t *depend);
  10644. +
  10645. +#endif
  10646. --- /dev/null
  10647. +++ busybox-1.18.1/archival/libipkg/pkg_dest.c
  10648. @@ -0,0 +1,92 @@
  10649. +/* pkg_dest.c - the itsy package management system
  10650. +
  10651. + Carl D. Worth
  10652. +
  10653. + Copyright (C) 2001 University of Southern California
  10654. +
  10655. + This program is free software; you can redistribute it and/or
  10656. + modify it under the terms of the GNU General Public License as
  10657. + published by the Free Software Foundation; either version 2, or (at
  10658. + your option) any later version.
  10659. +
  10660. + This program is distributed in the hope that it will be useful, but
  10661. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10662. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10663. + General Public License for more details.
  10664. +*/
  10665. +
  10666. +#include "ipkg.h"
  10667. +
  10668. +#include "pkg_dest.h"
  10669. +#include "file_util.h"
  10670. +#include "str_util.h"
  10671. +#include "sprintf_alloc.h"
  10672. +
  10673. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
  10674. +{
  10675. + dest->name = strdup(name);
  10676. +
  10677. + /* Guarantee that dest->root_dir ends with a '/' */
  10678. + if (str_ends_with(root_dir, "/")) {
  10679. + dest->root_dir = strdup(root_dir);
  10680. + } else {
  10681. + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
  10682. + }
  10683. + file_mkdir_hier(dest->root_dir, 0755);
  10684. +
  10685. + sprintf_alloc(&dest->ipkg_dir, "%s%s",
  10686. + dest->root_dir, IPKG_STATE_DIR_PREFIX);
  10687. + file_mkdir_hier(dest->ipkg_dir, 0755);
  10688. +
  10689. + if (str_starts_with (lists_dir, "/"))
  10690. + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
  10691. + else
  10692. + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
  10693. +
  10694. + file_mkdir_hier(dest->lists_dir, 0755);
  10695. +
  10696. + sprintf_alloc(&dest->info_dir, "%s/%s",
  10697. + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
  10698. + file_mkdir_hier(dest->info_dir, 0755);
  10699. +
  10700. + sprintf_alloc(&dest->status_file_name, "%s/%s",
  10701. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10702. +
  10703. + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
  10704. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10705. +
  10706. + dest->status_file = NULL;
  10707. +
  10708. + return 0;
  10709. +}
  10710. +
  10711. +void pkg_dest_deinit(pkg_dest_t *dest)
  10712. +{
  10713. + free(dest->name);
  10714. + dest->name = NULL;
  10715. +
  10716. + free(dest->root_dir);
  10717. + dest->root_dir = NULL;
  10718. +
  10719. + free(dest->ipkg_dir);
  10720. + dest->ipkg_dir = NULL;
  10721. +
  10722. + free(dest->lists_dir);
  10723. + dest->lists_dir = NULL;
  10724. +
  10725. + free(dest->info_dir);
  10726. + dest->info_dir = NULL;
  10727. +
  10728. + free(dest->status_file_name);
  10729. + dest->status_file_name = NULL;
  10730. +
  10731. + free(dest->status_file_tmp_name);
  10732. + dest->status_file_tmp_name = NULL;
  10733. +
  10734. + if (dest->status_file) {
  10735. + fclose(dest->status_file);
  10736. + }
  10737. + dest->status_file = NULL;
  10738. +
  10739. + dest->root_dir = NULL;
  10740. +}
  10741. --- /dev/null
  10742. +++ busybox-1.18.1/archival/libipkg/pkg_dest.h
  10743. @@ -0,0 +1,38 @@
  10744. +/* pkg_dest.h - the itsy package management system
  10745. +
  10746. + Carl D. Worth
  10747. +
  10748. + Copyright (C) 2001 University of Southern California
  10749. +
  10750. + This program is free software; you can redistribute it and/or
  10751. + modify it under the terms of the GNU General Public License as
  10752. + published by the Free Software Foundation; either version 2, or (at
  10753. + your option) any later version.
  10754. +
  10755. + This program is distributed in the hope that it will be useful, but
  10756. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10757. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10758. + General Public License for more details.
  10759. +*/
  10760. +
  10761. +#ifndef PKG_DEST_H
  10762. +#define PKG_DEST_H
  10763. +
  10764. +typedef struct pkg_dest pkg_dest_t;
  10765. +struct pkg_dest
  10766. +{
  10767. + char *name;
  10768. + char *root_dir;
  10769. + char *ipkg_dir;
  10770. + char *lists_dir;
  10771. + char *info_dir;
  10772. + char *status_file_name;
  10773. + char *status_file_tmp_name;
  10774. + FILE *status_file;
  10775. +};
  10776. +
  10777. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
  10778. +void pkg_dest_deinit(pkg_dest_t *dest);
  10779. +
  10780. +#endif
  10781. +
  10782. --- /dev/null
  10783. +++ busybox-1.18.1/archival/libipkg/pkg_dest_list.c
  10784. @@ -0,0 +1,85 @@
  10785. +/* pkg_dest_list.c - the itsy package management system
  10786. +
  10787. + Carl D. Worth
  10788. +
  10789. + Copyright (C) 2001 University of Southern California
  10790. +
  10791. + This program is free software; you can redistribute it and/or
  10792. + modify it under the terms of the GNU General Public License as
  10793. + published by the Free Software Foundation; either version 2, or (at
  10794. + your option) any later version.
  10795. +
  10796. + This program is distributed in the hope that it will be useful, but
  10797. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10798. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10799. + General Public License for more details.
  10800. +*/
  10801. +
  10802. +#include "ipkg.h"
  10803. +
  10804. +#include "pkg_dest.h"
  10805. +#include "void_list.h"
  10806. +#include "pkg_dest_list.h"
  10807. +
  10808. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
  10809. +{
  10810. + return void_list_elt_init((void_list_elt_t *) elt, data);
  10811. +}
  10812. +
  10813. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
  10814. +{
  10815. + void_list_elt_deinit((void_list_elt_t *) elt);
  10816. +}
  10817. +
  10818. +int pkg_dest_list_init(pkg_dest_list_t *list)
  10819. +{
  10820. + return void_list_init((void_list_t *) list);
  10821. +}
  10822. +
  10823. +void pkg_dest_list_deinit(pkg_dest_list_t *list)
  10824. +{
  10825. + pkg_dest_list_elt_t *iter;
  10826. + pkg_dest_t *pkg_dest;
  10827. +
  10828. + for (iter = list->head; iter; iter = iter->next) {
  10829. + pkg_dest = iter->data;
  10830. + pkg_dest_deinit(pkg_dest);
  10831. +
  10832. + /* malloced in pkg_dest_list_append */
  10833. + free(pkg_dest);
  10834. + iter->data = NULL;
  10835. + }
  10836. + void_list_deinit((void_list_t *) list);
  10837. +}
  10838. +
  10839. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10840. + const char *root_dir,const char *lists_dir)
  10841. +{
  10842. + int err;
  10843. + pkg_dest_t *pkg_dest;
  10844. +
  10845. + /* freed in plg_dest_list_deinit */
  10846. + pkg_dest = malloc(sizeof(pkg_dest_t));
  10847. + if (pkg_dest == NULL) {
  10848. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10849. + return NULL;
  10850. + }
  10851. +
  10852. + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
  10853. + err = void_list_append((void_list_t *) list, pkg_dest);
  10854. + if (err) {
  10855. + return NULL;
  10856. + }
  10857. +
  10858. + return pkg_dest;
  10859. +}
  10860. +
  10861. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
  10862. +{
  10863. + return void_list_push((void_list_t *) list, data);
  10864. +}
  10865. +
  10866. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
  10867. +{
  10868. + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
  10869. +}
  10870. --- /dev/null
  10871. +++ busybox-1.18.1/archival/libipkg/pkg_dest_list.h
  10872. @@ -0,0 +1,50 @@
  10873. +/* pkg_dest_list.h - the itsy package management system
  10874. +
  10875. + Carl D. Worth
  10876. +
  10877. + Copyright (C) 2001 University of Southern California
  10878. +
  10879. + This program is free software; you can redistribute it and/or
  10880. + modify it under the terms of the GNU General Public License as
  10881. + published by the Free Software Foundation; either version 2, or (at
  10882. + your option) any later version.
  10883. +
  10884. + This program is distributed in the hope that it will be useful, but
  10885. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10886. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10887. + General Public License for more details.
  10888. +*/
  10889. +
  10890. +#ifndef PKG_DEST_LIST_H
  10891. +#define PKG_DEST_LIST_H
  10892. +
  10893. +#include "pkg_dest.h"
  10894. +
  10895. +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
  10896. +struct pkg_dest_list_elt
  10897. +{
  10898. + pkg_dest_list_elt_t *next;
  10899. + pkg_dest_t *data;
  10900. +};
  10901. +
  10902. +typedef struct pkg_dest_list pkg_dest_list_t;
  10903. +struct pkg_dest_list
  10904. +{
  10905. + pkg_dest_list_elt_t pre_head;
  10906. + pkg_dest_list_elt_t *head;
  10907. + pkg_dest_list_elt_t *tail;
  10908. +};
  10909. +
  10910. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
  10911. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
  10912. +
  10913. +int pkg_dest_list_init(pkg_dest_list_t *list);
  10914. +void pkg_dest_list_deinit(pkg_dest_list_t *list);
  10915. +
  10916. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10917. + const char *root_dir,const char* lists_dir);
  10918. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
  10919. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
  10920. +
  10921. +#endif
  10922. +
  10923. --- /dev/null
  10924. +++ busybox-1.18.1/archival/libipkg/pkg_extract.c
  10925. @@ -0,0 +1,255 @@
  10926. +/* pkg_extract.c - the itsy package management system
  10927. +
  10928. + Carl D. Worth
  10929. +
  10930. + Copyright (C) 2001 University of Southern California
  10931. +
  10932. + This program is free software; you can redistribute it and/or
  10933. + modify it under the terms of the GNU General Public License as
  10934. + published by the Free Software Foundation; either version 2, or (at
  10935. + your option) any later version.
  10936. +
  10937. + This program is distributed in the hope that it will be useful, but
  10938. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10939. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10940. + General Public License for more details.
  10941. +*/
  10942. +
  10943. +#include "ipkg.h"
  10944. +#include <errno.h>
  10945. +#include <fcntl.h>
  10946. +#include <stdio.h>
  10947. +
  10948. +#include "pkg_extract.h"
  10949. +
  10950. +#include "libbb.h"
  10951. +#include "file_util.h"
  10952. +#include "sprintf_alloc.h"
  10953. +#include "archive.h"
  10954. +
  10955. +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
  10956. +#define IPKG_DATA_ARCHIVE "data.tar.gz"
  10957. +#define IPKG_CONTROL_FILE "control"
  10958. +
  10959. +static void FAST_FUNC ipkg_data_extract_all_prefix(archive_handle_t *archive_handle)
  10960. +{
  10961. + char *name_ptr = archive_handle->file_header->name;
  10962. +
  10963. + /* Skip all leading "/" */
  10964. + while (*name_ptr == '/')
  10965. + name_ptr++;
  10966. + /* Skip all leading "./" and "../" */
  10967. + while (name_ptr[0] == '.') {
  10968. + if (name_ptr[1] == '.' && name_ptr[2] == '/')
  10969. + name_ptr++;
  10970. + if (name_ptr[1] != '/')
  10971. + break;
  10972. + name_ptr += 2;
  10973. + }
  10974. +
  10975. + if (name_ptr[0] != '\0') {
  10976. + archive_handle->file_header->name = xasprintf("%s%s", archive_handle->dpkg__buffer, name_ptr);
  10977. + data_extract_all(archive_handle);
  10978. + }
  10979. +}
  10980. +
  10981. +static void FAST_FUNC ipkg_data_extract_to_buffer(archive_handle_t *archive_handle)
  10982. +{
  10983. + unsigned size = archive_handle->file_header->size;
  10984. +
  10985. + archive_handle->dpkg__buffer = xzalloc(size + 1);
  10986. + xread(archive_handle->src_fd, archive_handle->dpkg__buffer, size);
  10987. +}
  10988. +
  10989. +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
  10990. +{
  10991. + archive_handle_t *archive;
  10992. + char *path;
  10993. +
  10994. + sprintf_alloc(&path, "%s/", dir);
  10995. + archive = init_handle();
  10996. + archive->src_fd = xopen(pkg->local_filename, O_RDONLY);
  10997. + archive->filter = filter_accept_list;
  10998. + llist_add_to(&(archive->accept), (char *)filename);
  10999. + archive->dpkg__buffer = path;
  11000. + archive->action_data = ipkg_data_extract_all_prefix;
  11001. + archive->ah_flags |= ARCHIVE_UNLINK_OLD;
  11002. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11003. + close(archive->src_fd);
  11004. + free(archive->accept);
  11005. + free(archive);
  11006. + free(path);
  11007. +}
  11008. +
  11009. +static void FAST_FUNC data_extract_file_name_to_buffer(archive_handle_t *archive)
  11010. +{
  11011. + unsigned int size = strlen(archive->file_header->name) + 2;
  11012. +
  11013. + if (archive->dpkg__buffer == NULL) {
  11014. + archive->dpkg__buffer = xmalloc(size);
  11015. + strcpy(archive->dpkg__buffer, archive->file_header->name);
  11016. + } else {
  11017. + size += strlen(archive->dpkg__buffer);
  11018. + archive->dpkg__buffer = xrealloc(archive->dpkg__buffer, size);
  11019. + strcat(archive->dpkg__buffer, archive->file_header->name);
  11020. + }
  11021. + strcat(archive->dpkg__buffer, "\n");
  11022. + data_skip(archive);
  11023. +}
  11024. +
  11025. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
  11026. +{
  11027. + archive_handle_t *archive;
  11028. + char *name;
  11029. + const char *filename = IPKG_CONTROL_FILE;
  11030. +
  11031. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  11032. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  11033. + archive = init_handle();
  11034. + archive->src_fd = xopen(name, O_RDONLY);
  11035. + archive->filter = filter_accept_list;
  11036. + llist_add_to(&(archive->accept), (char *)filename);
  11037. + archive->action_data = ipkg_data_extract_to_buffer;
  11038. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11039. + close(archive->src_fd);
  11040. + fputs(archive->dpkg__buffer, stream);
  11041. + free(archive->dpkg__buffer);
  11042. + free(archive->accept);
  11043. + free(archive);
  11044. + free(name);
  11045. +
  11046. + return 0;
  11047. +}
  11048. +
  11049. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
  11050. +{
  11051. + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
  11052. +}
  11053. +
  11054. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
  11055. +{
  11056. + archive_handle_t *archive;
  11057. + char *name;
  11058. + char *path;
  11059. +
  11060. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  11061. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  11062. + sprintf_alloc(&path, "%s/%s", dir, prefix);
  11063. + archive = init_handle();
  11064. + archive->src_fd = xopen(name, O_RDONLY);
  11065. + archive->filter = filter_accept_all;
  11066. + archive->dpkg__buffer = path;
  11067. + archive->action_data = ipkg_data_extract_all_prefix;
  11068. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_RESTORE_DATE | ARCHIVE_UNLINK_OLD;
  11069. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11070. + close(archive->src_fd);
  11071. + free(archive);
  11072. + free(path);
  11073. + free(name);
  11074. +
  11075. + return 0;
  11076. +}
  11077. +
  11078. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
  11079. +{
  11080. + archive_handle_t *archive;
  11081. + char *name;
  11082. + char *path;
  11083. +
  11084. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  11085. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  11086. + sprintf_alloc(&path, "%s/", dir);
  11087. + archive = init_handle();
  11088. + archive->src_fd = xopen(name, O_RDONLY);
  11089. + archive->filter = filter_accept_all;
  11090. + archive->dpkg__buffer = path;
  11091. + archive->action_data = ipkg_data_extract_all_prefix;
  11092. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_RESTORE_DATE | ARCHIVE_UNLINK_OLD;
  11093. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11094. + close(archive->src_fd);
  11095. + free(archive);
  11096. + free(path);
  11097. + free(name);
  11098. +
  11099. + return 0;
  11100. +}
  11101. +
  11102. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
  11103. +{
  11104. + int err=0;
  11105. + char *line, *data_file;
  11106. + FILE *file;
  11107. + FILE *tmp;
  11108. +
  11109. + file = fopen(file_name, "w");
  11110. + if (file == NULL) {
  11111. + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
  11112. + __FUNCTION__, file_name);
  11113. + return EINVAL;
  11114. + }
  11115. +
  11116. + tmp = tmpfile();
  11117. + if (pkg->installed_files) {
  11118. + str_list_elt_t *elt;
  11119. + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
  11120. + fprintf(file, "%s\n", elt->data);
  11121. + }
  11122. + } else {
  11123. + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
  11124. + if (err) {
  11125. + fclose(file);
  11126. + fclose(tmp);
  11127. + return err;
  11128. + }
  11129. +
  11130. + /* Fixup data file names by removing the initial '.' */
  11131. + rewind(tmp);
  11132. + while (1) {
  11133. + line = file_read_line_alloc(tmp);
  11134. + if (line == NULL) {
  11135. + break;
  11136. + }
  11137. +
  11138. + data_file = line;
  11139. + if (*data_file == '.') {
  11140. + data_file++;
  11141. + }
  11142. +
  11143. + if (*data_file != '/') {
  11144. + fputs("/", file);
  11145. + }
  11146. +
  11147. + /* I have no idea why, but this is what dpkg does */
  11148. + if (strcmp(data_file, "/\n") == 0) {
  11149. + fputs("/.\n", file);
  11150. + } else {
  11151. + fputs(data_file, file);
  11152. + }
  11153. + }
  11154. + }
  11155. + fclose(tmp);
  11156. + fclose(file);
  11157. +
  11158. + return err;
  11159. +}
  11160. +
  11161. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
  11162. +{
  11163. + archive_handle_t *archive;
  11164. + char *name;
  11165. +
  11166. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  11167. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  11168. + archive = init_handle();
  11169. + archive->src_fd = xopen(name, O_RDONLY);
  11170. + archive->filter = filter_accept_all;
  11171. + archive->action_data = data_extract_file_name_to_buffer;
  11172. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11173. + close(archive->src_fd);
  11174. + fputs(archive->dpkg__buffer, file);
  11175. + free(archive->dpkg__buffer);
  11176. + free(archive);
  11177. + free(name);
  11178. +
  11179. + return 0;
  11180. +}
  11181. --- /dev/null
  11182. +++ busybox-1.18.1/archival/libipkg/pkg_extract.h
  11183. @@ -0,0 +1,32 @@
  11184. +/* pkg_extract.c - the itsy package management system
  11185. +
  11186. + Carl D. Worth
  11187. +
  11188. + Copyright (C) 2001 University of Southern California
  11189. +
  11190. + This program is free software; you can redistribute it and/or
  11191. + modify it under the terms of the GNU General Public License as
  11192. + published by the Free Software Foundation; either version 2, or (at
  11193. + your option) any later version.
  11194. +
  11195. + This program is distributed in the hope that it will be useful, but
  11196. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11197. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11198. + General Public License for more details.
  11199. +*/
  11200. +
  11201. +#ifndef PKG_EXTRACT_H
  11202. +#define PKG_EXTRACT_H
  11203. +
  11204. +#include "pkg.h"
  11205. +
  11206. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
  11207. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
  11208. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
  11209. + const char *dir,
  11210. + const char *prefix);
  11211. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
  11212. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
  11213. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
  11214. +
  11215. +#endif
  11216. --- /dev/null
  11217. +++ busybox-1.18.1/archival/libipkg/pkg_hash.c
  11218. @@ -0,0 +1,623 @@
  11219. +/* ipkg_hash.c - the itsy package management system
  11220. +
  11221. + Steven M. Ayer
  11222. +
  11223. + Copyright (C) 2002 Compaq Computer Corporation
  11224. +
  11225. + This program is free software; you can redistribute it and/or
  11226. + modify it under the terms of the GNU General Public License as
  11227. + published by the Free Software Foundation; either version 2, or (at
  11228. + your option) any later version.
  11229. +
  11230. + This program is distributed in the hope that it will be useful, but
  11231. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11232. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11233. + General Public License for more details.
  11234. +*/
  11235. +
  11236. +#include "ipkg.h"
  11237. +#include <errno.h>
  11238. +#include <ctype.h>
  11239. +#include <stdlib.h>
  11240. +#include <string.h>
  11241. +
  11242. +#include "hash_table.h"
  11243. +#include "pkg.h"
  11244. +#include "ipkg_message.h"
  11245. +#include "pkg_vec.h"
  11246. +#include "pkg_hash.h"
  11247. +#include "pkg_parse.h"
  11248. +#include "ipkg_utils.h"
  11249. +
  11250. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11251. +
  11252. +/*
  11253. + * this will talk to both feeds-lists files and installed status files
  11254. + * example api:
  11255. + *
  11256. + * hash_table_t hash;
  11257. + * pkg_hash_init(name, &hash, 1000);
  11258. + * pkg_hash_add_from_file(<feed filename>);
  11259. + *
  11260. + * the query function is just there as a shell to prove to me that this
  11261. + * sort of works, but isn't far from doing something useful
  11262. + *
  11263. + * -sma, 12/21/01
  11264. + * modified: CDW 3 Jan. 2002
  11265. + */
  11266. +
  11267. +
  11268. +
  11269. +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
  11270. +{
  11271. + return hash_table_init(name, hash, len);
  11272. +}
  11273. +
  11274. +void pkg_hash_deinit(hash_table_t *hash)
  11275. +{
  11276. + hash_table_deinit(hash);
  11277. +}
  11278. +
  11279. +
  11280. +/* Find the default arch for a given package status file if none is given. */
  11281. +static char *pkg_get_default_arch(ipkg_conf_t *conf)
  11282. +{
  11283. + nv_pair_list_elt_t *l;
  11284. + const char *def_arch = HOST_CPU_STR; /* Default arch */
  11285. + int def_prio = 0; /* Other archs override this */
  11286. +
  11287. + l = conf->arch_list.head;
  11288. +
  11289. + while (l) {
  11290. + nv_pair_t *nv = l->data;
  11291. + int priority = strtol(nv->value, NULL, 0);
  11292. +
  11293. + /* Check if this arch has higher priority, and is valid */
  11294. + if ((priority > def_prio) &&
  11295. + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
  11296. + /* Our new default */
  11297. + def_prio = priority;
  11298. + def_arch = nv->name;
  11299. + }
  11300. + l = l->next;
  11301. + }
  11302. +
  11303. + return strdup(def_arch);
  11304. +}
  11305. +
  11306. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11307. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
  11308. +{
  11309. + hash_table_t *hash = &conf->pkg_hash;
  11310. + char **raw;
  11311. + char **raw_start;
  11312. + pkg_t *pkg;
  11313. +
  11314. + raw = raw_start = read_raw_pkgs_from_file(file_name);
  11315. + if (!raw)
  11316. + return -ENOMEM;
  11317. +
  11318. + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
  11319. + pkg = pkg_new();
  11320. + if (!pkg)
  11321. + return -ENOMEM;
  11322. +
  11323. + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
  11324. + if (!pkg->architecture) {
  11325. + char *version_str = pkg_version_str_alloc(pkg);
  11326. + pkg->architecture = pkg_get_default_arch(conf);
  11327. + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
  11328. + pkg->name, version_str, pkg->architecture);
  11329. + free(version_str);
  11330. + }
  11331. + hash_insert_pkg(hash, pkg, is_status_file,conf);
  11332. + } else {
  11333. + free(pkg);
  11334. + }
  11335. + }
  11336. +
  11337. + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
  11338. + memory after read_raw_pkgs_from_file */
  11339. + raw = raw_start;
  11340. + while (*raw) {
  11341. + free(*raw++);
  11342. + }
  11343. + free(raw_start);
  11344. + return 0;
  11345. +}
  11346. +
  11347. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
  11348. +{
  11349. + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
  11350. +}
  11351. +
  11352. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
  11353. +{
  11354. + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
  11355. + if (apkg)
  11356. + return NULL;
  11357. + return apkg->provided_by;
  11358. +}
  11359. +
  11360. +
  11361. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11362. + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
  11363. +{
  11364. + int i;
  11365. + int nprovides = 0;
  11366. + int nmatching = 0;
  11367. + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
  11368. + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
  11369. + abstract_pkg_vec_t *provided_apkg_vec;
  11370. + abstract_pkg_t **provided_apkgs;
  11371. + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
  11372. + pkg_t *latest_installed_parent = NULL;
  11373. + pkg_t *latest_matching = NULL;
  11374. + pkg_t *held_pkg = NULL;
  11375. + pkg_t *good_pkg_by_name = NULL;
  11376. +
  11377. + if (matching_apkgs == NULL || providers == NULL ||
  11378. + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
  11379. + return NULL;
  11380. +
  11381. + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
  11382. +
  11383. + provided_apkg_vec = apkg->provided_by;
  11384. + nprovides = provided_apkg_vec->len;
  11385. + provided_apkgs = provided_apkg_vec->pkgs;
  11386. + if (nprovides > 1)
  11387. + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
  11388. +
  11389. + /* accumulate all the providers */
  11390. + for (i = 0; i < nprovides; i++) {
  11391. + abstract_pkg_t *provider_apkg = provided_apkgs[i];
  11392. + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
  11393. + abstract_pkg_vec_insert(providers, provider_apkg);
  11394. + }
  11395. + nprovides = providers->len;
  11396. +
  11397. + for (i = 0; i < nprovides; i++) {
  11398. + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
  11399. + abstract_pkg_t *replacement_apkg = NULL;
  11400. + pkg_vec_t *vec;
  11401. +
  11402. + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
  11403. + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
  11404. + if (provider_apkg->replaced_by->len > 1) {
  11405. + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
  11406. + provider_apkg->name, replacement_apkg->name);
  11407. + }
  11408. + }
  11409. +
  11410. + if (replacement_apkg)
  11411. + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
  11412. + replacement_apkg->name, provider_apkg->name);
  11413. +
  11414. + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
  11415. + if (abstract_pkg_vec_contains(providers, replacement_apkg))
  11416. + continue;
  11417. + else
  11418. + provider_apkg = replacement_apkg;
  11419. + }
  11420. +
  11421. + if (!(vec = provider_apkg->pkgs)) {
  11422. + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
  11423. + continue;
  11424. + }
  11425. +
  11426. +
  11427. + /* now check for supported architecture */
  11428. + {
  11429. + int max_count = 0;
  11430. + int j;
  11431. +
  11432. + /* count packages matching max arch priority and keep track of last one */
  11433. + for (j = 0; j < vec->len; j++) {
  11434. + pkg_t *maybe = vec->pkgs[j];
  11435. + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
  11436. + maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
  11437. + if (maybe->arch_priority > 0) {
  11438. + max_count++;
  11439. + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
  11440. + pkg_vec_insert(matching_pkgs, maybe);
  11441. + }
  11442. + }
  11443. + }
  11444. + }
  11445. +
  11446. + if (matching_pkgs->len > 1)
  11447. + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
  11448. + if (matching_apkgs->len > 1)
  11449. + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
  11450. +
  11451. +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
  11452. + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
  11453. +/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
  11454. + Until now I always got the latest, but that breaks the downgrade option.
  11455. + If I stop at the first one, I would probably miss the new ones
  11456. + Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
  11457. + or from a Packages feed.
  11458. + It it is from a file it always need to be checked whatever version I have in feeds or everywhere, according to force-down or whatever options*/
  11459. +/*Pigi*/
  11460. +
  11461. + for (i = 0; i < matching_pkgs->len; i++) {
  11462. + pkg_t *matching = matching_pkgs->pkgs[i];
  11463. + if (constraint_fcn(matching, cdata)) { /* We found it */
  11464. + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
  11465. + good_pkg_by_name = matching;
  11466. + if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
  11467. + break;
  11468. + }
  11469. + }
  11470. +
  11471. +
  11472. + for (i = 0; i < matching_pkgs->len; i++) {
  11473. + pkg_t *matching = matching_pkgs->pkgs[i];
  11474. + latest_matching = matching;
  11475. + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
  11476. + latest_installed_parent = matching;
  11477. + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
  11478. + if (held_pkg)
  11479. + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
  11480. + held_pkg->name, matching->name);
  11481. + held_pkg = matching;
  11482. + }
  11483. + }
  11484. +
  11485. + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
  11486. + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
  11487. + apkg->name, matching_apkgs->len);
  11488. + for (i = 0; i < matching_apkgs->len; i++) {
  11489. + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
  11490. + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
  11491. + }
  11492. + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
  11493. + }
  11494. +
  11495. + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
  11496. + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
  11497. + __FUNCTION__, apkg->name, matching_pkgs->len);
  11498. + for (i = 0; i < matching_pkgs->len; i++) {
  11499. + pkg_t *matching = matching_pkgs->pkgs[i];
  11500. + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
  11501. + matching->name, matching->version, matching->architecture);
  11502. + }
  11503. + }
  11504. +
  11505. + nmatching = matching_apkgs->len;
  11506. +
  11507. + pkg_vec_free(matching_pkgs);
  11508. + abstract_pkg_vec_free(matching_apkgs);
  11509. + abstract_pkg_vec_free(providers);
  11510. +
  11511. + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
  11512. + return good_pkg_by_name;
  11513. + }
  11514. + if (held_pkg) {
  11515. + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
  11516. + return held_pkg;
  11517. + }
  11518. + if (latest_installed_parent) {
  11519. + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
  11520. + return latest_installed_parent;
  11521. + }
  11522. + if (nmatching > 1) {
  11523. + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
  11524. + return NULL;
  11525. + }
  11526. + if (latest_matching) {
  11527. + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
  11528. + latest_matching->name, latest_matching->version, latest_matching->architecture);
  11529. + return latest_matching;
  11530. + }
  11531. + return NULL;
  11532. +}
  11533. +
  11534. +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
  11535. +{
  11536. + const char *name = (const char *)cdata;
  11537. + if (strcmp(pkg->name, name) == 0)
  11538. + return 1;
  11539. + else
  11540. + return 0;
  11541. +}
  11542. +
  11543. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
  11544. +{
  11545. + hash_table_t *hash = &conf->pkg_hash;
  11546. + abstract_pkg_t *apkg = NULL;
  11547. +
  11548. + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
  11549. + return NULL;
  11550. +
  11551. + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
  11552. +}
  11553. +
  11554. +
  11555. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11556. + const char *pkg_name,
  11557. + const char * version)
  11558. +{
  11559. + pkg_vec_t * vec;
  11560. + register int i;
  11561. + char *version_str = NULL;
  11562. +
  11563. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
  11564. + return NULL;
  11565. +
  11566. + for(i = 0; i < vec->len; i++) {
  11567. + version_str = pkg_version_str_alloc(vec->pkgs[i]);
  11568. + if(!strcmp(version_str, version)) {
  11569. + free(version_str);
  11570. + break;
  11571. + }
  11572. + free(version_str);
  11573. + }
  11574. +
  11575. + if(i == vec->len)
  11576. + return NULL;
  11577. +
  11578. + return vec->pkgs[i];
  11579. +}
  11580. +
  11581. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11582. + const char *pkg_name,
  11583. + pkg_dest_t *dest)
  11584. +{
  11585. + pkg_vec_t * vec;
  11586. + register int i;
  11587. +
  11588. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
  11589. + return NULL;
  11590. + }
  11591. +
  11592. + for(i = 0; i < vec->len; i++)
  11593. + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
  11594. + return vec->pkgs[i];
  11595. + }
  11596. + return NULL;
  11597. +}
  11598. +
  11599. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11600. + const char *pkg_name)
  11601. +{
  11602. + pkg_vec_t * vec;
  11603. + register int i;
  11604. +
  11605. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
  11606. + return NULL;
  11607. + }
  11608. +
  11609. + for(i = 0; i < vec->len; i++)
  11610. + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
  11611. + return vec->pkgs[i];
  11612. + }
  11613. +
  11614. + return NULL;
  11615. +}
  11616. +
  11617. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
  11618. +{
  11619. + abstract_pkg_t * ab_pkg;
  11620. +
  11621. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
  11622. + return NULL;
  11623. + }
  11624. +
  11625. + if (ab_pkg->pkgs) {
  11626. + return ab_pkg->pkgs;
  11627. + } else if (ab_pkg->provided_by) {
  11628. + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
  11629. + if (abpkg != NULL){
  11630. + return abpkg->pkgs;
  11631. + } else {
  11632. + return ab_pkg->pkgs;
  11633. + }
  11634. + } else {
  11635. + return NULL;
  11636. + }
  11637. +}
  11638. +
  11639. +static int pkg_compare_names(const void *p1, const void *p2)
  11640. +{
  11641. + const pkg_t *pkg1 = *(const pkg_t **)p1;
  11642. + const pkg_t *pkg2 = *(const pkg_t **)p2;
  11643. + if (pkg1->name == NULL)
  11644. + return 1;
  11645. + if (pkg2->name == NULL)
  11646. + return -1;
  11647. + return(strcmp(pkg1->name, pkg2->name));
  11648. +}
  11649. +
  11650. +
  11651. +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
  11652. +{
  11653. + int j;
  11654. + const char *name;
  11655. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11656. + pkg_vec_t *all = (pkg_vec_t *)data;
  11657. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11658. + name = pkg_name;
  11659. + if (pkg_vec) {
  11660. + for (j = 0; j < pkg_vec->len; j++) {
  11661. + pkg_t *pkg = pkg_vec->pkgs[j];
  11662. + pkg_vec_insert(all, pkg);
  11663. + }
  11664. + }
  11665. +}
  11666. +
  11667. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
  11668. +{
  11669. + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
  11670. + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
  11671. +}
  11672. +
  11673. +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
  11674. +{
  11675. + const char *name;
  11676. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11677. + pkg_vec_t *all = (pkg_vec_t *)data;
  11678. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11679. + int j;
  11680. + name = pkg_name;
  11681. + if (pkg_vec) {
  11682. + for (j = 0; j < pkg_vec->len; j++) {
  11683. + pkg_t *pkg = pkg_vec->pkgs[j];
  11684. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  11685. + pkg_vec_insert(all, pkg);
  11686. + }
  11687. + }
  11688. + }
  11689. +}
  11690. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
  11691. +{
  11692. + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
  11693. + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
  11694. +}
  11695. +
  11696. +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
  11697. +{
  11698. + int i;
  11699. + pkg_t *pkg;
  11700. + const char *name;
  11701. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11702. + ipkg_conf_t *conf = (ipkg_conf_t *)data;
  11703. + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
  11704. + name = pkg_name;
  11705. + fprintf(stdout, "%s\n", ab_pkg->name);
  11706. + i = 0;
  11707. + if (dependents != NULL)
  11708. + while (dependents [i] != NULL)
  11709. + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
  11710. + dependents = ab_pkg->provided_by->pkgs;
  11711. + i = 0;
  11712. + if (dependents != NULL)
  11713. + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
  11714. + printf ("\tprovided by - %s\n", dependents [i ++]->name);
  11715. + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
  11716. + if (pkg) {
  11717. + i = 0;
  11718. + while (i < pkg->depends_count)
  11719. + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
  11720. + }
  11721. +}
  11722. +void pkg_hash_dump(hash_table_t *hash, void *data)
  11723. +{
  11724. +
  11725. + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
  11726. + hash_table_foreach(hash, pkg_hash_dump_helper, data);
  11727. + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
  11728. +}
  11729. +
  11730. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11731. +{
  11732. + abstract_pkg_t * ab_pkg;
  11733. +
  11734. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
  11735. + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
  11736. +
  11737. + return ab_pkg;
  11738. +}
  11739. +
  11740. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  11741. +{
  11742. + abstract_pkg_t * ab_pkg;
  11743. + int arch_priority;
  11744. +
  11745. + if(!pkg)
  11746. + return pkg;
  11747. +
  11748. + arch_priority = pkg->arch_priority;
  11749. +
  11750. + if (buildDepends(hash, pkg)<0){
  11751. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11752. + return NULL;
  11753. + }
  11754. + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
  11755. +
  11756. + if (set_status) {
  11757. + if (pkg->state_status == SS_INSTALLED) {
  11758. + ab_pkg->state_status = SS_INSTALLED;
  11759. + } else if (pkg->state_status == SS_UNPACKED) {
  11760. + ab_pkg->state_status = SS_UNPACKED;
  11761. + }
  11762. + }
  11763. +
  11764. + if(!ab_pkg->pkgs)
  11765. + ab_pkg->pkgs = pkg_vec_alloc();
  11766. +
  11767. + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
  11768. + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
  11769. + pkg->parent = ab_pkg;
  11770. +
  11771. + if (buildProvides(hash, ab_pkg, pkg)<0){
  11772. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11773. + return NULL;
  11774. + }
  11775. + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
  11776. + if (buildConflicts(hash, pkg)<0){
  11777. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11778. + return NULL;
  11779. + }
  11780. + if (buildReplaces(hash, ab_pkg, pkg)<0) {
  11781. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11782. + return NULL;
  11783. + }
  11784. +
  11785. + buildDependedUponBy(pkg, ab_pkg);
  11786. + return pkg;
  11787. +}
  11788. +
  11789. +/*
  11790. + * this will assume that we've already determined that
  11791. + * the abstract pkg doesn't exist, 'cause we should know these things...
  11792. + */
  11793. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11794. +{
  11795. + abstract_pkg_t * ab_pkg;
  11796. +
  11797. + ab_pkg = abstract_pkg_new();
  11798. + if (ab_pkg == NULL) { return NULL; }
  11799. +
  11800. + ab_pkg->name = strdup(pkg_name);
  11801. + hash_table_insert(hash, pkg_name, ab_pkg);
  11802. +
  11803. + return ab_pkg;
  11804. +}
  11805. +
  11806. +
  11807. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
  11808. +{
  11809. + hash_table_t *file_hash = &conf->file_hash;
  11810. +
  11811. + return hash_table_get(file_hash, file_name);
  11812. +}
  11813. +
  11814. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
  11815. +{
  11816. + hash_table_t *file_hash = &conf->file_hash;
  11817. + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
  11818. + int file_name_len = strlen(file_name);
  11819. +
  11820. + if (file_name[file_name_len -1] == '/')
  11821. + return 0;
  11822. +
  11823. + if (conf->offline_root) {
  11824. + int len = strlen(conf->offline_root);
  11825. + if (strncmp(file_name, conf->offline_root, len) == 0) {
  11826. + file_name += len;
  11827. + }
  11828. + }
  11829. +
  11830. + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
  11831. + hash_table_insert(file_hash, file_name, owning_pkg);
  11832. + if (old_owning_pkg) {
  11833. + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
  11834. + /* mark this package to have its filelist written */
  11835. + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11836. + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11837. + }
  11838. + return 0;
  11839. +}
  11840. +
  11841. +
  11842. --- /dev/null
  11843. +++ busybox-1.18.1/archival/libipkg/pkg_hash.h
  11844. @@ -0,0 +1,61 @@
  11845. +/* pkg_hash.h - the itsy package management system
  11846. +
  11847. + Steven M. Ayer
  11848. +
  11849. + Copyright (C) 2002 Compaq Computer Corporation
  11850. +
  11851. + This program is free software; you can redistribute it and/or
  11852. + modify it under the terms of the GNU General Public License as
  11853. + published by the Free Software Foundation; either version 2, or (at
  11854. + your option) any later version.
  11855. +
  11856. + This program is distributed in the hope that it will be useful, but
  11857. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11858. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11859. + General Public License for more details.
  11860. +*/
  11861. +
  11862. +#ifndef PKG_HASH_H
  11863. +#define PKG_HASH_H
  11864. +
  11865. +#include "pkg.h"
  11866. +#include "pkg_vec.h"
  11867. +#include "hash_table.h"
  11868. +
  11869. +
  11870. +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
  11871. +void pkg_hash_deinit(hash_table_t *hash);
  11872. +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
  11873. +
  11874. +void pkg_hash_dump(hash_table_t *hash, void *data);
  11875. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
  11876. +
  11877. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11878. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
  11879. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
  11880. +
  11881. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11882. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
  11883. +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11884. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
  11885. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11886. + const char *pkg_name,
  11887. + const char * version);
  11888. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
  11889. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11890. + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
  11891. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
  11892. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11893. + const char *pkg_name);
  11894. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11895. + const char *pkg_name,
  11896. + pkg_dest_t *dest);
  11897. +
  11898. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
  11899. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
  11900. +
  11901. +/* XXX: shouldn't this go in pkg_vec.[ch]? */
  11902. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11903. +
  11904. +#endif
  11905. +
  11906. --- /dev/null
  11907. +++ busybox-1.18.1/archival/libipkg/pkg_parse.c
  11908. @@ -0,0 +1,368 @@
  11909. +/* pkg_parse.c - the itsy package management system
  11910. +
  11911. + Steven M. Ayer
  11912. +
  11913. + Copyright (C) 2002 Compaq Computer Corporation
  11914. +
  11915. + This program is free software; you can redistribute it and/or
  11916. + modify it under the terms of the GNU General Public License as
  11917. + published by the Free Software Foundation; either version 2, or (at
  11918. + your option) any later version.
  11919. +
  11920. + This program is distributed in the hope that it will be useful, but
  11921. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11922. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11923. + General Public License for more details.
  11924. +*/
  11925. +
  11926. +#include "ipkg.h"
  11927. +#include <errno.h>
  11928. +#include <ctype.h>
  11929. +
  11930. +#include "pkg.h"
  11931. +#include "ipkg_utils.h"
  11932. +#include "pkg_parse.h"
  11933. +
  11934. +int alterProvidesLine(char *raw, char *temp);
  11935. +
  11936. +int isGenericFieldType(char * type, char * line)
  11937. +{
  11938. + if(!strncmp(line, type, strlen(type)))
  11939. + return 1;
  11940. + return 0;
  11941. +}
  11942. +
  11943. +char * parseGenericFieldType(char * type, char * raw)
  11944. +{
  11945. + char * field_value = raw + (strlen(type) + 1);
  11946. + return trim_alloc(field_value);
  11947. +}
  11948. +
  11949. +void parseStatus(pkg_t *pkg, char * raw)
  11950. +{
  11951. + char sw_str[64], sf_str[64], ss_str[64];
  11952. +
  11953. + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
  11954. + pkg->state_want = pkg_state_want_from_str(sw_str);
  11955. + pkg->state_flag = pkg_state_flag_from_str(sf_str);
  11956. + pkg->state_status = pkg_state_status_from_str(ss_str);
  11957. +}
  11958. +
  11959. +char ** parseDependsString(char * raw, int * depends_count)
  11960. +{
  11961. + char ** depends = NULL;
  11962. + int line_count = 0;
  11963. + char buff[2048], * dest;
  11964. +
  11965. + while(raw && *raw && !isspace(*raw)) {
  11966. + raw++;
  11967. + }
  11968. +
  11969. + if(line_is_blank(raw)){
  11970. + *depends_count = line_count;
  11971. + return NULL;
  11972. + }
  11973. + while(raw && *raw){
  11974. + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
  11975. +
  11976. + while(isspace(*raw)) raw++;
  11977. +
  11978. + dest = buff;
  11979. + while((*raw != ',') && *raw)
  11980. + *dest++ = *raw++;
  11981. +
  11982. + *dest = '\0';
  11983. + depends[line_count] = trim_alloc(buff);
  11984. + if(depends[line_count] ==NULL)
  11985. + return NULL;
  11986. + line_count++;
  11987. + if(*raw == ',')
  11988. + raw++;
  11989. + }
  11990. + *depends_count = line_count;
  11991. + return depends;
  11992. +}
  11993. +
  11994. +void parseConffiles(pkg_t * pkg, char * raw)
  11995. +{
  11996. + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
  11997. +
  11998. + if(!strncmp(raw, "Conffiles:", 10))
  11999. + raw += strlen("Conffiles:");
  12000. +
  12001. + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
  12002. + conffile_list_append(&pkg->conffiles, file_name, md5sum);
  12003. + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
  12004. + while (*raw && isspace(*raw)) {
  12005. + raw++;
  12006. + }
  12007. + raw += strlen(file_name);
  12008. + while (*raw && isspace(*raw)) {
  12009. + raw++;
  12010. + }
  12011. + raw += strlen(md5sum);
  12012. + }
  12013. +}
  12014. +
  12015. +int parseVersion(pkg_t *pkg, char *raw)
  12016. +{
  12017. + char *colon, *eepochcolon;
  12018. +#ifdef USE_DEBVERSION
  12019. + char *hyphen;
  12020. +#endif
  12021. + unsigned long epoch;
  12022. +
  12023. + if (!*raw) {
  12024. + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
  12025. + return EINVAL;
  12026. + }
  12027. +
  12028. + if (strncmp(raw, "Version:", 8) == 0) {
  12029. + raw += 8;
  12030. + }
  12031. + while (*raw && isspace(*raw)) {
  12032. + raw++;
  12033. + }
  12034. +
  12035. + colon= strchr(raw,':');
  12036. + if (colon) {
  12037. + epoch= strtoul(raw,&eepochcolon,10);
  12038. + if (colon != eepochcolon) {
  12039. + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
  12040. + return EINVAL;
  12041. + }
  12042. + if (!*++colon) {
  12043. + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
  12044. + return EINVAL;
  12045. + }
  12046. + raw= colon;
  12047. + pkg->epoch= epoch;
  12048. + } else {
  12049. + pkg->epoch= 0;
  12050. + }
  12051. +
  12052. + pkg->revision = (char *)"";
  12053. + pkg->familiar_revision = (char *)"";
  12054. +
  12055. + pkg->version= malloc(strlen(raw)+1);
  12056. + if ( pkg->version == NULL ) {
  12057. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12058. + return ENOMEM;
  12059. + }
  12060. + strcpy(pkg->version, raw);
  12061. +
  12062. +#ifdef USE_DEBVERSION
  12063. + hyphen= strrchr(pkg->version,'-');
  12064. +
  12065. + if (hyphen) {
  12066. + *hyphen++= 0;
  12067. + if (strncmp("fam", hyphen, 3) == 0) {
  12068. + pkg->familiar_revision=hyphen+3;
  12069. + hyphen= strrchr(pkg->version,'-');
  12070. + if (hyphen) {
  12071. + *hyphen++= 0;
  12072. + pkg->revision = hyphen;
  12073. + }
  12074. + } else {
  12075. + pkg->revision = hyphen;
  12076. + }
  12077. + }
  12078. +#endif
  12079. +
  12080. +/*
  12081. + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
  12082. + pkg->epoch,
  12083. + pkg->version,
  12084. + pkg->revision,
  12085. + pkg->familiar_revision);
  12086. +*/
  12087. +
  12088. + return 0;
  12089. +}
  12090. +
  12091. +
  12092. +/* This code is needed to insert in first position the keyword for the aligning bug */
  12093. +
  12094. +int alterProvidesLine(char *raw, char *temp)
  12095. +{
  12096. +
  12097. +
  12098. + if (!*raw) {
  12099. + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
  12100. + return -EINVAL;
  12101. + }
  12102. +
  12103. + if ( temp == NULL ) {
  12104. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12105. + return -ENOMEM;
  12106. + }
  12107. +
  12108. + if (strncmp(raw, "Provides:", 9) == 0) {
  12109. + raw += 9;
  12110. + }
  12111. + while (*raw && isspace(*raw)) {
  12112. + raw++;
  12113. + }
  12114. +
  12115. + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
  12116. + while (*raw) {
  12117. + strncat( temp, raw++, 1);
  12118. + }
  12119. + return 0;
  12120. +
  12121. +}
  12122. +
  12123. +/* Some random thoughts from Carl:
  12124. +
  12125. + This function could be considerably simplified if we just kept
  12126. + an array of all the generic string-valued field names, and looped
  12127. + through those looking for a match. Also, these fields could perhaps
  12128. + be stored in the package as an array as well, (or, probably better,
  12129. + as an nv_pair_list_t).
  12130. +
  12131. + Fields which require special parsing or storage, (such as Depends:
  12132. + and Status:) could be handled as they are now.
  12133. +*/
  12134. +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
  12135. + to a dependency list. And, since we already have
  12136. + Depends/Pre-Depends and need to add Conflicts, Recommends, and
  12137. + Enhances, perhaps we could generalize all of these and save some
  12138. + code duplication.
  12139. +*/
  12140. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
  12141. +{
  12142. + int reading_conffiles, reading_description;
  12143. + int pkg_false_provides=1;
  12144. + char ** lines;
  12145. + char * provide=NULL;
  12146. +
  12147. + pkg->src = src;
  12148. + pkg->dest = dest;
  12149. +
  12150. + reading_conffiles = reading_description = 0;
  12151. +
  12152. + for (lines = *raw; *lines; lines++) {
  12153. + /* fprintf(stderr, "PARSING %s\n", *lines);*/
  12154. + if(isGenericFieldType((char *)"Package:", *lines))
  12155. + pkg->name = parseGenericFieldType((char *)"Package", *lines);
  12156. + else if(isGenericFieldType((char *)"Architecture:", *lines))
  12157. + pkg->architecture = parseGenericFieldType((char *)"Architecture", *lines);
  12158. + else if(isGenericFieldType((char *)"Filename:", *lines))
  12159. + pkg->filename = parseGenericFieldType((char *)"Filename", *lines);
  12160. + else if(isGenericFieldType((char *)"Section:", *lines))
  12161. + pkg->section = parseGenericFieldType((char *)"Section", *lines);
  12162. + else if(isGenericFieldType((char *)"MD5sum:", *lines))
  12163. + pkg->md5sum = parseGenericFieldType((char *)"MD5sum", *lines);
  12164. + /* The old ipkg wrote out status files with the wrong case for MD5sum,
  12165. + let's parse it either way */
  12166. + else if(isGenericFieldType((char *)"MD5Sum:", *lines))
  12167. + pkg->md5sum = parseGenericFieldType((char *)"MD5Sum", *lines);
  12168. + else if(isGenericFieldType((char *)"Size:", *lines))
  12169. + pkg->size = parseGenericFieldType((char *)"Size", *lines);
  12170. + else if(isGenericFieldType((char *)"Source:", *lines))
  12171. + pkg->source = parseGenericFieldType((char *)"Source", *lines);
  12172. + else if(isGenericFieldType((char *)"Installed-Size:", *lines))
  12173. + pkg->installed_size = parseGenericFieldType((char *)"Installed-Size", *lines);
  12174. + else if(isGenericFieldType((char *)"Installed-Time:", *lines)) {
  12175. + char *time_str = parseGenericFieldType((char *)"Installed-Time", *lines);
  12176. + pkg->installed_time = strtoul(time_str, NULL, 0);
  12177. + } else if(isGenericFieldType((char *)"Priority:", *lines))
  12178. + pkg->priority = parseGenericFieldType((char *)"Priority", *lines);
  12179. + else if(isGenericFieldType((char *)"Essential:", *lines)) {
  12180. + char *essential_value;
  12181. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12182. + if (strcmp(essential_value, "yes") == 0) {
  12183. + pkg->essential = 1;
  12184. + }
  12185. + free(essential_value);
  12186. + }
  12187. + else if(isGenericFieldType((char *)"Status", *lines))
  12188. + parseStatus(pkg, *lines);
  12189. + else if(isGenericFieldType((char *)"Version", *lines))
  12190. + parseVersion(pkg, *lines);
  12191. + else if(isGenericFieldType((char *)"Maintainer", *lines))
  12192. + pkg->maintainer = parseGenericFieldType((char *)"Maintainer", *lines);
  12193. + else if(isGenericFieldType((char *)"Conffiles", *lines)){
  12194. + parseConffiles(pkg, *lines);
  12195. + reading_conffiles = 1;
  12196. + }
  12197. + else if(isGenericFieldType((char *)"Description", *lines)) {
  12198. + pkg->description = parseGenericFieldType((char *)"Description", *lines);
  12199. + reading_conffiles = 0;
  12200. + reading_description = 1;
  12201. + }
  12202. +
  12203. + else if(isGenericFieldType((char *)"Provides", *lines)){
  12204. +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
  12205. + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
  12206. + if ( alterProvidesLine(*lines,provide) ){
  12207. + return EINVAL;
  12208. + }
  12209. + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
  12210. +/* Let's try to hack a bit here.
  12211. + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
  12212. + in alot of other places. We will remove it before writing down the status database */
  12213. + pkg_false_provides=0;
  12214. + free(provide);
  12215. + }
  12216. +
  12217. + else if(isGenericFieldType((char *)"Depends", *lines))
  12218. + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
  12219. + else if(isGenericFieldType((char *)"Pre-Depends", *lines))
  12220. + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
  12221. + else if(isGenericFieldType((char *)"Recommends", *lines))
  12222. + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
  12223. + else if(isGenericFieldType((char *)"Suggests", *lines))
  12224. + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
  12225. + /* Abhaya: support for conflicts */
  12226. + else if(isGenericFieldType((char *)"Conflicts", *lines))
  12227. + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
  12228. + else if(isGenericFieldType((char *)"Replaces", *lines))
  12229. + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
  12230. + else if(line_is_blank(*lines)) {
  12231. + lines++;
  12232. + break;
  12233. + }
  12234. + else if(**lines == ' '){
  12235. + if(reading_description) {
  12236. + /* we already know it's not blank, so the rest of description */
  12237. + pkg->description = realloc(pkg->description,
  12238. + strlen(pkg->description)
  12239. + + 1 + strlen(*lines) + 1);
  12240. + strcat(pkg->description, "\n");
  12241. + strcat(pkg->description, (*lines));
  12242. + }
  12243. + else if(reading_conffiles)
  12244. + parseConffiles(pkg, *lines);
  12245. + }
  12246. + }
  12247. + *raw = lines;
  12248. +/* If the ipk has not a Provides line, we insert our false line */
  12249. + if ( pkg_false_provides==1)
  12250. + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
  12251. +
  12252. + if (pkg->name) {
  12253. + return 0;
  12254. + } else {
  12255. + return EINVAL;
  12256. + }
  12257. +}
  12258. +
  12259. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
  12260. +{
  12261. + char ** lines;
  12262. +
  12263. + for (lines = *raw; *lines; lines++) {
  12264. + if(isGenericFieldType((char *)"Essential:", *lines)) {
  12265. + char *essential_value;
  12266. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12267. + if (strcmp(essential_value, "yes") == 0) {
  12268. + pkg->essential = 1;
  12269. + }
  12270. + free(essential_value);
  12271. + }
  12272. + }
  12273. + *raw = lines;
  12274. +
  12275. + return 0;
  12276. +}
  12277. --- /dev/null
  12278. +++ busybox-1.18.1/archival/libipkg/pkg_parse.h
  12279. @@ -0,0 +1,31 @@
  12280. +/* pkg_parse.h - the itsy package management system
  12281. +
  12282. + Steven M. Ayer
  12283. +
  12284. + Copyright (C) 2002 Compaq Computer Corporation
  12285. +
  12286. + This program is free software; you can redistribute it and/or
  12287. + modify it under the terms of the GNU General Public License as
  12288. + published by the Free Software Foundation; either version 2, or (at
  12289. + your option) any later version.
  12290. +
  12291. + This program is distributed in the hope that it will be useful, but
  12292. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12293. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12294. + General Public License for more details.
  12295. +*/
  12296. +
  12297. +#ifndef PKG_PARSE_H
  12298. +#define PKG_PARSE_H
  12299. +
  12300. +int isGenericFieldType(char * type, char * line);
  12301. +char * parseGenericFieldType(char * type, char * raw);
  12302. +void parseStatus(pkg_t *pkg, char * raw);
  12303. +int parseVersion(pkg_t *pkg, char *raw);
  12304. +char ** parseDependsString(char * raw, int * depends_count);
  12305. +int parseVersion(pkg_t *pkg, char *raw);
  12306. +void parseConffiles(pkg_t * pkg, char * raw);
  12307. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
  12308. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
  12309. +
  12310. +#endif
  12311. --- /dev/null
  12312. +++ busybox-1.18.1/archival/libipkg/pkg_src.c
  12313. @@ -0,0 +1,43 @@
  12314. +/* pkg_src.c - the itsy package management system
  12315. +
  12316. + Carl D. Worth
  12317. +
  12318. + Copyright (C) 2001 University of Southern California
  12319. +
  12320. + This program is free software; you can redistribute it and/or
  12321. + modify it under the terms of the GNU General Public License as
  12322. + published by the Free Software Foundation; either version 2, or (at
  12323. + your option) any later version.
  12324. +
  12325. + This program is distributed in the hope that it will be useful, but
  12326. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12327. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12328. + General Public License for more details.
  12329. +*/
  12330. +
  12331. +#include "ipkg.h"
  12332. +
  12333. +#include "pkg_src.h"
  12334. +#include "str_util.h"
  12335. +
  12336. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
  12337. +{
  12338. + src->gzip = gzip;
  12339. + src->name = str_dup_safe (name);
  12340. + src->value = str_dup_safe (base_url);
  12341. + if (extra_data)
  12342. + src->extra_data = str_dup_safe (extra_data);
  12343. + else
  12344. + src->extra_data = NULL;
  12345. + return 0;
  12346. +}
  12347. +
  12348. +void pkg_src_deinit(pkg_src_t *src)
  12349. +{
  12350. + free (src->name);
  12351. + free (src->value);
  12352. + if (src->extra_data)
  12353. + free (src->extra_data);
  12354. +}
  12355. +
  12356. +
  12357. --- /dev/null
  12358. +++ busybox-1.18.1/archival/libipkg/pkg_src.h
  12359. @@ -0,0 +1,34 @@
  12360. +/* pkg_src.h - the itsy package management system
  12361. +
  12362. + Carl D. Worth
  12363. +
  12364. + Copyright (C) 2001 University of Southern California
  12365. +
  12366. + This program is free software; you can redistribute it and/or
  12367. + modify it under the terms of the GNU General Public License as
  12368. + published by the Free Software Foundation; either version 2, or (at
  12369. + your option) any later version.
  12370. +
  12371. + This program is distributed in the hope that it will be useful, but
  12372. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12373. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12374. + General Public License for more details.
  12375. +*/
  12376. +
  12377. +#ifndef PKG_SRC_H
  12378. +#define PKG_SRC_H
  12379. +
  12380. +#include "nv_pair.h"
  12381. +
  12382. +typedef struct
  12383. +{
  12384. + char *name;
  12385. + char *value;
  12386. + char *extra_data;
  12387. + int gzip;
  12388. +} pkg_src_t;
  12389. +
  12390. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
  12391. +void pkg_src_deinit(pkg_src_t *src);
  12392. +
  12393. +#endif
  12394. --- /dev/null
  12395. +++ busybox-1.18.1/archival/libipkg/pkg_src_list.c
  12396. @@ -0,0 +1,75 @@
  12397. +/* pkg_src_list.c - the itsy package management system
  12398. +
  12399. + Carl D. Worth
  12400. +
  12401. + Copyright (C) 2001 University of Southern California
  12402. +
  12403. + This program is free software; you can redistribute it and/or
  12404. + modify it under the terms of the GNU General Public License as
  12405. + published by the Free Software Foundation; either version 2, or (at
  12406. + your option) any later version.
  12407. +
  12408. + This program is distributed in the hope that it will be useful, but
  12409. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12410. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12411. + General Public License for more details.
  12412. +*/
  12413. +
  12414. +#include "ipkg.h"
  12415. +
  12416. +#include "pkg_src_list.h"
  12417. +#include "void_list.h"
  12418. +
  12419. +int pkg_src_list_init(pkg_src_list_t *list)
  12420. +{
  12421. + return void_list_init((void_list_t *) list);
  12422. +}
  12423. +
  12424. +void pkg_src_list_deinit(pkg_src_list_t *list)
  12425. +{
  12426. + pkg_src_list_elt_t *iter;
  12427. + pkg_src_t *pkg_src;
  12428. +
  12429. + for (iter = list->head; iter; iter = iter->next) {
  12430. + pkg_src = iter->data;
  12431. + pkg_src_deinit(pkg_src);
  12432. +
  12433. + /* malloced in pkg_src_list_append */
  12434. + free(pkg_src);
  12435. + iter->data = NULL;
  12436. + }
  12437. + void_list_deinit((void_list_t *) list);
  12438. +}
  12439. +
  12440. +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
  12441. + const char *name, const char *base_url, const char *extra_data,
  12442. + int gzip)
  12443. +{
  12444. + int err;
  12445. +
  12446. + /* freed in pkg_src_list_deinit */
  12447. + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
  12448. +
  12449. + if (pkg_src == NULL) {
  12450. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12451. + return NULL;
  12452. + }
  12453. + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
  12454. +
  12455. + err = void_list_append((void_list_t *) list, pkg_src);
  12456. + if (err) {
  12457. + return NULL;
  12458. + }
  12459. +
  12460. + return pkg_src;
  12461. +}
  12462. +
  12463. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
  12464. +{
  12465. + return void_list_push((void_list_t *) list, data);
  12466. +}
  12467. +
  12468. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
  12469. +{
  12470. + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
  12471. +}
  12472. --- /dev/null
  12473. +++ busybox-1.18.1/archival/libipkg/pkg_src_list.h
  12474. @@ -0,0 +1,57 @@
  12475. +/* pkg_src_list.h - the itsy package management system
  12476. +
  12477. + Carl D. Worth
  12478. +
  12479. + Copyright (C) 2001 University of Southern California
  12480. +
  12481. + This program is free software; you can redistribute it and/or
  12482. + modify it under the terms of the GNU General Public License as
  12483. + published by the Free Software Foundation; either version 2, or (at
  12484. + your option) any later version.
  12485. +
  12486. + This program is distributed in the hope that it will be useful, but
  12487. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12488. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12489. + General Public License for more details.
  12490. +*/
  12491. +
  12492. +#ifndef PKG_SRC_LIST_H
  12493. +#define PKG_SRC_LIST_H
  12494. +
  12495. +#include "pkg_src.h"
  12496. +
  12497. +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
  12498. +struct pkg_src_list_elt
  12499. +{
  12500. + pkg_src_list_elt_t *next;
  12501. + pkg_src_t *data;
  12502. +};
  12503. +
  12504. +typedef struct pkg_src_list pkg_src_list_t;
  12505. +struct pkg_src_list
  12506. +{
  12507. + pkg_src_list_elt_t pre_head;
  12508. + pkg_src_list_elt_t *head;
  12509. + pkg_src_list_elt_t *tail;
  12510. +};
  12511. +
  12512. +static inline int pkg_src_list_empty(pkg_src_list_t *list)
  12513. +{
  12514. + if (list->head == NULL)
  12515. + return 1;
  12516. + else
  12517. + return 0;
  12518. +}
  12519. +
  12520. +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
  12521. +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
  12522. +
  12523. +int pkg_src_list_init(pkg_src_list_t *list);
  12524. +void pkg_src_list_deinit(pkg_src_list_t *list);
  12525. +
  12526. +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list, const char *name, const char *root_dir, const char *extra_data, int gzip);
  12527. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
  12528. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
  12529. +
  12530. +#endif
  12531. +
  12532. --- /dev/null
  12533. +++ busybox-1.18.1/archival/libipkg/pkg_vec.c
  12534. @@ -0,0 +1,231 @@
  12535. +/* pkg_vec.c - the itsy package management system
  12536. +
  12537. + Steven M. Ayer
  12538. +
  12539. + Copyright (C) 2002 Compaq Computer Corporation
  12540. +
  12541. + This program is free software; you can redistribute it and/or
  12542. + modify it under the terms of the GNU General Public License as
  12543. + published by the Free Software Foundation; either version 2, or (at
  12544. + your option) any later version.
  12545. +
  12546. + This program is distributed in the hope that it will be useful, but
  12547. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12548. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12549. + General Public License for more details.
  12550. +*/
  12551. +
  12552. +#include <stdlib.h>
  12553. +#include <fnmatch.h>
  12554. +#include "libbb.h"
  12555. +#include "xregex.h"
  12556. +#include "ipkg.h"
  12557. +#include "pkg.h"
  12558. +
  12559. +pkg_vec_t * pkg_vec_alloc(void)
  12560. +{
  12561. + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
  12562. + if (!vec) {
  12563. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12564. + return NULL;
  12565. + }
  12566. + vec->pkgs = NULL;
  12567. + vec->len = 0;
  12568. +
  12569. + return vec;
  12570. +}
  12571. +
  12572. +void pkg_vec_free(pkg_vec_t *vec)
  12573. +{
  12574. + free(vec->pkgs);
  12575. + free(vec);
  12576. +}
  12577. +
  12578. +/*
  12579. + * assumption: all names in a vector are identical
  12580. + * assumption: all version strings are trimmed,
  12581. + * so identical versions have identical version strings,
  12582. + * implying identical packages; let's marry these
  12583. + */
  12584. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  12585. +{
  12586. + int i;
  12587. + int found = 0;
  12588. +
  12589. + /* look for a duplicate pkg by name, version, and architecture */
  12590. + for (i = 0; i < vec->len; i++){
  12591. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
  12592. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
  12593. + vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
  12594. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12595. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12596. + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
  12597. + found = 1;
  12598. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
  12599. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12600. + break;
  12601. + }
  12602. + }
  12603. +
  12604. + /* we didn't find one, add it */
  12605. + if (!found){
  12606. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
  12607. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12608. +
  12609. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12610. + vec->pkgs[vec->len] = pkg;
  12611. + vec->len++;
  12612. + return pkg;
  12613. + }
  12614. + /* update the one that we have */
  12615. + else {
  12616. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
  12617. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12618. + if (set_status) {
  12619. + /* this is from the status file, so need to merge with existing database */
  12620. + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
  12621. + pkg_merge(vec->pkgs[i], pkg, set_status);
  12622. + /* XXX: CLEANUP: It's not so polite to free something here
  12623. + that was passed in from above. */
  12624. + pkg_deinit(pkg);
  12625. + free(pkg);
  12626. + } else {
  12627. + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
  12628. + /* just overwrite the old one */
  12629. + pkg_deinit(vec->pkgs[i]);
  12630. + free(vec->pkgs[i]);
  12631. + vec->pkgs[i] = pkg;
  12632. + }
  12633. + return vec->pkgs[i];
  12634. + }
  12635. +}
  12636. +
  12637. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
  12638. +{
  12639. + int i;
  12640. + int found = 0;
  12641. +
  12642. + /* look for a duplicate pkg by name, version, and architecture */
  12643. + for (i = 0; i < vec->len; i++)
  12644. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12645. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12646. + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
  12647. + found = 1;
  12648. + break;
  12649. + }
  12650. +
  12651. + /* we didn't find one, add it */
  12652. + if(!found){
  12653. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12654. + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
  12655. + vec->len++;
  12656. + }
  12657. +}
  12658. +
  12659. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
  12660. +{
  12661. + int i;
  12662. + for (i = 0; i < vec->len; i++)
  12663. + if (vec->pkgs[i] == apkg)
  12664. + return 1;
  12665. + return 0;
  12666. +}
  12667. +
  12668. +typedef int (*compare_fcn_t)(const void *, const void *);
  12669. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
  12670. +{
  12671. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12672. +}
  12673. +
  12674. +int pkg_vec_clear_marks(pkg_vec_t *vec)
  12675. +{
  12676. + int npkgs = vec->len;
  12677. + int i;
  12678. + for (i = 0; i < npkgs; i++) {
  12679. + pkg_t *pkg = vec->pkgs[i];
  12680. + pkg->state_flag &= ~SF_MARKED;
  12681. + }
  12682. + return 0;
  12683. +}
  12684. +
  12685. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
  12686. +{
  12687. + int matching_count = 0;
  12688. + pkg_t **pkgs = vec->pkgs;
  12689. + int npkgs = vec->len;
  12690. + int i;
  12691. + for (i = 0; i < npkgs; i++) {
  12692. + pkg_t *pkg = pkgs[i];
  12693. + if (fnmatch(pattern, pkg->name, 0)==0) {
  12694. + pkg->state_flag |= SF_MARKED;
  12695. + matching_count++;
  12696. + }
  12697. + }
  12698. + return matching_count;
  12699. +}
  12700. +
  12701. +
  12702. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
  12703. +{
  12704. + abstract_pkg_vec_t * vec ;
  12705. + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
  12706. + if (!vec) {
  12707. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12708. + return NULL;
  12709. + }
  12710. + vec->pkgs = NULL;
  12711. + vec->len = 0;
  12712. +
  12713. + return vec;
  12714. +}
  12715. +
  12716. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
  12717. +{
  12718. + free(vec->pkgs);
  12719. + free(vec);
  12720. +}
  12721. +
  12722. +/*
  12723. + * assumption: all names in a vector are unique
  12724. + */
  12725. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
  12726. +{
  12727. + int i;
  12728. +
  12729. + /* look for a duplicate pkg by name */
  12730. + for(i = 0; i < vec->len; i++)
  12731. + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12732. + break;
  12733. +
  12734. + /* we didn't find one, add it */
  12735. + if(i == vec->len){
  12736. + vec->pkgs =
  12737. + (abstract_pkg_t **)
  12738. + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
  12739. + vec->pkgs[vec->len] = pkg;
  12740. + vec->len++;
  12741. + }
  12742. +}
  12743. +
  12744. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
  12745. +{
  12746. + if (vec->len > i)
  12747. + return vec->pkgs[i];
  12748. + else
  12749. + return NULL;
  12750. +}
  12751. +
  12752. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
  12753. +{
  12754. + int i;
  12755. + for (i = 0; i < vec->len; i++)
  12756. + if (vec->pkgs[i] == apkg)
  12757. + return 1;
  12758. + return 0;
  12759. +}
  12760. +
  12761. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
  12762. +{
  12763. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12764. +}
  12765. +
  12766. --- /dev/null
  12767. +++ busybox-1.18.1/archival/libipkg/pkg_vec.h
  12768. @@ -0,0 +1,62 @@
  12769. +/* pkg_vec.h - the itsy package management system
  12770. +
  12771. + Steven M. Ayer
  12772. +
  12773. + Copyright (C) 2002 Compaq Computer Corporation
  12774. +
  12775. + This program is free software; you can redistribute it and/or
  12776. + modify it under the terms of the GNU General Public License as
  12777. + published by the Free Software Foundation; either version 2, or (at
  12778. + your option) any later version.
  12779. +
  12780. + This program is distributed in the hope that it will be useful, but
  12781. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12782. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12783. + General Public License for more details.
  12784. +*/
  12785. +
  12786. +#ifndef PKG_VEC_H
  12787. +#define PKG_VEC_H
  12788. +
  12789. +typedef struct pkg pkg_t;
  12790. +typedef struct abstract_pkg abstract_pkg_t;
  12791. +
  12792. +struct pkg_vec
  12793. +{
  12794. + pkg_t **pkgs;
  12795. + int len;
  12796. +};
  12797. +typedef struct pkg_vec pkg_vec_t;
  12798. +
  12799. +struct abstract_pkg_vec
  12800. +{
  12801. + abstract_pkg_t **pkgs;
  12802. + int len;
  12803. +};
  12804. +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
  12805. +
  12806. +
  12807. +pkg_vec_t * pkg_vec_alloc(void);
  12808. +void pkg_vec_free(pkg_vec_t *vec);
  12809. +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
  12810. +
  12811. +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
  12812. +/* pkg_vec_insert_merge: might munge pkg.
  12813. +* returns the pkg that is in the pkg graph */
  12814. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
  12815. +/* this one never munges pkg */
  12816. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
  12817. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
  12818. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
  12819. +
  12820. +int pkg_vec_clear_marks(pkg_vec_t *vec);
  12821. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
  12822. +
  12823. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
  12824. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
  12825. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
  12826. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
  12827. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
  12828. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
  12829. +#endif
  12830. +
  12831. --- /dev/null
  12832. +++ busybox-1.18.1/archival/libipkg/sprintf_alloc.h
  12833. @@ -0,0 +1,25 @@
  12834. +/* sprintf_alloca.c -- like sprintf with memory allocation
  12835. +
  12836. + Carl D. Worth
  12837. +
  12838. + Copyright (C) 2001 University of Southern California
  12839. +
  12840. + This program is free software; you can redistribute it and/or modify
  12841. + it under the terms of the GNU General Public License as published by
  12842. + the Free Software Foundation; either version 2, or (at your option)
  12843. + any later version.
  12844. +
  12845. + This program is distributed in the hope that it will be useful,
  12846. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  12847. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12848. + GNU General Public License for more details.
  12849. +*/
  12850. +
  12851. +#ifndef SPRINTF_ALLOC_H
  12852. +#define SPRINTF_ALLOC_H
  12853. +
  12854. +#include "libbb.h"
  12855. +
  12856. +#define sprintf_alloc(str, fmt, args...) *str = xasprintf(fmt, ## args)
  12857. +
  12858. +#endif
  12859. --- /dev/null
  12860. +++ busybox-1.18.1/archival/libipkg/str_list.c
  12861. @@ -0,0 +1,76 @@
  12862. +/* str_list.c - the itsy package management system
  12863. +
  12864. + Carl D. Worth
  12865. +
  12866. + Copyright (C) 2001 University of Southern California
  12867. +
  12868. + This program is free software; you can redistribute it and/or
  12869. + modify it under the terms of the GNU General Public License as
  12870. + published by the Free Software Foundation; either version 2, or (at
  12871. + your option) any later version.
  12872. +
  12873. + This program is distributed in the hope that it will be useful, but
  12874. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12875. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12876. + General Public License for more details.
  12877. +*/
  12878. +
  12879. +#include "ipkg.h"
  12880. +
  12881. +#include "str_list.h"
  12882. +
  12883. +int str_list_elt_init(str_list_elt_t *elt, char *data)
  12884. +{
  12885. + return void_list_elt_init((void_list_elt_t *) elt, data);
  12886. +}
  12887. +
  12888. +void str_list_elt_deinit(str_list_elt_t *elt)
  12889. +{
  12890. + void_list_elt_deinit((void_list_elt_t *) elt);
  12891. +}
  12892. +
  12893. +str_list_t *str_list_alloc(void)
  12894. +{
  12895. + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
  12896. + if (list)
  12897. + str_list_init(list);
  12898. + return list;
  12899. +}
  12900. +
  12901. +int str_list_init(str_list_t *list)
  12902. +{
  12903. + return void_list_init((void_list_t *) list);
  12904. +}
  12905. +
  12906. +void str_list_deinit(str_list_t *list)
  12907. +{
  12908. + void_list_deinit((void_list_t *) list);
  12909. +}
  12910. +
  12911. +int str_list_append(str_list_t *list, char *data)
  12912. +{
  12913. + return void_list_append((void_list_t *) list, data);
  12914. +}
  12915. +
  12916. +int str_list_push(str_list_t *list, char *data)
  12917. +{
  12918. + return void_list_push((void_list_t *) list, data);
  12919. +}
  12920. +
  12921. +str_list_elt_t *str_list_pop(str_list_t *list)
  12922. +{
  12923. + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
  12924. +}
  12925. +
  12926. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
  12927. +{
  12928. + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
  12929. + (void_list_elt_t **) iter);
  12930. +}
  12931. +
  12932. +char *str_list_remove_elt(str_list_t *list, const char *target_str)
  12933. +{
  12934. + return (char *)void_list_remove_elt((void_list_t *) list,
  12935. + (void *)target_str,
  12936. + (void_list_cmp_t)strcmp);
  12937. +}
  12938. --- /dev/null
  12939. +++ busybox-1.18.1/archival/libipkg/str_list.h
  12940. @@ -0,0 +1,51 @@
  12941. +/* str_list.h - the itsy package management system
  12942. +
  12943. + Carl D. Worth
  12944. +
  12945. + Copyright (C) 2001 University of Southern California
  12946. +
  12947. + This program is free software; you can redistribute it and/or
  12948. + modify it under the terms of the GNU General Public License as
  12949. + published by the Free Software Foundation; either version 2, or (at
  12950. + your option) any later version.
  12951. +
  12952. + This program is distributed in the hope that it will be useful, but
  12953. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12954. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12955. + General Public License for more details.
  12956. +*/
  12957. +
  12958. +#ifndef STR_LIST_H
  12959. +#define STR_LIST_H
  12960. +
  12961. +#include "void_list.h"
  12962. +
  12963. +typedef struct str_list_elt str_list_elt_t;
  12964. +struct str_list_elt
  12965. +{
  12966. + str_list_elt_t *next;
  12967. + char *data;
  12968. +};
  12969. +
  12970. +typedef struct xstr_list str_list_t;
  12971. +struct xstr_list
  12972. +{
  12973. + str_list_elt_t pre_head;
  12974. + str_list_elt_t *head;
  12975. + str_list_elt_t *tail;
  12976. +};
  12977. +
  12978. +int str_list_elt_init(str_list_elt_t *elt, char *data);
  12979. +void str_list_elt_deinit(str_list_elt_t *elt);
  12980. +
  12981. +str_list_t *str_list_alloc(void);
  12982. +int str_list_init(str_list_t *list);
  12983. +void str_list_deinit(str_list_t *list);
  12984. +
  12985. +int str_list_append(str_list_t *list, char *data);
  12986. +int str_list_push(str_list_t *list, char *data);
  12987. +str_list_elt_t *str_list_pop(str_list_t *list);
  12988. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
  12989. +char *str_list_remove_elt(str_list_t *list, const char *target_str);
  12990. +
  12991. +#endif
  12992. --- /dev/null
  12993. +++ busybox-1.18.1/archival/libipkg/str_util.c
  12994. @@ -0,0 +1,69 @@
  12995. +/* str_utils.c - the itsy package management system
  12996. +
  12997. + Carl D. Worth
  12998. +
  12999. + Copyright (C) 2001 University of Southern California
  13000. +
  13001. + This program is free software; you can redistribute it and/or
  13002. + modify it under the terms of the GNU General Public License as
  13003. + published by the Free Software Foundation; either version 2, or (at
  13004. + your option) any later version.
  13005. +
  13006. + This program is distributed in the hope that it will be useful, but
  13007. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13008. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13009. + General Public License for more details.
  13010. +*/
  13011. +
  13012. +#include "ipkg.h"
  13013. +
  13014. +int str_starts_with(const char *str, const char *prefix);
  13015. +int str_ends_with(const char *str, const char *suffix);
  13016. +int str_chomp(char *str);
  13017. +int str_toupper(char *str);
  13018. +char *str_dup_safe(const char *str);
  13019. +
  13020. +int str_starts_with(const char *str, const char *prefix)
  13021. +{
  13022. + return (strncmp(str, prefix, strlen(prefix)) == 0);
  13023. +}
  13024. +
  13025. +int str_ends_with(const char *str, const char *suffix)
  13026. +{
  13027. + int suffix_len;
  13028. + int str_len;
  13029. +
  13030. + str_len = strlen(str);
  13031. + suffix_len = strlen(suffix);
  13032. +
  13033. + if (str_len < suffix_len) {
  13034. + return 0;
  13035. + }
  13036. +
  13037. + return (strcmp(str + str_len - suffix_len, suffix) == 0);
  13038. +}
  13039. +
  13040. +int str_chomp(char *str)
  13041. +{
  13042. + if (str[strlen(str) - 1] == '\n') {
  13043. + str[strlen(str) - 1] = '\0';
  13044. + return 1;
  13045. + }
  13046. + return 0;
  13047. +}
  13048. +
  13049. +int str_toupper(char *str)
  13050. +{
  13051. + while (*str) {
  13052. + *str = toupper(*str);
  13053. + str++;
  13054. + }
  13055. +
  13056. + return 0;
  13057. +}
  13058. +
  13059. +char *str_dup_safe(const char *str)
  13060. +{
  13061. + return str ? strdup(str) : NULL;
  13062. +}
  13063. +
  13064. --- /dev/null
  13065. +++ busybox-1.18.1/archival/libipkg/str_util.h
  13066. @@ -0,0 +1,27 @@
  13067. +/* str_utils.h - the itsy package management system
  13068. +
  13069. + Carl D. Worth
  13070. +
  13071. + Copyright (C) 2001 University of Southern California
  13072. +
  13073. + This program is free software; you can redistribute it and/or
  13074. + modify it under the terms of the GNU General Public License as
  13075. + published by the Free Software Foundation; either version 2, or (at
  13076. + your option) any later version.
  13077. +
  13078. + This program is distributed in the hope that it will be useful, but
  13079. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13080. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13081. + General Public License for more details.
  13082. +*/
  13083. +
  13084. +#ifndef STR_UTILS_H
  13085. +#define STR_UTILS_H
  13086. +
  13087. +int str_starts_with(const char *str, const char *prefix);
  13088. +int str_ends_with(const char *str, const char *suffix);
  13089. +int str_chomp(char *str);
  13090. +int str_toupper(char *str);
  13091. +char *str_dup_safe(const char *str);
  13092. +
  13093. +#endif
  13094. --- /dev/null
  13095. +++ busybox-1.18.1/archival/libipkg/user.c
  13096. @@ -0,0 +1,49 @@
  13097. +/* user.c - the itsy package management system
  13098. +
  13099. + Jamey Hicks
  13100. +
  13101. + Copyright (C) 2002 Hewlett Packard Company
  13102. + Copyright (C) 2001 University of Southern California
  13103. +
  13104. + This program is free software; you can redistribute it and/or
  13105. + modify it under the terms of the GNU General Public License as
  13106. + published by the Free Software Foundation; either version 2, or (at
  13107. + your option) any later version.
  13108. +
  13109. + This program is distributed in the hope that it will be useful, but
  13110. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13111. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13112. + General Public License for more details.
  13113. +*/
  13114. +
  13115. +#include <stdio.h>
  13116. +#include <stdarg.h>
  13117. +#include "libbb.h"
  13118. +#include "file_util.h"
  13119. +#include "str_util.h"
  13120. +#include "libipkg.h"
  13121. +
  13122. +char *get_user_response(const char *format, ...);
  13123. +static char *question = NULL;
  13124. +static int question_len = 255;
  13125. +
  13126. +char *get_user_response(const char *format, ...)
  13127. +{
  13128. + int len = question_len;
  13129. + va_list ap;
  13130. + char *response;
  13131. + va_start(ap, format);
  13132. +
  13133. + do {
  13134. + if (question == NULL || len > question_len) {
  13135. + question = realloc(question, len + 1);
  13136. + question_len = len;
  13137. + }
  13138. + len = vsnprintf(question,question_len,format,ap);
  13139. + } while (len > question_len);
  13140. + response = strdup(ipkg_cb_response(question));
  13141. + str_chomp(response);
  13142. + str_tolower(response);
  13143. +
  13144. + return response;
  13145. +}
  13146. --- /dev/null
  13147. +++ busybox-1.18.1/archival/libipkg/user.h
  13148. @@ -0,0 +1,23 @@
  13149. +/* user.c - the itsy package management system
  13150. +
  13151. + Jamey Hicks
  13152. +
  13153. + Copyright (C) 2002 Hewlett Packard Company
  13154. + Copyright (C) 2001 University of Southern California
  13155. +
  13156. + This program is free software; you can redistribute it and/or
  13157. + modify it under the terms of the GNU General Public License as
  13158. + published by the Free Software Foundation; either version 2, or (at
  13159. + your option) any later version.
  13160. +
  13161. + This program is distributed in the hope that it will be useful, but
  13162. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13163. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13164. + General Public License for more details.
  13165. +*/
  13166. +
  13167. +#include <stdio.h>
  13168. +#include <stdarg.h>
  13169. +
  13170. +char *get_user_response(const char *format, ...);
  13171. +
  13172. --- /dev/null
  13173. +++ busybox-1.18.1/archival/libipkg/void_list.c
  13174. @@ -0,0 +1,194 @@
  13175. +/* void_list.c - the itsy package management system
  13176. +
  13177. + Carl D. Worth
  13178. +
  13179. + Copyright (C) 2001 University of Southern California
  13180. +
  13181. + This program is free software; you can redistribute it and/or
  13182. + modify it under the terms of the GNU General Public License as
  13183. + published by the Free Software Foundation; either version 2, or (at
  13184. + your option) any later version.
  13185. +
  13186. + This program is distributed in the hope that it will be useful, but
  13187. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13188. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13189. + General Public License for more details.
  13190. +*/
  13191. +
  13192. +#include "ipkg.h"
  13193. +#include <errno.h>
  13194. +
  13195. +#include "void_list.h"
  13196. +
  13197. +int void_list_elt_init(void_list_elt_t *elt, void *data)
  13198. +{
  13199. + elt->next = NULL;
  13200. + elt->data = data;
  13201. +
  13202. + return 0;
  13203. +}
  13204. +
  13205. +void void_list_elt_deinit(void_list_elt_t *elt)
  13206. +{
  13207. + void_list_elt_init(elt, NULL);
  13208. +}
  13209. +
  13210. +int void_list_init(void_list_t *list)
  13211. +{
  13212. + void_list_elt_init(&list->pre_head, NULL);
  13213. + list->head = NULL;
  13214. + list->pre_head.next = list->head;
  13215. + list->tail = NULL;
  13216. +
  13217. + return 0;
  13218. +}
  13219. +
  13220. +void void_list_deinit(void_list_t *list)
  13221. +{
  13222. + void_list_elt_t *elt;
  13223. +
  13224. + while (list->head) {
  13225. + elt = void_list_pop(list);
  13226. + void_list_elt_deinit(elt);
  13227. + /* malloced in void_list_append */
  13228. + free(elt);
  13229. + }
  13230. +}
  13231. +
  13232. +int void_list_append(void_list_t *list, void *data)
  13233. +{
  13234. + void_list_elt_t *elt;
  13235. +
  13236. + /* freed in void_list_deinit */
  13237. + elt = malloc(sizeof(void_list_elt_t));
  13238. + if (elt == NULL) {
  13239. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13240. + return ENOMEM;
  13241. + }
  13242. +
  13243. + void_list_elt_init(elt, data);
  13244. +
  13245. + if (list->tail) {
  13246. + list->tail->next = elt;
  13247. + list->tail = elt;
  13248. + } else {
  13249. + list->head = elt;
  13250. + list->pre_head.next = list->head;
  13251. + list->tail = elt;
  13252. + }
  13253. +
  13254. + return 0;
  13255. +}
  13256. +
  13257. +int void_list_push(void_list_t *list, void *data)
  13258. +{
  13259. + void_list_elt_t *elt;
  13260. +
  13261. + elt = malloc(sizeof(void_list_elt_t));
  13262. + if (elt == NULL) {
  13263. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13264. + return ENOMEM;
  13265. + }
  13266. +
  13267. + void_list_elt_init(elt, data);
  13268. +
  13269. + elt->next = list->head;
  13270. + list->head->next = elt;
  13271. + if (list->tail == NULL) {
  13272. + list->tail = list->head;
  13273. + }
  13274. +
  13275. + return 0;
  13276. +}
  13277. +
  13278. +void_list_elt_t *void_list_pop(void_list_t *list)
  13279. +{
  13280. + void_list_elt_t *elt;
  13281. +
  13282. + elt = list->head;
  13283. +
  13284. + if (list->head) {
  13285. + list->head = list->head->next;
  13286. + list->pre_head.next = list->head;
  13287. + if (list->head == NULL) {
  13288. + list->tail = NULL;
  13289. + }
  13290. + }
  13291. +
  13292. + return elt;
  13293. +}
  13294. +
  13295. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
  13296. +{
  13297. + void_list_elt_t *prior;
  13298. + void_list_elt_t *old_elt;
  13299. + void *old_data;
  13300. +
  13301. + old_elt = *iter;
  13302. + old_data = old_elt->data;
  13303. +
  13304. + if (old_elt == list->head) {
  13305. + prior = &list->pre_head;
  13306. + void_list_pop(list);
  13307. + } else {
  13308. + for (prior = list->head; prior; prior = prior->next) {
  13309. + if (prior->next == old_elt) {
  13310. + break;
  13311. + }
  13312. + }
  13313. + if (prior == NULL || prior->next != old_elt) {
  13314. + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
  13315. + return NULL;
  13316. + }
  13317. + prior->next = old_elt->next;
  13318. +
  13319. + if (old_elt == list->tail) {
  13320. + list->tail = prior;
  13321. + }
  13322. + }
  13323. +
  13324. + void_list_elt_deinit(old_elt);
  13325. + *iter = prior;
  13326. +
  13327. + return old_data;
  13328. +}
  13329. +
  13330. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13331. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
  13332. +{
  13333. + void_list_elt_t *prior;
  13334. + void_list_elt_t *old_elt = NULL;
  13335. + void *old_data = NULL;
  13336. +
  13337. + /* first element */
  13338. + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
  13339. + old_elt = list->head;
  13340. + old_data = list->head->data;
  13341. + void_list_pop(list);
  13342. + } else {
  13343. + int found = 0;
  13344. + for (prior = list->head; prior && prior->next; prior = prior->next) {
  13345. + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
  13346. + old_elt = prior->next;
  13347. + old_data = old_elt->data;
  13348. + found = 1;
  13349. + break;
  13350. + }
  13351. + }
  13352. + if (!found) {
  13353. + return NULL;
  13354. + }
  13355. + prior->next = old_elt->next;
  13356. +
  13357. + if (old_elt == list->tail) {
  13358. + list->tail = prior;
  13359. + }
  13360. + }
  13361. + if (old_elt)
  13362. + void_list_elt_deinit(old_elt);
  13363. +
  13364. + if (old_data)
  13365. + return old_data;
  13366. + else
  13367. + return NULL;
  13368. +}
  13369. --- /dev/null
  13370. +++ busybox-1.18.1/archival/libipkg/void_list.h
  13371. @@ -0,0 +1,59 @@
  13372. +/* void_list.h - the itsy package management system
  13373. +
  13374. + Carl D. Worth
  13375. +
  13376. + Copyright (C) 2001 University of Southern California
  13377. +
  13378. + This program is free software; you can redistribute it and/or
  13379. + modify it under the terms of the GNU General Public License as
  13380. + published by the Free Software Foundation; either version 2, or (at
  13381. + your option) any later version.
  13382. +
  13383. + This program is distributed in the hope that it will be useful, but
  13384. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13385. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13386. + General Public License for more details.
  13387. +*/
  13388. +
  13389. +#ifndef VOID_LIST_H
  13390. +#define VOID_LIST_H
  13391. +
  13392. +typedef struct void_list_elt void_list_elt_t;
  13393. +struct void_list_elt
  13394. +{
  13395. + void_list_elt_t *next;
  13396. + void *data;
  13397. +};
  13398. +
  13399. +typedef struct void_list void_list_t;
  13400. +struct void_list
  13401. +{
  13402. + void_list_elt_t pre_head;
  13403. + void_list_elt_t *head;
  13404. + void_list_elt_t *tail;
  13405. +};
  13406. +
  13407. +static inline int void_list_empty(void_list_t *list)
  13408. +{
  13409. + if (list->head == NULL)
  13410. + return 1;
  13411. + else
  13412. + return 0;
  13413. +}
  13414. +
  13415. +int void_list_elt_init(void_list_elt_t *elt, void *data);
  13416. +void void_list_elt_deinit(void_list_elt_t *elt);
  13417. +
  13418. +int void_list_init(void_list_t *list);
  13419. +void void_list_deinit(void_list_t *list);
  13420. +
  13421. +int void_list_append(void_list_t *list, void *data);
  13422. +int void_list_push(void_list_t *list, void *data);
  13423. +void_list_elt_t *void_list_pop(void_list_t *list);
  13424. +
  13425. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
  13426. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13427. +typedef int (*void_list_cmp_t)(const void *, const void *);
  13428. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
  13429. +
  13430. +#endif
  13431. --- /dev/null
  13432. +++ busybox-1.18.1/archival/libipkg/xsystem.c
  13433. @@ -0,0 +1,64 @@
  13434. +/* xsystem.c - system(3) with error messages
  13435. +
  13436. + Carl D. Worth
  13437. +
  13438. + Copyright (C) 2001 University of Southern California
  13439. +
  13440. + This program is free software; you can redistribute it and/or
  13441. + modify it under the terms of the GNU General Public License as
  13442. + published by the Free Software Foundation; either version 2, or (at
  13443. + your option) any later version.
  13444. +
  13445. + This program is distributed in the hope that it will be useful, but
  13446. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13447. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13448. + General Public License for more details.
  13449. +*/
  13450. +
  13451. +#include "ipkg.h"
  13452. +#include <sys/wait.h>
  13453. +
  13454. +#include "xsystem.h"
  13455. +
  13456. +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
  13457. + really need the /bin/sh invocation which takes resources and
  13458. + introduces security problems. I should switch all of this to a sort
  13459. + of execl() or execv() interface/implementation.
  13460. +*/
  13461. +
  13462. +/* Like system(3), but with error messages printed if the fork fails
  13463. + or if the child process dies due to an uncaught signal. Also, the
  13464. + return value is a bit simpler:
  13465. +
  13466. + -1 if there was any problem
  13467. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13468. + as defined in <sys/wait.h>.
  13469. +*/
  13470. +int xsystem(const char *cmd)
  13471. +{
  13472. + int err;
  13473. +
  13474. + err = system(cmd);
  13475. +
  13476. + if (err == -1) {
  13477. + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
  13478. + __FUNCTION__, cmd);
  13479. + return -1;
  13480. + }
  13481. +
  13482. + if (WIFSIGNALED(err)) {
  13483. + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
  13484. + __FUNCTION__, WTERMSIG(err), cmd);
  13485. + return -1;
  13486. + }
  13487. +
  13488. + if (WIFEXITED(err)) {
  13489. + /* Normal child exit */
  13490. + return WEXITSTATUS(err);
  13491. + }
  13492. +
  13493. + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
  13494. + __FUNCTION__, err);
  13495. + return -1;
  13496. +}
  13497. +
  13498. --- /dev/null
  13499. +++ busybox-1.18.1/archival/libipkg/xsystem.h
  13500. @@ -0,0 +1,34 @@
  13501. +/* xsystem.h - system(3) with error messages
  13502. +
  13503. + Carl D. Worth
  13504. +
  13505. + Copyright (C) 2001 University of Southern California
  13506. +
  13507. + This program is free software; you can redistribute it and/or
  13508. + modify it under the terms of the GNU General Public License as
  13509. + published by the Free Software Foundation; either version 2, or (at
  13510. + your option) any later version.
  13511. +
  13512. + This program is distributed in the hope that it will be useful, but
  13513. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13514. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13515. + General Public License for more details.
  13516. +*/
  13517. +
  13518. +#ifndef XSYSTEM_H
  13519. +#define XSYSTEM_H
  13520. +
  13521. +#include <stdlib.h>
  13522. +
  13523. +/* Like system(3), but with error messages printed if the fork fails
  13524. + or if the child process dies due to an uncaught signal. Also, the
  13525. + return value is a bit simpler:
  13526. +
  13527. + -1 if there was any problem
  13528. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13529. + as defined in <sys/wait.h>.
  13530. +*/
  13531. +int xsystem(const char *cmd);
  13532. +
  13533. +#endif
  13534. +
  13535. --- busybox-1.18.1.orig/include/applets.src.h
  13536. +++ busybox-1.18.1/include/applets.src.h
  13537. @@ -195,6 +195,7 @@
  13538. IF_IPCALC(APPLET(ipcalc, _BB_DIR_BIN, _BB_SUID_DROP))
  13539. IF_IPCRM(APPLET(ipcrm, _BB_DIR_USR_BIN, _BB_SUID_REQUIRE))
  13540. IF_IPCS(APPLET(ipcs, _BB_DIR_USR_BIN, _BB_SUID_REQUIRE))
  13541. +IF_IPKG(APPLET(ipkg, _BB_DIR_USR_BIN, _BB_SUID_DROP))
  13542. IF_IPLINK(APPLET(iplink, _BB_DIR_BIN, _BB_SUID_DROP))
  13543. IF_IPROUTE(APPLET(iproute, _BB_DIR_BIN, _BB_SUID_DROP))
  13544. IF_IPRULE(APPLET(iprule, _BB_DIR_BIN, _BB_SUID_DROP))
  13545. --- busybox-1.18.1.orig/include/archive.h
  13546. +++ busybox-1.18.1/include/archive.h
  13547. @@ -95,7 +95,7 @@
  13548. struct hardlinks_t *cpio__hardlinks_to_create;
  13549. struct hardlinks_t *cpio__created_hardlinks;
  13550. #endif
  13551. -#if ENABLE_DPKG || ENABLE_DPKG_DEB
  13552. +#if ENABLE_DPKG || ENABLE_DPKG_DEB || ENABLE_IPKG
  13553. /* Temporary storage */
  13554. char *dpkg__buffer;
  13555. /* How to process any sub archive, e.g. get_header_tar_gz */
  13556. --- busybox-1.18.1.orig/include/usage.src.h
  13557. +++ busybox-1.18.1/include/usage.src.h
  13558. @@ -1919,6 +1919,82 @@
  13559. "\n -l Limits" \
  13560. "\n -u Summary" \
  13561. +#define ipkg_trivial_usage \
  13562. + "[options]... sub-command [arguments]..."
  13563. +#define ipkg_full_usage \
  13564. + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
  13565. + "\n" \
  13566. + "Sub-commands:\n" \
  13567. + "\nPackage Manipulation:\n" \
  13568. + "\tupdate Update list of available packages\n" \
  13569. + "\tupgrade Upgrade all installed packages to latest version\n" \
  13570. + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
  13571. + "\tinstall <file.ipk> Install package <file.ipk>\n" \
  13572. + "\tconfigure [<pkg>] Configure unpacked packages\n" \
  13573. + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
  13574. + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
  13575. + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
  13576. + "\n" \
  13577. + "Informational Commands:\n" \
  13578. + "\tlist List available packages and descriptions\n" \
  13579. + "\tlist_installed List all and only the installed packages and description \n" \
  13580. + "\tfiles <pkg> List all files belonging to <pkg>\n" \
  13581. + "\tsearch <file|regexp> Search for a package providing <file>\n" \
  13582. + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
  13583. + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
  13584. + "\tdownload <pkg> Download <pkg> to current directory.\n" \
  13585. + "\tcompare_versions <v1> <op> <v2>\n" \
  13586. + "\t compare versions using <= < > >= = << >>\n" \
  13587. + "\tprint_architecture prints the architecture.\n" \
  13588. + "\tprint_installation_architecture\n" \
  13589. + "\twhatdepends [-A] [pkgname|pat]+\n" \
  13590. + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
  13591. + "\twhatprovides [-A] [pkgname|pat]+\n" \
  13592. + "\twhatconflicts [-A] [pkgname|pat]+\n" \
  13593. + "\twhatreplaces [-A] [pkgname|pat]+\n" \
  13594. + "\t prints the installation architecture.\n" \
  13595. + "\n" \
  13596. + "\nOptions:\n" \
  13597. + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
  13598. + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
  13599. + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
  13600. + "\t 0 errors only\n" \
  13601. + "\t 1 normal messages (default)\n" \
  13602. + "\t 2 informative messages\n" \
  13603. + "\t 3 debug output\n" \
  13604. + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
  13605. + "\t-conf <conf_file> Default configuration file location\n" \
  13606. + " is /etc/ipkg.conf\n" \
  13607. + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
  13608. + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
  13609. + " <dest_name> should be a defined dest name from\n" \
  13610. + " the configuration file, (but can also be a\n" \
  13611. + " directory name in a pinch).\n" \
  13612. + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
  13613. + "\t-offline <offline_root> offline installation of packages.\n" \
  13614. + "\t-verbose_wget more wget messages\n" \
  13615. + "\n" \
  13616. + "Force Options (use when ipkg is too smart for its own good):\n" \
  13617. + "\t-force-depends Make dependency checks warnings instead of errors\n" \
  13618. + "\t Install/remove package in spite of failed dependences\n" \
  13619. + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
  13620. + " (no prompts). Note that this will not prevent\n" \
  13621. + " package installation scripts from prompting.\n" \
  13622. + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
  13623. + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
  13624. + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
  13625. + "\t-force_space Install even if there does not seem to be enough space.\n" \
  13626. + "\t-noaction No action -- test only\n" \
  13627. + "\t-nodeps Do not follow dependences\n" \
  13628. + "\t-force-removal-of-dependent-packages\n" \
  13629. + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
  13630. + "\t-test No action -- test only\n" \
  13631. + "\t-t Specify tmp-dir.\n" \
  13632. + "\t--tmp-dir Specify tmp-dir.\n" \
  13633. + "\n" \
  13634. + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
  13635. + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
  13636. +
  13637. #define iplink_trivial_usage \
  13638. "{ set DEVICE { up | down | arp { on | off } | show [DEVICE] }"
  13639. #define iplink_full_usage "\n\n" \