001-ipkg.patch 426 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797
  1. diff -Nur busybox-1.13.4.orig/Makefile busybox-1.13.4/Makefile
  2. --- busybox-1.13.4.orig/Makefile 2009-04-15 02:11:01.000000000 +0200
  3. +++ busybox-1.13.4/Makefile 2009-05-31 15:40:37.158023800 +0200
  4. @@ -444,6 +444,7 @@
  5. libs-y := \
  6. archival/ \
  7. + archival/libipkg/ \
  8. archival/libunarchive/ \
  9. console-tools/ \
  10. coreutils/ \
  11. diff -Nur busybox-1.13.4.orig/archival/Config.in busybox-1.13.4/archival/Config.in
  12. --- busybox-1.13.4.orig/archival/Config.in 2008-11-09 18:28:02.000000000 +0100
  13. +++ busybox-1.13.4/archival/Config.in 2009-05-31 15:40:36.993689729 +0200
  14. @@ -158,6 +158,14 @@
  15. gzip is used to compress files.
  16. It's probably the most widely used UNIX compression program.
  17. +config IPKG
  18. + bool "ipkg"
  19. + default n
  20. + select MD5SUM
  21. + select WGET
  22. + help
  23. + ipkg is the itsy package management system.
  24. +
  25. config RPM2CPIO
  26. bool "rpm2cpio"
  27. default n
  28. diff -Nur busybox-1.13.4.orig/archival/Kbuild busybox-1.13.4/archival/Kbuild
  29. --- busybox-1.13.4.orig/archival/Kbuild 2008-11-09 18:28:02.000000000 +0100
  30. +++ busybox-1.13.4/archival/Kbuild 2009-05-31 15:40:36.997989438 +0200
  31. @@ -16,6 +16,7 @@
  32. lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o
  33. lib-$(CONFIG_GUNZIP) += bbunzip.o
  34. lib-$(CONFIG_GZIP) += gzip.o bbunzip.o
  35. +lib-$(CONFIG_IPKG) += ipkg.o
  36. lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o
  37. lib-$(CONFIG_RPM) += rpm.o
  38. lib-$(CONFIG_TAR) += tar.o
  39. diff -Nur busybox-1.13.4.orig/archival/dpkg.c busybox-1.13.4/archival/dpkg.c
  40. --- busybox-1.13.4.orig/archival/dpkg.c 2008-11-09 18:28:02.000000000 +0100
  41. +++ busybox-1.13.4/archival/dpkg.c 2009-05-31 15:40:36.993689729 +0200
  42. @@ -1485,16 +1485,7 @@
  43. return ar_handle->sub_archive->buffer;
  44. }
  45. -static void FAST_FUNC data_extract_all_prefix(archive_handle_t *archive_handle)
  46. -{
  47. - char *name_ptr = archive_handle->file_header->name;
  48. -
  49. - name_ptr += strspn(name_ptr, "./");
  50. - if (name_ptr[0] != '\0') {
  51. - archive_handle->file_header->name = xasprintf("%s%s", archive_handle->buffer, name_ptr);
  52. - data_extract_all(archive_handle);
  53. - }
  54. -}
  55. +/* remove data_extract_all_prefix */
  56. static void unpack_package(deb_file_t *deb_file)
  57. {
  58. diff -Nur busybox-1.13.4.orig/archival/ipkg.c busybox-1.13.4/archival/ipkg.c
  59. --- busybox-1.13.4.orig/archival/ipkg.c 1970-01-01 01:00:00.000000000 +0100
  60. +++ busybox-1.13.4/archival/ipkg.c 2009-05-31 15:40:36.993689729 +0200
  61. @@ -0,0 +1,28 @@
  62. +/* ipkg.c - the itsy package management system
  63. +
  64. + Florina Boor
  65. +
  66. + Copyright (C) 2003 kernel concepts
  67. +
  68. + This program is free software; you can redistribute it and/or
  69. + modify it under the terms of the GNU General Public License as
  70. + published by the Free Software Foundation; either version 2, or (at
  71. + your option) any later version.
  72. +
  73. + This program is distributed in the hope that it will be useful, but
  74. + WITHOUT ANY WARRANTY; without even the implied warranty of
  75. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  76. + General Public License for more details.
  77. +
  78. + ipkg command line frontend using libipkg
  79. +
  80. +*/
  81. +
  82. +#include "libbb.h"
  83. +#include "libipkg/libipkg.h"
  84. +
  85. +int ipkg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  86. +int ipkg_main(int argc, char **argv)
  87. +{
  88. + return ipkg_op(argc, argv);
  89. +}
  90. diff -Nur busybox-1.13.4.orig/archival/libipkg/Kbuild busybox-1.13.4/archival/libipkg/Kbuild
  91. --- busybox-1.13.4.orig/archival/libipkg/Kbuild 1970-01-01 01:00:00.000000000 +0100
  92. +++ busybox-1.13.4/archival/libipkg/Kbuild 2009-05-31 15:40:37.069994700 +0200
  93. @@ -0,0 +1,60 @@
  94. +# Makefile for busybox
  95. +#
  96. +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
  97. +# Copyright (C) 2006 OpenWrt.org
  98. +#
  99. +# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
  100. +
  101. +LIBIPKG_CORE_OBJS:= \
  102. + args.o \
  103. + libipkg.o \
  104. + user.o \
  105. +
  106. +LIBIPKG_CMD_OBJS:= \
  107. + ipkg_cmd.o \
  108. + ipkg_configure.o \
  109. + ipkg_download.o \
  110. + ipkg_install.o \
  111. + ipkg_remove.o \
  112. + ipkg_upgrade.o \
  113. +
  114. +LIBIPKG_DB_OBJS:= \
  115. + hash_table.o \
  116. + ipkg_conf.o \
  117. + ipkg_utils.o \
  118. + pkg.o \
  119. + pkg_depends.o \
  120. + pkg_extract.o \
  121. + pkg_hash.o \
  122. + pkg_parse.o \
  123. + pkg_vec.o \
  124. +
  125. +LIBIPKG_LIST_OBJS:= \
  126. + conffile.o \
  127. + conffile_list.o \
  128. + nv_pair.o \
  129. + nv_pair_list.o \
  130. + pkg_dest.o \
  131. + pkg_dest_list.o \
  132. + pkg_src.o \
  133. + pkg_src_list.o \
  134. + str_list.o \
  135. + void_list.o \
  136. +
  137. +LIBIPKG_UTIL_OBJS:= \
  138. + file_util.o \
  139. + ipkg_message.o \
  140. + str_util.o \
  141. + xsystem.o \
  142. +
  143. +lib-y :=
  144. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CORE_OBJS)
  145. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CMD_OBJS)
  146. +lib-$(CONFIG_IPKG) += $(LIBIPKG_DB_OBJS)
  147. +lib-$(CONFIG_IPKG) += $(LIBIPKG_LIST_OBJS)
  148. +lib-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_OBJS)
  149. +
  150. +ifeq ($(strip $(IPKG_ARCH)),)
  151. +IPKG_ARCH:=$(TARGET_ARCH)
  152. +endif
  153. +CFLAGS += -DIPKG_LIB -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(IPKG_ARCH)\""
  154. diff -Nur busybox-1.13.4.orig/archival/libipkg/args.c busybox-1.13.4/archival/libipkg/args.c
  155. --- busybox-1.13.4.orig/archival/libipkg/args.c 1970-01-01 01:00:00.000000000 +0100
  156. +++ busybox-1.13.4/archival/libipkg/args.c 2009-05-31 15:40:36.997989438 +0200
  157. @@ -0,0 +1,242 @@
  158. +/* args.c - parse command-line args
  159. +
  160. + Carl D. Worth
  161. +
  162. + Copyright 2001 University of Southern California
  163. +
  164. + This program is free software; you can redistribute it and/or modify
  165. + it under the terms of the GNU General Public License as published by
  166. + the Free Software Foundation; either version 2, or (at your option)
  167. + any later version.
  168. +
  169. + This program is distributed in the hope that it will be useful,
  170. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  171. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  172. + GNU General Public License for more details.
  173. + */
  174. +
  175. +#include <getopt.h>
  176. +#include <stdlib.h>
  177. +#include <string.h>
  178. +#include <unistd.h>
  179. +
  180. +#include "ipkg.h"
  181. +#include "ipkg_message.h"
  182. +
  183. +#include "args.h"
  184. +#include "sprintf_alloc.h"
  185. +
  186. +#include "libbb.h"
  187. +
  188. +
  189. +static void print_version(void);
  190. +
  191. +enum long_args_opt
  192. +{
  193. + ARGS_OPT_FORCE_DEFAULTS = 129,
  194. + ARGS_OPT_FORCE_DEPENDS,
  195. + ARGS_OPT_FORCE_OVERWRITE,
  196. + ARGS_OPT_FORCE_DOWNGRADE,
  197. + ARGS_OPT_FORCE_REINSTALL,
  198. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
  199. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
  200. + ARGS_OPT_FORCE_SPACE,
  201. + ARGS_OPT_NOACTION,
  202. + ARGS_OPT_NODEPS,
  203. + ARGS_OPT_VERBOSE_WGET,
  204. + ARGS_OPT_VERBOSITY,
  205. + ARGS_OPT_MULTIPLE_PROVIDERS
  206. +};
  207. +
  208. +int args_init(args_t *args)
  209. +{
  210. + const char *conf_file_dir;
  211. +
  212. + memset(args, 0, sizeof(args_t));
  213. +
  214. + args->dest = ARGS_DEFAULT_DEST;
  215. +
  216. + conf_file_dir = getenv("IPKG_CONF_DIR");
  217. + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
  218. + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
  219. + }
  220. + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
  221. + ARGS_DEFAULT_CONF_FILE_NAME);
  222. +
  223. + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
  224. + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
  225. + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
  226. + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
  227. + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
  228. + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
  229. + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
  230. + args->noaction = ARGS_DEFAULT_NOACTION;
  231. + args->nodeps = ARGS_DEFAULT_NODEPS;
  232. + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
  233. + args->verbosity = ARGS_DEFAULT_VERBOSITY;
  234. + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
  235. + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
  236. + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
  237. + args->multiple_providers = 0;
  238. + args->nocheckfordirorfile = 0;
  239. + args->noreadfeedsfile = 0;
  240. +
  241. + return 1;
  242. +}
  243. +
  244. +void args_deinit(args_t *args)
  245. +{
  246. + free(args->conf_file);
  247. + args->conf_file = NULL;
  248. +}
  249. +
  250. +int args_parse(args_t *args, int argc, char *argv[])
  251. +{
  252. + int c;
  253. + int option_index = 0;
  254. + int parse_err = 0;
  255. + static struct option long_options[] = {
  256. + {"query-all", 0, 0, 'A'},
  257. + {"conf-file", 1, 0, 'f'},
  258. + {"conf", 1, 0, 'f'},
  259. + {"dest", 1, 0, 'd'},
  260. + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  261. + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  262. + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  263. + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  264. + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  265. + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  266. + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  267. + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  268. + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  269. + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  270. + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
  271. + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
  272. + {"recursive", 0, 0,
  273. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  274. + {"force-removal-of-dependent-packages", 0, 0,
  275. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  276. + {"force_removal_of_dependent_packages", 0, 0,
  277. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  278. + {"force-removal-of-essential-packages", 0, 0,
  279. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  280. + {"force_removal_of_essential_packages", 0, 0,
  281. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  282. + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  283. + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  284. + {"noaction", 0, 0, ARGS_OPT_NOACTION},
  285. + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
  286. + {"offline", 1, 0, 'o'},
  287. + {"offline-root", 1, 0, 'o'},
  288. + {"test", 0, 0, ARGS_OPT_NOACTION},
  289. + {"tmp-dir", 1, 0, 't'},
  290. + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  291. + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  292. + {"verbosity", 2, 0, 'V'},
  293. + {"version", 0, 0, 'v'},
  294. + {0, 0, 0, 0}
  295. + };
  296. +
  297. + while (1) {
  298. + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
  299. + if (c == -1)
  300. + break;
  301. +
  302. + switch (c) {
  303. + case 'A':
  304. + args->query_all = 1;
  305. + break;
  306. + case 'd':
  307. + args->dest = optarg;
  308. + break;
  309. + case 'f':
  310. + free(args->conf_file);
  311. + args->conf_file = strdup(optarg);
  312. + break;
  313. + case 'o':
  314. + args->offline_root = optarg;
  315. + break;
  316. + case 'n':
  317. + args->noaction = 1;
  318. + break;
  319. + case 't':
  320. + args->tmp_dir = strdup(optarg);
  321. + break;
  322. + case 'v':
  323. + print_version();
  324. + exit(0);
  325. + case 'V':
  326. + case ARGS_OPT_VERBOSITY:
  327. + if (optarg)
  328. + args->verbosity = atoi(optarg);
  329. + else
  330. + args->verbosity += 1;
  331. + break;
  332. + case ARGS_OPT_FORCE_DEFAULTS:
  333. + args->force_defaults = 1;
  334. + break;
  335. + case ARGS_OPT_FORCE_DEPENDS:
  336. + args->force_depends = 1;
  337. + break;
  338. + case ARGS_OPT_FORCE_OVERWRITE:
  339. + args->force_overwrite = 1;
  340. + break;
  341. + case ARGS_OPT_FORCE_DOWNGRADE:
  342. + args->force_downgrade = 1;
  343. + break;
  344. + case ARGS_OPT_FORCE_REINSTALL:
  345. + args->force_reinstall = 1;
  346. + break;
  347. + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
  348. + args->force_removal_of_essential_packages = 1;
  349. + break;
  350. + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
  351. + args->force_removal_of_dependent_packages = 1;
  352. + break;
  353. + case ARGS_OPT_FORCE_SPACE:
  354. + args->force_space = 1;
  355. + break;
  356. + case ARGS_OPT_VERBOSE_WGET:
  357. + args->verbose_wget = 1;
  358. + break;
  359. + case ARGS_OPT_MULTIPLE_PROVIDERS:
  360. + args->multiple_providers = 1;
  361. + break;
  362. + case ARGS_OPT_NODEPS:
  363. + args->nodeps = 1;
  364. + break;
  365. + case ARGS_OPT_NOACTION:
  366. + args->noaction = 1;
  367. + break;
  368. + case ':':
  369. + parse_err++;
  370. + break;
  371. + case '?':
  372. + parse_err++;
  373. + break;
  374. + default:
  375. + bb_error_msg("Confusion: getopt_long returned %d\n", c);
  376. + }
  377. + }
  378. +
  379. + if (parse_err) {
  380. + return -parse_err;
  381. + } else {
  382. + return optind;
  383. + }
  384. +}
  385. +
  386. +void args_usage(const char *complaint)
  387. +{
  388. + if (complaint) {
  389. + bb_error_msg("%s\n", complaint);
  390. + }
  391. + print_version();
  392. + bb_show_usage();
  393. + exit(1);
  394. +}
  395. +
  396. +static void print_version(void)
  397. +{
  398. + bb_error_msg("version %s\n", IPKG_VERSION);
  399. +}
  400. diff -Nur busybox-1.13.4.orig/archival/libipkg/args.h busybox-1.13.4/archival/libipkg/args.h
  401. --- busybox-1.13.4.orig/archival/libipkg/args.h 1970-01-01 01:00:00.000000000 +0100
  402. +++ busybox-1.13.4/archival/libipkg/args.h 2009-05-31 15:40:36.997989438 +0200
  403. @@ -0,0 +1,72 @@
  404. +/* args.h - parse command-line args
  405. +
  406. + Carl D. Worth
  407. +
  408. + Copyright 2001 University of Southern California
  409. +
  410. + This program is free software; you can redistribute it and/or modify
  411. + it under the terms of the GNU General Public License as published by
  412. + the Free Software Foundation; either version 2, or (at your option)
  413. + any later version.
  414. +
  415. + This program is distributed in the hope that it will be useful,
  416. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  417. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  418. + GNU General Public License for more details.
  419. +*/
  420. +
  421. +#ifndef ARGS_H
  422. +#define ARGS_H
  423. +
  424. +struct args
  425. +{
  426. + char *conf_file;
  427. + char *dest;
  428. + char *tmp_dir;
  429. + int force_defaults;
  430. + int force_depends;
  431. + int force_overwrite;
  432. + int force_downgrade;
  433. + int force_reinstall;
  434. + int force_removal_of_essential_packages;
  435. + int force_removal_of_dependent_packages;
  436. + int force_space;
  437. + int noaction;
  438. + int nodeps;
  439. + int multiple_providers;
  440. + int query_all;
  441. + int verbose_wget;
  442. + int verbosity;
  443. + int nocheckfordirorfile;
  444. + int noreadfeedsfile;
  445. + char *offline_root;
  446. + char *offline_root_pre_script_cmd;
  447. + char *offline_root_post_script_cmd;
  448. +};
  449. +typedef struct args args_t;
  450. +
  451. +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
  452. +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
  453. +#define ARGS_DEFAULT_DEST NULL
  454. +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
  455. +#define ARGS_DEFAULT_FORCE_DEPENDS 0
  456. +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
  457. +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
  458. +#define ARGS_DEFAULT_FORCE_REINSTALL 0
  459. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
  460. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
  461. +#define ARGS_DEFAULT_FORCE_SPACE 0
  462. +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
  463. +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
  464. +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
  465. +#define ARGS_DEFAULT_NOACTION 0
  466. +#define ARGS_DEFAULT_NODEPS 0
  467. +#define ARGS_DEFAULT_VERBOSE_WGET 0
  468. +#define ARGS_DEFAULT_VERBOSITY 1
  469. +
  470. +int args_init(args_t *args);
  471. +void args_deinit(args_t *args);
  472. +int args_parse(args_t *args, int argc, char *argv[]);
  473. +void args_usage(const char *complaint);
  474. +
  475. +#endif
  476. diff -Nur busybox-1.13.4.orig/archival/libipkg/conffile.c busybox-1.13.4/archival/libipkg/conffile.c
  477. --- busybox-1.13.4.orig/archival/libipkg/conffile.c 1970-01-01 01:00:00.000000000 +0100
  478. +++ busybox-1.13.4/archival/libipkg/conffile.c 2009-05-31 15:40:36.997989438 +0200
  479. @@ -0,0 +1,65 @@
  480. +/* conffile.c - the itsy package management system
  481. +
  482. + Carl D. Worth
  483. +
  484. + Copyright (C) 2001 University of Southern California
  485. +
  486. + This program is free software; you can redistribute it and/or
  487. + modify it under the terms of the GNU General Public License as
  488. + published by the Free Software Foundation; either version 2, or (at
  489. + your option) any later version.
  490. +
  491. + This program is distributed in the hope that it will be useful, but
  492. + WITHOUT ANY WARRANTY; without even the implied warranty of
  493. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  494. + General Public License for more details.
  495. +*/
  496. +
  497. +#include <string.h>
  498. +#include <stdlib.h>
  499. +
  500. +#include "libbb.h"
  501. +#include "ipkg.h"
  502. +#include "ipkg_message.h"
  503. +
  504. +#include "conffile.h"
  505. +#include "file_util.h"
  506. +#include "sprintf_alloc.h"
  507. +
  508. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum)
  509. +{
  510. + return nv_pair_init(conffile, file_name, (char *)md5sum);
  511. +}
  512. +
  513. +void conffile_deinit(conffile_t *conffile)
  514. +{
  515. + nv_pair_deinit(conffile);
  516. +}
  517. +
  518. +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
  519. +{
  520. + uint8_t *md5sum;
  521. + char *filename = conffile->name;
  522. + char *root_filename;
  523. + int ret;
  524. +
  525. + if (conffile->value == NULL) {
  526. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
  527. + return 1;
  528. + }
  529. +
  530. + root_filename = root_filename_alloc(conf, filename);
  531. +
  532. + md5sum = file_md5sum_alloc(root_filename);
  533. +
  534. + ret = strcmp((char *)md5sum, conffile->value);
  535. + if (ret) {
  536. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
  537. + conffile->name, md5sum, conffile->value);
  538. + }
  539. +
  540. + free(root_filename);
  541. + free(md5sum);
  542. +
  543. + return ret;
  544. +}
  545. diff -Nur busybox-1.13.4.orig/archival/libipkg/conffile.h busybox-1.13.4/archival/libipkg/conffile.h
  546. --- busybox-1.13.4.orig/archival/libipkg/conffile.h 1970-01-01 01:00:00.000000000 +0100
  547. +++ busybox-1.13.4/archival/libipkg/conffile.h 2009-05-31 15:40:36.997989438 +0200
  548. @@ -0,0 +1,30 @@
  549. +/* conffile.h - the itsy package management system
  550. +
  551. + Carl D. Worth
  552. +
  553. + Copyright (C) 2001 University of Southern California
  554. +
  555. + This program is free software; you can redistribute it and/or
  556. + modify it under the terms of the GNU General Public License as
  557. + published by the Free Software Foundation; either version 2, or (at
  558. + your option) any later version.
  559. +
  560. + This program is distributed in the hope that it will be useful, but
  561. + WITHOUT ANY WARRANTY; without even the implied warranty of
  562. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  563. + General Public License for more details.
  564. +*/
  565. +
  566. +#ifndef CONFFILE_H
  567. +#define CONFFILE_H
  568. +
  569. +#include "nv_pair.h"
  570. +
  571. +typedef struct nv_pair conffile_t;
  572. +
  573. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum);
  574. +void conffile_deinit(conffile_t *conffile);
  575. +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
  576. +
  577. +#endif
  578. +
  579. diff -Nur busybox-1.13.4.orig/archival/libipkg/conffile_list.c busybox-1.13.4/archival/libipkg/conffile_list.c
  580. --- busybox-1.13.4.orig/archival/libipkg/conffile_list.c 1970-01-01 01:00:00.000000000 +0100
  581. +++ busybox-1.13.4/archival/libipkg/conffile_list.c 2009-05-31 15:40:37.001989668 +0200
  582. @@ -0,0 +1,47 @@
  583. +/* conffile_list.c - the itsy package management system
  584. +
  585. + Carl D. Worth
  586. +
  587. + Copyright (C) 2001 University of Southern California
  588. +
  589. + This program is free software; you can redistribute it and/or
  590. + modify it under the terms of the GNU General Public License as
  591. + published by the Free Software Foundation; either version 2, or (at
  592. + your option) any later version.
  593. +
  594. + This program is distributed in the hope that it will be useful, but
  595. + WITHOUT ANY WARRANTY; without even the implied warranty of
  596. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  597. + General Public License for more details.
  598. +*/
  599. +
  600. +#include "ipkg.h"
  601. +
  602. +#include "conffile_list.h"
  603. +
  604. +int conffile_list_init(conffile_list_t *list)
  605. +{
  606. + return nv_pair_list_init(list);
  607. +}
  608. +
  609. +void conffile_list_deinit(conffile_list_t *list)
  610. +{
  611. + nv_pair_list_deinit(list);
  612. +}
  613. +
  614. +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
  615. + const char *md5sum)
  616. +{
  617. + return nv_pair_list_append(list, file_name, md5sum);
  618. +}
  619. +
  620. +int conffile_list_push(conffile_list_t *list, conffile_t *data)
  621. +{
  622. + return nv_pair_list_push(list, data);
  623. +}
  624. +
  625. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
  626. +{
  627. + return nv_pair_list_pop(list);
  628. +}
  629. +
  630. diff -Nur busybox-1.13.4.orig/archival/libipkg/conffile_list.h busybox-1.13.4/archival/libipkg/conffile_list.h
  631. --- busybox-1.13.4.orig/archival/libipkg/conffile_list.h 1970-01-01 01:00:00.000000000 +0100
  632. +++ busybox-1.13.4/archival/libipkg/conffile_list.h 2009-05-31 15:40:37.005990736 +0200
  633. @@ -0,0 +1,36 @@
  634. +/* conffile_list.h - the itsy package management system
  635. +
  636. + Carl D. Worth
  637. +
  638. + Copyright (C) 2001 University of Southern California
  639. +
  640. + This program is free software; you can redistribute it and/or
  641. + modify it under the terms of the GNU General Public License as
  642. + published by the Free Software Foundation; either version 2, or (at
  643. + your option) any later version.
  644. +
  645. + This program is distributed in the hope that it will be useful, but
  646. + WITHOUT ANY WARRANTY; without even the implied warranty of
  647. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  648. + General Public License for more details.
  649. +*/
  650. +
  651. +#ifndef CONFFILE_LIST_H
  652. +#define CONFFILE_LIST_H
  653. +
  654. +#include "conffile.h"
  655. +#include "nv_pair_list.h"
  656. +
  657. +typedef struct nv_pair_list_elt conffile_list_elt_t;
  658. +typedef struct nv_pair_list conffile_list_t;
  659. +
  660. +int conffile_list_init(conffile_list_t *list);
  661. +void conffile_list_deinit(conffile_list_t *list);
  662. +
  663. +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
  664. + const char *root_dir);
  665. +int conffile_list_push(conffile_list_t *list, conffile_t *data);
  666. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
  667. +
  668. +#endif
  669. +
  670. diff -Nur busybox-1.13.4.orig/archival/libipkg/file_util.c busybox-1.13.4/archival/libipkg/file_util.c
  671. --- busybox-1.13.4.orig/archival/libipkg/file_util.c 1970-01-01 01:00:00.000000000 +0100
  672. +++ busybox-1.13.4/archival/libipkg/file_util.c 2009-05-31 15:40:37.005990736 +0200
  673. @@ -0,0 +1,132 @@
  674. +/* file_util.c - convenience routines for common stat operations
  675. +
  676. + Carl D. Worth
  677. +
  678. + Copyright (C) 2001 University of Southern California
  679. +
  680. + This program is free software; you can redistribute it and/or
  681. + modify it under the terms of the GNU General Public License as
  682. + published by the Free Software Foundation; either version 2, or (at
  683. + your option) any later version.
  684. +
  685. + This program is distributed in the hope that it will be useful, but
  686. + WITHOUT ANY WARRANTY; without even the implied warranty of
  687. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  688. + General Public License for more details.
  689. +*/
  690. +
  691. +#include "ipkg.h"
  692. +#include <sys/types.h>
  693. +#include <sys/stat.h>
  694. +
  695. +#include "sprintf_alloc.h"
  696. +#include "file_util.h"
  697. +#include "libbb.h"
  698. +#undef strlen
  699. +
  700. +int file_exists(const char *file_name)
  701. +{
  702. + int err;
  703. + struct stat stat_buf;
  704. +
  705. + err = stat(file_name, &stat_buf);
  706. + if (err == 0) {
  707. + return 1;
  708. + } else {
  709. + return 0;
  710. + }
  711. +}
  712. +
  713. +int file_is_dir(const char *file_name)
  714. +{
  715. + int err;
  716. + struct stat stat_buf;
  717. +
  718. + err = stat(file_name, &stat_buf);
  719. + if (err) {
  720. + return 0;
  721. + }
  722. +
  723. + return S_ISDIR(stat_buf.st_mode);
  724. +}
  725. +
  726. +/* read a single line from a file, stopping at a newline or EOF.
  727. + If a newline is read, it will appear in the resulting string.
  728. + Return value is a malloc'ed char * which should be freed at
  729. + some point by the caller.
  730. +
  731. + Return value is NULL if the file is at EOF when called.
  732. +*/
  733. +#define FILE_READ_LINE_BUF_SIZE 1024
  734. +char *file_read_line_alloc(FILE *file)
  735. +{
  736. + char buf[FILE_READ_LINE_BUF_SIZE];
  737. + int buf_len;
  738. + char *line = NULL;
  739. + int line_size = 0;
  740. +
  741. + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
  742. + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
  743. + buf_len = strlen(buf);
  744. + if (line) {
  745. + line_size += buf_len;
  746. + line = realloc(line, line_size);
  747. + if (line == NULL) {
  748. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  749. + break;
  750. + }
  751. + strcat(line, buf);
  752. + } else {
  753. + line_size = buf_len + 1;
  754. + line = strdup(buf);
  755. + }
  756. + if (buf[buf_len - 1] == '\n') {
  757. + break;
  758. + }
  759. + }
  760. +
  761. + return line;
  762. +}
  763. +
  764. +int file_move(const char *src, const char *dest)
  765. +{
  766. + int err;
  767. +
  768. + err = rename(src, dest);
  769. +
  770. + if (err && errno == EXDEV) {
  771. + err = file_copy(src, dest);
  772. + unlink(src);
  773. + } else if (err) {
  774. + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
  775. + __FUNCTION__, src, dest, strerror(errno));
  776. + }
  777. +
  778. + return err;
  779. +}
  780. +
  781. +/* I put these here to keep libbb dependencies from creeping all over
  782. + the ipkg code */
  783. +int file_copy(const char *src, const char *dest)
  784. +{
  785. + int err;
  786. +
  787. + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
  788. + if (err) {
  789. + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
  790. + __FUNCTION__, src, dest);
  791. + }
  792. +
  793. + return err;
  794. +}
  795. +
  796. +int file_mkdir_hier(char *path, long mode)
  797. +{
  798. + return bb_make_directory(path, mode, FILEUTILS_RECUR);
  799. +}
  800. +
  801. +uint8_t *file_md5sum_alloc(const char *file_name)
  802. +{
  803. + return hash_file(file_name, HASH_MD5);
  804. +}
  805. +
  806. diff -Nur busybox-1.13.4.orig/archival/libipkg/file_util.h busybox-1.13.4/archival/libipkg/file_util.h
  807. --- busybox-1.13.4.orig/archival/libipkg/file_util.h 1970-01-01 01:00:00.000000000 +0100
  808. +++ busybox-1.13.4/archival/libipkg/file_util.h 2009-05-31 15:40:37.005990736 +0200
  809. @@ -0,0 +1,29 @@
  810. +/* file_util.h - convenience routines for common file operations
  811. +
  812. + Carl D. Worth
  813. +
  814. + Copyright (C) 2001 University of Southern California
  815. +
  816. + This program is free software; you can redistribute it and/or
  817. + modify it under the terms of the GNU General Public License as
  818. + published by the Free Software Foundation; either version 2, or (at
  819. + your option) any later version.
  820. +
  821. + This program is distributed in the hope that it will be useful, but
  822. + WITHOUT ANY WARRANTY; without even the implied warranty of
  823. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  824. + General Public License for more details.
  825. +*/
  826. +
  827. +#ifndef FILE_UTIL_H
  828. +#define FILE_UTIL_H
  829. +
  830. +int file_exists(const char *file_name);
  831. +int file_is_dir(const char *file_name);
  832. +char *file_read_line_alloc(FILE *file);
  833. +int file_move(const char *src, const char *dest);
  834. +int file_copy(const char *src, const char *dest);
  835. +int file_mkdir_hier(char *path, long mode);
  836. +uint8_t *file_md5sum_alloc(const char *file_name);
  837. +
  838. +#endif
  839. diff -Nur busybox-1.13.4.orig/archival/libipkg/hash_table.c busybox-1.13.4/archival/libipkg/hash_table.c
  840. --- busybox-1.13.4.orig/archival/libipkg/hash_table.c 1970-01-01 01:00:00.000000000 +0100
  841. +++ busybox-1.13.4/archival/libipkg/hash_table.c 2009-05-31 15:40:37.005990736 +0200
  842. @@ -0,0 +1,155 @@
  843. +/* hash.c - hash tables for ipkg
  844. +
  845. + Steven M. Ayer, Jamey Hicks
  846. +
  847. + Copyright (C) 2002 Compaq Computer Corporation
  848. +
  849. + This program is free software; you can redistribute it and/or
  850. + modify it under the terms of the GNU General Public License as
  851. + published by the Free Software Foundation; either version 2, or (at
  852. + your option) any later version.
  853. +
  854. + This program is distributed in the hope that it will be useful, but
  855. + WITHOUT ANY WARRANTY; without even the implied warranty of
  856. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  857. + General Public License for more details.
  858. +*/
  859. +
  860. +#include <errno.h>
  861. +#include <stdio.h>
  862. +#include <stdlib.h>
  863. +#include <string.h>
  864. +#include "hash_table.h"
  865. +#include "ipkg_message.h"
  866. +
  867. +
  868. +static int hash_index(hash_table_t *hash, const char *pkg_name);
  869. +static int rotating(const char *key, int len, int prime);
  870. +
  871. +static int hash_index(hash_table_t *hash, const char *pkg_name)
  872. +{
  873. + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
  874. +}
  875. +
  876. +static int rotating(const char *key, int len, int prime)
  877. +{
  878. + unsigned int hash, i;
  879. + for (hash=len, i=0; i<len; ++i)
  880. + hash = (hash<<4)^(hash>>28)^key[i];
  881. + return (hash % prime);
  882. +}
  883. +
  884. +
  885. +/*
  886. + * this is an open table keyed by strings
  887. + */
  888. +int hash_table_init(const char *name, hash_table_t *hash, int len)
  889. +{
  890. + static int primes_table[] = {
  891. + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
  892. + 19471, 23143, 33961, 46499, 49727, 99529, 0
  893. + };
  894. + int *picker;
  895. +
  896. + if (hash->entries != NULL) {
  897. + /* we have been here already */
  898. + return 0;
  899. + }
  900. +
  901. + hash->name = name;
  902. + hash->entries = NULL;
  903. + hash->n_entries = 0;
  904. + hash->hash_entry_key = NULL;
  905. +
  906. + picker = primes_table;
  907. + while(*picker && (*picker++ < len));
  908. + if(!*picker)
  909. + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
  910. + --picker;
  911. +
  912. + hash->n_entries = *picker;
  913. + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
  914. + if (hash->entries == NULL) {
  915. + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
  916. + return ENOMEM;
  917. + }
  918. + return 0;
  919. +}
  920. +
  921. +void hash_table_deinit(hash_table_t *hash)
  922. +{
  923. + free(hash->entries);
  924. + hash->entries = NULL;
  925. + hash->n_entries = 0;
  926. +}
  927. +
  928. +void *hash_table_get(hash_table_t *hash, const char *key)
  929. +{
  930. + int ndx= hash_index(hash, key);
  931. + hash_entry_t *hash_entry = hash->entries + ndx;
  932. + while (hash_entry)
  933. + {
  934. + if (hash_entry->key)
  935. + {
  936. + if (strcmp(key, hash_entry->key) == 0) {
  937. + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
  938. + return hash_entry->data;
  939. + }
  940. + }
  941. + hash_entry = hash_entry->next;
  942. + }
  943. + return NULL;
  944. +}
  945. +
  946. +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
  947. +{
  948. + int ndx= hash_index(hash, key);
  949. + hash_entry_t *hash_entry = hash->entries + ndx;
  950. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
  951. + if (hash_entry->key) {
  952. + if (strcmp(hash_entry->key, key) == 0) {
  953. + /* alread in table, update the value */
  954. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
  955. + hash_entry->data = value;
  956. + return 0;
  957. + } else {
  958. + /*
  959. + * if this is a collision, we have to go to the end of the ll,
  960. + * then add a new entry
  961. + * before we can hook up the value
  962. + */
  963. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
  964. + while (hash_entry->next)
  965. + hash_entry = hash_entry->next;
  966. + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
  967. + if (!hash_entry->next) {
  968. + return -ENOMEM;
  969. + }
  970. + hash_entry = hash_entry->next;
  971. + hash_entry->next = NULL;
  972. + }
  973. + }
  974. + hash->n_elements++;
  975. + hash_entry->key = strdup(key);
  976. + hash_entry->data = value;
  977. +
  978. + return 0;
  979. +}
  980. +
  981. +
  982. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
  983. +{
  984. + int i;
  985. + if (!hash || !f)
  986. + return;
  987. +
  988. + for (i = 0; i < hash->n_entries; i++) {
  989. + hash_entry_t *hash_entry = (hash->entries + i);
  990. + do {
  991. + if(hash_entry->key) {
  992. + f(hash_entry->key, hash_entry->data, data);
  993. + }
  994. + } while((hash_entry = hash_entry->next));
  995. + }
  996. +}
  997. +
  998. diff -Nur busybox-1.13.4.orig/archival/libipkg/hash_table.h busybox-1.13.4/archival/libipkg/hash_table.h
  999. --- busybox-1.13.4.orig/archival/libipkg/hash_table.h 1970-01-01 01:00:00.000000000 +0100
  1000. +++ busybox-1.13.4/archival/libipkg/hash_table.h 2009-05-31 15:40:37.005990736 +0200
  1001. @@ -0,0 +1,44 @@
  1002. +/* hash.h - hash tables for ipkg
  1003. +
  1004. + Steven M. Ayer, Jamey Hicks
  1005. +
  1006. + Copyright (C) 2002 Compaq Computer Corporation
  1007. +
  1008. + This program is free software; you can redistribute it and/or
  1009. + modify it under the terms of the GNU General Public License as
  1010. + published by the Free Software Foundation; either version 2, or (at
  1011. + your option) any later version.
  1012. +
  1013. + This program is distributed in the hope that it will be useful, but
  1014. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1015. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1016. + General Public License for more details.
  1017. +*/
  1018. +
  1019. +#ifndef _HASH_TABLE_H_
  1020. +#define _HASH_TABLE_H_
  1021. +
  1022. +typedef struct hash_entry hash_entry_t;
  1023. +typedef struct hash_table hash_table_t;
  1024. +
  1025. +struct hash_entry {
  1026. + const char * key;
  1027. + void * data;
  1028. + struct hash_entry * next;
  1029. +};
  1030. +
  1031. +struct hash_table {
  1032. + const char *name;
  1033. + hash_entry_t * entries;
  1034. + int n_entries; /* number of buckets */
  1035. + int n_elements;
  1036. + const char * (*hash_entry_key)(void * data);
  1037. +};
  1038. +
  1039. +int hash_table_init(const char *name, hash_table_t *hash, int len);
  1040. +void hash_table_deinit(hash_table_t *hash);
  1041. +void *hash_table_get(hash_table_t *hash, const char *key);
  1042. +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
  1043. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
  1044. +
  1045. +#endif /* _HASH_TABLE_H_ */
  1046. diff -Nur busybox-1.13.4.orig/archival/libipkg/ipkg.h busybox-1.13.4/archival/libipkg/ipkg.h
  1047. --- busybox-1.13.4.orig/archival/libipkg/ipkg.h 1970-01-01 01:00:00.000000000 +0100
  1048. +++ busybox-1.13.4/archival/libipkg/ipkg.h 2009-05-31 15:40:37.037992297 +0200
  1049. @@ -0,0 +1,66 @@
  1050. +/* ipkg.h - the itsy package management system
  1051. +
  1052. + Carl D. Worth
  1053. +
  1054. + Copyright (C) 2001 University of Southern California
  1055. +
  1056. + This program is free software; you can redistribute it and/or
  1057. + modify it under the terms of the GNU General Public License as
  1058. + published by the Free Software Foundation; either version 2, or (at
  1059. + your option) any later version.
  1060. +
  1061. + This program is distributed in the hope that it will be useful, but
  1062. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1063. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1064. + General Public License for more details.
  1065. +*/
  1066. +
  1067. +#ifndef IPKG_H
  1068. +#define IPKG_H
  1069. +
  1070. +#include "libbb.h"
  1071. +
  1072. +#include "ipkg_includes.h"
  1073. +#include "ipkg_conf.h"
  1074. +#include "ipkg_message.h"
  1075. +
  1076. +#define IPKG_PKG_EXTENSION ".ipk"
  1077. +#define DPKG_PKG_EXTENSION ".deb"
  1078. +
  1079. +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
  1080. +#define IPKG_PKG_VERSION_SEP_CHAR '_'
  1081. +
  1082. +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
  1083. +#define IPKG_LISTS_DIR_SUFFIX "lists"
  1084. +#define IPKG_INFO_DIR_SUFFIX "info"
  1085. +#define IPKG_STATUS_FILE_SUFFIX "status"
  1086. +
  1087. +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
  1088. +
  1089. +#define IPKG_LIST_DESCRIPTION_LENGTH 128
  1090. +
  1091. +#define IPKG_VERSION "1.00"
  1092. +
  1093. +
  1094. +enum ipkg_error {
  1095. + IPKG_SUCCESS = 0,
  1096. + IPKG_PKG_DEPS_UNSATISFIED,
  1097. + IPKG_PKG_IS_ESSENTIAL,
  1098. + IPKG_PKG_HAS_DEPENDENTS,
  1099. + IPKG_PKG_HAS_NO_CANDIDATE
  1100. +};
  1101. +typedef enum ipkg_error ipkg_error_t;
  1102. +
  1103. +extern int ipkg_state_changed;
  1104. +
  1105. +
  1106. +struct errlist {
  1107. + char * errmsg;
  1108. + struct errlist * next;
  1109. +} ;
  1110. +
  1111. +extern struct errlist* error_list;
  1112. +
  1113. +extern ipkg_conf_t *global_conf;
  1114. +
  1115. +#endif
  1116. diff -Nur busybox-1.13.4.orig/archival/libipkg/ipkg_cmd.c busybox-1.13.4/archival/libipkg/ipkg_cmd.c
  1117. --- busybox-1.13.4.orig/archival/libipkg/ipkg_cmd.c 1970-01-01 01:00:00.000000000 +0100
  1118. +++ busybox-1.13.4/archival/libipkg/ipkg_cmd.c 2009-05-31 15:40:37.013991196 +0200
  1119. @@ -0,0 +1,1433 @@
  1120. +/* ipkg_cmd.c - the itsy package management system
  1121. +
  1122. + Carl D. Worth
  1123. +
  1124. + Copyright (C) 2001 University of Southern California
  1125. +
  1126. + This program is free software; you can redistribute it and/or
  1127. + modify it under the terms of the GNU General Public License as
  1128. + published by the Free Software Foundation; either version 2, or (at
  1129. + your option) any later version.
  1130. +
  1131. + This program is distributed in the hope that it will be useful, but
  1132. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1133. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1134. + General Public License for more details.
  1135. +*/
  1136. +
  1137. +#include <string.h>
  1138. +
  1139. +#include "ipkg.h"
  1140. +#include <libgen.h>
  1141. +#include <glob.h>
  1142. +#include <errno.h>
  1143. +#include <stdlib.h>
  1144. +#include <unistd.h>
  1145. +#include <signal.h>
  1146. +#include <stdio.h>
  1147. +#include <dirent.h>
  1148. +
  1149. +#include "ipkg_conf.h"
  1150. +#include "ipkg_cmd.h"
  1151. +#include "ipkg_message.h"
  1152. +#include "pkg.h"
  1153. +#include "pkg_dest.h"
  1154. +#include "pkg_parse.h"
  1155. +#include "sprintf_alloc.h"
  1156. +#include "pkg.h"
  1157. +#include "file_util.h"
  1158. +#include "str_util.h"
  1159. +#include "unarchive.h"
  1160. +
  1161. +#include <fnmatch.h>
  1162. +
  1163. +
  1164. +#include "ipkg_download.h"
  1165. +#include "ipkg_install.h"
  1166. +#include "ipkg_upgrade.h"
  1167. +#include "ipkg_remove.h"
  1168. +#include "ipkg_configure.h"
  1169. +#include "ipkg_message.h"
  1170. +
  1171. +#ifdef IPKG_LIB
  1172. +#include "libipkg.h"
  1173. +static void *p_userdata = NULL;
  1174. +#endif
  1175. +
  1176. +static int ipkg_update_cmd(ipkg_conf_t *conf);
  1177. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1178. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1179. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1180. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1181. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf);
  1182. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1183. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1184. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1185. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1186. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1187. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1188. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1189. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1190. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1191. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1192. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1193. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1194. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1195. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1196. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1197. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1198. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1199. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf);
  1200. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1201. +
  1202. +/* XXX: CLEANUP: The usage strings should be incorporated into this
  1203. + array for easier maintenance */
  1204. +static ipkg_cmd_t cmds[] = {
  1205. + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
  1206. + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
  1207. + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
  1208. + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
  1209. + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
  1210. + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
  1211. + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
  1212. + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
  1213. + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
  1214. + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
  1215. + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
  1216. + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
  1217. + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
  1218. + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
  1219. + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
  1220. + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1221. + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1222. + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1223. + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1224. + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1225. + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1226. + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
  1227. + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
  1228. + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
  1229. + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
  1230. + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
  1231. + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
  1232. + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
  1233. + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
  1234. +};
  1235. +
  1236. +int ipkg_state_changed;
  1237. +static void write_status_files_if_changed(ipkg_conf_t *conf)
  1238. +{
  1239. + if (ipkg_state_changed && !conf->noaction) {
  1240. + ipkg_message(conf, IPKG_INFO,
  1241. + " writing status file\n");
  1242. + ipkg_conf_write_status_files(conf);
  1243. + pkg_write_changed_filelists(conf);
  1244. + } else {
  1245. + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
  1246. + }
  1247. +}
  1248. +
  1249. +
  1250. +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
  1251. +
  1252. +ipkg_cmd_t *ipkg_cmd_find(const char *name)
  1253. +{
  1254. + int i;
  1255. + ipkg_cmd_t *cmd;
  1256. +
  1257. + for (i=0; i < num_cmds; i++) {
  1258. + cmd = &cmds[i];
  1259. + if (strcmp(name, cmd->name) == 0) {
  1260. + return cmd;
  1261. + }
  1262. + }
  1263. +
  1264. + return NULL;
  1265. +}
  1266. +
  1267. +#ifdef IPKG_LIB
  1268. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
  1269. +{
  1270. + int result;
  1271. + p_userdata = userdata;
  1272. +
  1273. +
  1274. + result = (cmd->fun)(conf, argc, argv);
  1275. + if ( result == 0 ) {
  1276. + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
  1277. + } else {
  1278. + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
  1279. +
  1280. + }
  1281. + if ( error_list ) {
  1282. + reverse_error_list(&error_list);
  1283. +
  1284. + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
  1285. + /* Here we print the errors collected and free the list */
  1286. + while (error_list != NULL) {
  1287. + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
  1288. + error_list = error_list->next;
  1289. +
  1290. + }
  1291. + free_error_list(&error_list);
  1292. +
  1293. + }
  1294. +
  1295. + p_userdata = NULL;
  1296. + return result;
  1297. +}
  1298. +#else
  1299. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv)
  1300. +{
  1301. + return (cmd->fun)(conf, argc, argv);
  1302. +}
  1303. +#endif
  1304. +
  1305. +static int ipkg_update_cmd(ipkg_conf_t *conf)
  1306. +{
  1307. + int err;
  1308. + int failures;
  1309. + char *lists_dir;
  1310. + pkg_src_list_elt_t *iter;
  1311. + pkg_src_t *src;
  1312. +
  1313. +
  1314. + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
  1315. +
  1316. + if (! file_is_dir(lists_dir)) {
  1317. + if (file_exists(lists_dir)) {
  1318. + ipkg_message(conf, IPKG_ERROR,
  1319. + "%s: ERROR: %s exists, but is not a directory\n",
  1320. + __FUNCTION__, lists_dir);
  1321. + free(lists_dir);
  1322. + return EINVAL;
  1323. + }
  1324. + err = file_mkdir_hier(lists_dir, 0755);
  1325. + if (err) {
  1326. + ipkg_message(conf, IPKG_ERROR,
  1327. + "%s: ERROR: failed to make directory %s: %s\n",
  1328. + __FUNCTION__, lists_dir, strerror(errno));
  1329. + free(lists_dir);
  1330. + return EINVAL;
  1331. + }
  1332. + }
  1333. +
  1334. + failures = 0;
  1335. + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
  1336. + char *url, *list_file_name;
  1337. +
  1338. + src = iter->data;
  1339. +
  1340. + if (src->extra_data) /* debian style? */
  1341. + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
  1342. + src->gzip ? "Packages.gz" : "Packages");
  1343. + else
  1344. + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
  1345. +
  1346. + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
  1347. + if (src->gzip) {
  1348. + char *tmp;
  1349. + char *tmp_file_name;
  1350. + FILE *in, *out;
  1351. +
  1352. + tmp = strdup ("/tmp/ipkg.XXXXXX");
  1353. +
  1354. + if (mkdtemp (tmp) == NULL) {
  1355. + perror ("mkdtemp");
  1356. + failures++;
  1357. + continue;
  1358. + }
  1359. +
  1360. + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
  1361. + err = ipkg_download(conf, url, tmp_file_name);
  1362. + if (err == 0) {
  1363. + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
  1364. + in = fopen (tmp_file_name, "r");
  1365. + out = fopen (list_file_name, "w");
  1366. + if (in && out) {
  1367. + inflate_unzip_result res;
  1368. + inflate_unzip (&res, 0x8000, fileno(in), fileno(out));
  1369. + } else
  1370. + err = 1;
  1371. + if (in)
  1372. + fclose (in);
  1373. + if (out)
  1374. + fclose (out);
  1375. + unlink (tmp_file_name);
  1376. + rmdir (tmp);
  1377. + free (tmp);
  1378. + }
  1379. + } else
  1380. + err = ipkg_download(conf, url, list_file_name);
  1381. + if (err) {
  1382. + failures++;
  1383. + } else {
  1384. + ipkg_message(conf, IPKG_NOTICE,
  1385. + "Updated list of available packages in %s\n",
  1386. + list_file_name);
  1387. + }
  1388. + free(url);
  1389. + free(list_file_name);
  1390. + }
  1391. + free(lists_dir);
  1392. +
  1393. +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
  1394. +#warning here
  1395. + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
  1396. + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
  1397. + * -Jamey 3/1/03
  1398. + */
  1399. + {
  1400. + int i;
  1401. + int changed = 0;
  1402. + pkg_vec_t *available = pkg_vec_alloc();
  1403. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1404. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
  1405. + for (i = 0; i < available->len; i++) {
  1406. + pkg_t *pkg = available->pkgs[i];
  1407. + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
  1408. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
  1409. + pkg->state_want = SW_UNKNOWN;
  1410. + changed = 1;
  1411. + }
  1412. + }
  1413. + pkg_vec_free(available);
  1414. + if (changed) {
  1415. + write_status_files_if_changed(conf);
  1416. + }
  1417. + }
  1418. +#endif
  1419. +
  1420. + return failures;
  1421. +}
  1422. +
  1423. +
  1424. +/* scan the args passed and cache the local filenames of the packages */
  1425. +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
  1426. +{
  1427. + int i;
  1428. + int err;
  1429. +
  1430. + /*
  1431. + * First scan through package names/urls
  1432. + * For any urls, download the packages and install in database.
  1433. + * For any files, install package info in database.
  1434. + */
  1435. + for (i = 0; i < argc; i ++) {
  1436. + char *filename = argv [i];
  1437. + //char *tmp = basename (tmp);
  1438. + //int tmplen = strlen (tmp);
  1439. +
  1440. + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
  1441. + // continue;
  1442. + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
  1443. + // continue;
  1444. +
  1445. + ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename );
  1446. +
  1447. + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
  1448. + if (err)
  1449. + return err;
  1450. + }
  1451. + return 0;
  1452. +}
  1453. +
  1454. +struct ipkg_intercept
  1455. +{
  1456. + char *oldpath;
  1457. + char *statedir;
  1458. +};
  1459. +
  1460. +typedef struct ipkg_intercept *ipkg_intercept_t;
  1461. +ipkg_intercept_t ipkg_prep_intercepts(void);
  1462. +
  1463. +ipkg_intercept_t ipkg_prep_intercepts(void)
  1464. +{
  1465. + ipkg_intercept_t ctx;
  1466. + char *newpath;
  1467. + int gen;
  1468. +
  1469. + ctx = malloc (sizeof (*ctx));
  1470. + ctx->oldpath = strdup (getenv ("PATH"));
  1471. +
  1472. + sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath);
  1473. + setenv ("PATH", newpath, 1);
  1474. + free (newpath);
  1475. +
  1476. + gen = 0;
  1477. + retry:
  1478. + sprintf_alloc (&ctx->statedir, "/tmp/ipkg-intercept-%d-%d", getpid (), gen);
  1479. + if (mkdir (ctx->statedir, 0770) < 0) {
  1480. + if (errno == EEXIST) {
  1481. + free (ctx->statedir);
  1482. + gen++;
  1483. + goto retry;
  1484. + }
  1485. + perror (ctx->statedir);
  1486. + return NULL;
  1487. + }
  1488. + setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1);
  1489. + return ctx;
  1490. +}
  1491. +
  1492. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx);
  1493. +
  1494. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx)
  1495. +{
  1496. + char *cmd;
  1497. + DIR *dir;
  1498. + int err = 0;
  1499. +
  1500. + setenv ("PATH", ctx->oldpath, 1);
  1501. + free (ctx->oldpath);
  1502. +
  1503. + dir = opendir (ctx->statedir);
  1504. + if (dir) {
  1505. + struct dirent *de;
  1506. + while (de = readdir (dir), de != NULL) {
  1507. + char *path;
  1508. +
  1509. + if (de->d_name[0] == '.')
  1510. + continue;
  1511. +
  1512. + sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name);
  1513. + if (access (path, X_OK) == 0) {
  1514. + if (system (path)) {
  1515. + err = errno;
  1516. + perror (de->d_name);
  1517. + }
  1518. + }
  1519. + free (path);
  1520. + }
  1521. + } else
  1522. + perror (ctx->statedir);
  1523. +
  1524. + sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
  1525. + system (cmd);
  1526. + free (cmd);
  1527. +
  1528. + free (ctx->statedir);
  1529. + free (ctx);
  1530. +
  1531. + return err;
  1532. +}
  1533. +
  1534. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
  1535. +{
  1536. + pkg_vec_t *all;
  1537. + int i;
  1538. + pkg_t *pkg;
  1539. + ipkg_intercept_t ic;
  1540. + int r, err = 0;
  1541. +
  1542. + ipkg_message(conf, IPKG_INFO,
  1543. + "Configuring unpacked packages\n");
  1544. + fflush( stdout );
  1545. +
  1546. + all = pkg_vec_alloc();
  1547. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  1548. +
  1549. + ic = ipkg_prep_intercepts();
  1550. +
  1551. + for(i = 0; i < all->len; i++) {
  1552. + pkg = all->pkgs[i];
  1553. +
  1554. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1555. + continue;
  1556. +
  1557. + if (pkg->state_status == SS_UNPACKED) {
  1558. + ipkg_message(conf, IPKG_NOTICE,
  1559. + "Configuring %s\n", pkg->name);
  1560. + fflush( stdout );
  1561. + r = ipkg_configure(conf, pkg);
  1562. + if (r == 0) {
  1563. + pkg->state_status = SS_INSTALLED;
  1564. + pkg->parent->state_status = SS_INSTALLED;
  1565. + pkg->state_flag &= ~SF_PREFER;
  1566. + } else {
  1567. + if (!err)
  1568. + err = r;
  1569. + }
  1570. + }
  1571. + }
  1572. +
  1573. + r = ipkg_finalize_intercepts (ic);
  1574. + if (r && !err)
  1575. + err = r;
  1576. +
  1577. + pkg_vec_free(all);
  1578. + return err;
  1579. +}
  1580. +
  1581. +static void sigint_handler(int sig)
  1582. +{
  1583. + signal(sig, SIG_DFL);
  1584. + ipkg_message(NULL, IPKG_NOTICE,
  1585. + "ipkg: interrupted. writing out status database\n");
  1586. + write_status_files_if_changed(global_conf);
  1587. + exit(128 + sig);
  1588. +}
  1589. +
  1590. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1591. +{
  1592. + int i;
  1593. + char *arg;
  1594. + int err=0;
  1595. +
  1596. + global_conf = conf;
  1597. + signal(SIGINT, sigint_handler);
  1598. +
  1599. + /*
  1600. + * Now scan through package names and install
  1601. + */
  1602. + for (i=0; i < argc; i++) {
  1603. + arg = argv[i];
  1604. +
  1605. + ipkg_message(conf, IPKG_DEBUG2, "Debug install_cmd: %s \n",arg );
  1606. + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
  1607. + if (err != EINVAL && err != 0)
  1608. + return err;
  1609. + }
  1610. + pkg_info_preinstall_check(conf);
  1611. +
  1612. + for (i=0; i < argc; i++) {
  1613. + arg = argv[i];
  1614. + if (conf->multiple_providers)
  1615. + err = ipkg_install_multi_by_name(conf, arg);
  1616. + else{
  1617. + err = ipkg_install_by_name(conf, arg);
  1618. + }
  1619. + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
  1620. + ipkg_message(conf, IPKG_ERROR,
  1621. + "Cannot find package %s.\n"
  1622. + "Check the spelling or perhaps run 'ipkg update'\n",
  1623. + arg);
  1624. + }
  1625. + }
  1626. +
  1627. + /* recheck to verify that all dependences are satisfied */
  1628. + if (0) ipkg_satisfy_all_dependences(conf);
  1629. +
  1630. + ipkg_configure_packages(conf, NULL);
  1631. +
  1632. + write_status_files_if_changed(conf);
  1633. +
  1634. + return err;
  1635. +}
  1636. +
  1637. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1638. +{
  1639. + int i;
  1640. + pkg_t *pkg;
  1641. + int err;
  1642. +
  1643. + global_conf = conf;
  1644. + signal(SIGINT, sigint_handler);
  1645. +
  1646. + if (argc) {
  1647. + for (i=0; i < argc; i++) {
  1648. + char *arg = argv[i];
  1649. +
  1650. + err = ipkg_prepare_url_for_install(conf, arg, &arg);
  1651. + if (err != EINVAL && err != 0)
  1652. + return err;
  1653. + }
  1654. + pkg_info_preinstall_check(conf);
  1655. +
  1656. + for (i=0; i < argc; i++) {
  1657. + char *arg = argv[i];
  1658. + if (conf->restrict_to_default_dest) {
  1659. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1660. + argv[i],
  1661. + conf->default_dest);
  1662. + if (pkg == NULL) {
  1663. + ipkg_message(conf, IPKG_NOTICE,
  1664. + "Package %s not installed in %s\n",
  1665. + argv[i], conf->default_dest->name);
  1666. + continue;
  1667. + }
  1668. + } else {
  1669. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  1670. + argv[i]);
  1671. + }
  1672. + if (pkg)
  1673. + ipkg_upgrade_pkg(conf, pkg);
  1674. + else {
  1675. + ipkg_install_by_name(conf, arg);
  1676. + }
  1677. + }
  1678. + } else {
  1679. + pkg_vec_t *installed = pkg_vec_alloc();
  1680. +
  1681. + pkg_info_preinstall_check(conf);
  1682. +
  1683. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  1684. + for (i = 0; i < installed->len; i++) {
  1685. + pkg = installed->pkgs[i];
  1686. + ipkg_upgrade_pkg(conf, pkg);
  1687. + }
  1688. + pkg_vec_free(installed);
  1689. + }
  1690. +
  1691. + /* recheck to verify that all dependences are satisfied */
  1692. + if (0) ipkg_satisfy_all_dependences(conf);
  1693. +
  1694. + ipkg_configure_packages(conf, NULL);
  1695. +
  1696. + write_status_files_if_changed(conf);
  1697. +
  1698. + return 0;
  1699. +}
  1700. +
  1701. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1702. +{
  1703. + int i, err;
  1704. + char *arg;
  1705. + pkg_t *pkg;
  1706. +
  1707. + pkg_info_preinstall_check(conf);
  1708. + for (i = 0; i < argc; i++) {
  1709. + arg = argv[i];
  1710. +
  1711. + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
  1712. + if (pkg == NULL) {
  1713. + ipkg_message(conf, IPKG_ERROR,
  1714. + "Cannot find package %s.\n"
  1715. + "Check the spelling or perhaps run 'ipkg update'\n",
  1716. + arg);
  1717. + continue;
  1718. + }
  1719. +
  1720. + err = ipkg_download_pkg(conf, pkg, ".");
  1721. +
  1722. + if (err) {
  1723. + ipkg_message(conf, IPKG_ERROR,
  1724. + "Failed to download %s\n", pkg->name);
  1725. + } else {
  1726. + ipkg_message(conf, IPKG_NOTICE,
  1727. + "Downloaded %s as %s\n",
  1728. + pkg->name, pkg->local_filename);
  1729. + }
  1730. + }
  1731. +
  1732. + return 0;
  1733. +}
  1734. +
  1735. +
  1736. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1737. +{
  1738. + int i ;
  1739. + pkg_vec_t *available;
  1740. + pkg_t *pkg;
  1741. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1742. + char *newline;
  1743. + char *pkg_name = NULL;
  1744. + char *version_str;
  1745. +
  1746. + if (argc > 0) {
  1747. + pkg_name = argv[0];
  1748. + }
  1749. + available = pkg_vec_alloc();
  1750. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1751. + for (i=0; i < available->len; i++) {
  1752. + pkg = available->pkgs[i];
  1753. + /* if we have package name or pattern and pkg does not match, then skip it */
  1754. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1755. + continue;
  1756. + if (pkg->description) {
  1757. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1758. + } else {
  1759. + desc_short[0] = '\0';
  1760. + }
  1761. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1762. + newline = strchr(desc_short, '\n');
  1763. + if (newline) {
  1764. + *newline = '\0';
  1765. + }
  1766. +#ifndef IPKG_LIB
  1767. + printf("%s - %s\n", pkg->name, desc_short);
  1768. +#else
  1769. + if (ipkg_cb_list) {
  1770. + version_str = pkg_version_str_alloc(pkg);
  1771. + ipkg_cb_list(pkg->name,desc_short,
  1772. + version_str,
  1773. + pkg->state_status,
  1774. + p_userdata);
  1775. + free(version_str);
  1776. + }
  1777. +#endif
  1778. + }
  1779. + pkg_vec_free(available);
  1780. +
  1781. + return 0;
  1782. +}
  1783. +
  1784. +
  1785. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1786. +{
  1787. + int i ;
  1788. + pkg_vec_t *available;
  1789. + pkg_t *pkg;
  1790. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1791. + char *newline;
  1792. + char *pkg_name = NULL;
  1793. + char *version_str;
  1794. +
  1795. + if (argc > 0) {
  1796. + pkg_name = argv[0];
  1797. + }
  1798. + available = pkg_vec_alloc();
  1799. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1800. + for (i=0; i < available->len; i++) {
  1801. + pkg = available->pkgs[i];
  1802. + /* if we have package name or pattern and pkg does not match, then skip it */
  1803. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1804. + continue;
  1805. + if (pkg->description) {
  1806. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1807. + } else {
  1808. + desc_short[0] = '\0';
  1809. + }
  1810. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1811. + newline = strchr(desc_short, '\n');
  1812. + if (newline) {
  1813. + *newline = '\0';
  1814. + }
  1815. +#ifndef IPKG_LIB
  1816. + printf("%s - %s\n", pkg->name, desc_short);
  1817. +#else
  1818. + if (ipkg_cb_list) {
  1819. + version_str = pkg_version_str_alloc(pkg);
  1820. + ipkg_cb_list(pkg->name,desc_short,
  1821. + version_str,
  1822. + pkg->state_status,
  1823. + p_userdata);
  1824. + free(version_str);
  1825. + }
  1826. +#endif
  1827. + }
  1828. +
  1829. + return 0;
  1830. +}
  1831. +
  1832. +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
  1833. +{
  1834. + int i;
  1835. + pkg_vec_t *available;
  1836. + pkg_t *pkg;
  1837. + char *pkg_name = NULL;
  1838. + char **pkg_fields = NULL;
  1839. + int n_fields = 0;
  1840. + char *buff ; // = (char *)malloc(1);
  1841. +
  1842. + if (argc > 0) {
  1843. + pkg_name = argv[0];
  1844. + }
  1845. + if (argc > 1) {
  1846. + pkg_fields = &argv[1];
  1847. + n_fields = argc - 1;
  1848. + }
  1849. +
  1850. + available = pkg_vec_alloc();
  1851. + if (installed_only)
  1852. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1853. + else
  1854. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1855. + for (i=0; i < available->len; i++) {
  1856. + pkg = available->pkgs[i];
  1857. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1858. + continue;
  1859. + }
  1860. +#ifndef IPKG_LIB
  1861. + if (n_fields) {
  1862. + for (j = 0; j < n_fields; j++)
  1863. + pkg_print_field(pkg, stdout, pkg_fields[j]);
  1864. + } else {
  1865. + pkg_print_info(pkg, stdout);
  1866. + }
  1867. +#else
  1868. +
  1869. + buff = pkg_formatted_info(pkg);
  1870. + if ( buff ) {
  1871. + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
  1872. + pkg->state_status,
  1873. + buff,
  1874. + p_userdata);
  1875. +/*
  1876. + We should not forget that actually the pointer is allocated.
  1877. + We need to free it :) ( Thanks florian for seeing the error )
  1878. +*/
  1879. + free(buff);
  1880. + }
  1881. +#endif
  1882. + if (conf->verbosity > 1) {
  1883. + conffile_list_elt_t *iter;
  1884. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  1885. + conffile_t *cf = iter->data;
  1886. + int modified = conffile_has_been_modified(conf, cf);
  1887. + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
  1888. + cf->name, cf->value, modified);
  1889. + }
  1890. + }
  1891. + }
  1892. +#ifndef IPKG_LIB
  1893. + if (buff)
  1894. + free(buff);
  1895. +#endif
  1896. + pkg_vec_free(available);
  1897. +
  1898. + return 0;
  1899. +}
  1900. +
  1901. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1902. +{
  1903. + return ipkg_info_status_cmd(conf, argc, argv, 0);
  1904. +}
  1905. +
  1906. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1907. +{
  1908. + return ipkg_info_status_cmd(conf, argc, argv, 1);
  1909. +}
  1910. +
  1911. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1912. +{
  1913. +
  1914. + int err;
  1915. + if (argc > 0) {
  1916. + char *pkg_name = NULL;
  1917. +
  1918. + pkg_name = argv[0];
  1919. +
  1920. + err = ipkg_configure_packages (conf, pkg_name);
  1921. +
  1922. + } else {
  1923. + err = ipkg_configure_packages (conf, NULL);
  1924. + }
  1925. +
  1926. + write_status_files_if_changed(conf);
  1927. +
  1928. + return err;
  1929. +}
  1930. +
  1931. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf)
  1932. +{
  1933. + int i, err;
  1934. + char *globpattern;
  1935. + glob_t globbuf;
  1936. +
  1937. + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
  1938. + err = glob(globpattern, 0, NULL, &globbuf);
  1939. + free(globpattern);
  1940. + if (err) {
  1941. + return 0;
  1942. + }
  1943. +
  1944. + ipkg_message(conf, IPKG_NOTICE,
  1945. + "The following packages in %s will now be installed.\n",
  1946. + conf->pending_dir);
  1947. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1948. + ipkg_message(conf, IPKG_NOTICE,
  1949. + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
  1950. + }
  1951. + ipkg_message(conf, IPKG_NOTICE, "\n");
  1952. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1953. + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
  1954. + if (err == 0) {
  1955. + err = unlink(globbuf.gl_pathv[i]);
  1956. + if (err) {
  1957. + ipkg_message(conf, IPKG_ERROR,
  1958. + "%s: ERROR: failed to unlink %s: %s\n",
  1959. + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
  1960. + return err;
  1961. + }
  1962. + }
  1963. + }
  1964. + globfree(&globbuf);
  1965. +
  1966. + return err;
  1967. +}
  1968. +
  1969. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1970. +{
  1971. + int i,a,done;
  1972. + pkg_t *pkg;
  1973. + pkg_t *pkg_to_remove;
  1974. + pkg_vec_t *available;
  1975. + char *pkg_name = NULL;
  1976. + global_conf = conf;
  1977. + signal(SIGINT, sigint_handler);
  1978. +
  1979. +// ENH: Add the "no pkg removed" just in case.
  1980. +
  1981. + done = 0;
  1982. +
  1983. + available = pkg_vec_alloc();
  1984. + pkg_info_preinstall_check(conf);
  1985. + if ( argc > 0 ) {
  1986. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1987. + for (i=0; i < argc; i++) {
  1988. + pkg_name = malloc(strlen(argv[i])+2);
  1989. + strcpy(pkg_name,argv[i]);
  1990. + for (a=0; a < available->len; a++) {
  1991. + pkg = available->pkgs[a];
  1992. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1993. + continue;
  1994. + }
  1995. + if (conf->restrict_to_default_dest) {
  1996. + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1997. + pkg->name,
  1998. + conf->default_dest);
  1999. + } else {
  2000. + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
  2001. + }
  2002. +
  2003. + if (pkg == NULL) {
  2004. + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
  2005. + continue;
  2006. + }
  2007. + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
  2008. + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
  2009. + continue;
  2010. + }
  2011. + ipkg_remove_pkg(conf, pkg_to_remove,0);
  2012. + done = 1;
  2013. + }
  2014. + free (pkg_name);
  2015. + }
  2016. + pkg_vec_free(available);
  2017. + } else {
  2018. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  2019. + int flagged_pkg_count = 0;
  2020. + int removed;
  2021. +
  2022. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
  2023. +
  2024. + for (i = 0; i < installed_pkgs->len; i++) {
  2025. + pkg = installed_pkgs->pkgs[i];
  2026. + if (pkg->state_flag & SF_USER) {
  2027. + flagged_pkg_count++;
  2028. + } else {
  2029. + if (!pkg_has_installed_dependents(pkg, NULL))
  2030. + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
  2031. + }
  2032. + }
  2033. + if (!flagged_pkg_count) {
  2034. + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
  2035. + "so refusing to uninstall unflagged non-leaf packages\n");
  2036. + return 0;
  2037. + }
  2038. +
  2039. + /* find packages not flagged SF_USER (i.e., installed to
  2040. + * satisfy a dependence) and not having any dependents, and
  2041. + * remove them */
  2042. + do {
  2043. + removed = 0;
  2044. + for (i = 0; i < installed_pkgs->len; i++) {
  2045. + pkg = installed_pkgs->pkgs[i];
  2046. + if (!(pkg->state_flag & SF_USER)
  2047. + && !pkg_has_installed_dependents(pkg, NULL)) {
  2048. + removed++;
  2049. + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
  2050. + ipkg_remove_pkg(conf, pkg,0);
  2051. + done = 1;
  2052. + }
  2053. + }
  2054. + } while (removed);
  2055. + pkg_vec_free(installed_pkgs);
  2056. + }
  2057. +
  2058. + if ( done == 0 )
  2059. + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
  2060. +
  2061. + write_status_files_if_changed(conf);
  2062. + return 0;
  2063. +}
  2064. +
  2065. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2066. +{
  2067. + int i;
  2068. + pkg_t *pkg;
  2069. +
  2070. + global_conf = conf;
  2071. + signal(SIGINT, sigint_handler);
  2072. +
  2073. + pkg_info_preinstall_check(conf);
  2074. +
  2075. + for (i=0; i < argc; i++) {
  2076. + if (conf->restrict_to_default_dest) {
  2077. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  2078. + argv[i],
  2079. + conf->default_dest);
  2080. + } else {
  2081. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  2082. + }
  2083. +
  2084. + if (pkg == NULL) {
  2085. + ipkg_message(conf, IPKG_ERROR,
  2086. + "Package %s is not installed.\n", argv[i]);
  2087. + continue;
  2088. + }
  2089. + ipkg_purge_pkg(conf, pkg);
  2090. + }
  2091. +
  2092. + write_status_files_if_changed(conf);
  2093. + return 0;
  2094. +}
  2095. +
  2096. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2097. +{
  2098. + int i;
  2099. + pkg_t *pkg;
  2100. + char *flags = argv[0];
  2101. +
  2102. + global_conf = conf;
  2103. + signal(SIGINT, sigint_handler);
  2104. +
  2105. + for (i=1; i < argc; i++) {
  2106. + if (conf->restrict_to_default_dest) {
  2107. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  2108. + argv[i],
  2109. + conf->default_dest);
  2110. + } else {
  2111. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  2112. + }
  2113. +
  2114. + if (pkg == NULL) {
  2115. + ipkg_message(conf, IPKG_ERROR,
  2116. + "Package %s is not installed.\n", argv[i]);
  2117. + continue;
  2118. + }
  2119. + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
  2120. + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
  2121. + pkg->state_flag = pkg_state_flag_from_str(flags);
  2122. + }
  2123. +/* pb_ asked this feature 03292004 */
  2124. +/* Actually I will use only this two, but this is an open for various status */
  2125. + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
  2126. + pkg->state_status = pkg_state_status_from_str(flags);
  2127. + }
  2128. + ipkg_state_changed++;
  2129. + ipkg_message(conf, IPKG_NOTICE,
  2130. + "Setting flags for package %s to %s\n",
  2131. + pkg->name, flags);
  2132. + }
  2133. +
  2134. + write_status_files_if_changed(conf);
  2135. + return 0;
  2136. +}
  2137. +
  2138. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2139. +{
  2140. + pkg_t *pkg;
  2141. + str_list_t *installed_files;
  2142. + str_list_elt_t *iter;
  2143. + char *pkg_version;
  2144. + size_t buff_len = 8192;
  2145. + size_t used_len;
  2146. + char *buff ;
  2147. +
  2148. + buff = (char *)malloc(buff_len);
  2149. + if ( buff == NULL ) {
  2150. + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
  2151. + return ENOMEM;
  2152. + }
  2153. +
  2154. + if (argc < 1) {
  2155. + return EINVAL;
  2156. + }
  2157. +
  2158. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  2159. + argv[0]);
  2160. + if (pkg == NULL) {
  2161. + ipkg_message(conf, IPKG_ERROR,
  2162. + "Package %s not installed.\n", argv[0]);
  2163. + return 0;
  2164. + }
  2165. +
  2166. + installed_files = pkg_get_installed_files(pkg);
  2167. + pkg_version = pkg_version_str_alloc(pkg);
  2168. +
  2169. +#ifndef IPKG_LIB
  2170. + printf("Package %s (%s) is installed on %s and has the following files:\n",
  2171. + pkg->name, pkg_version, pkg->dest->name);
  2172. + for (iter = installed_files->head; iter; iter = iter->next) {
  2173. + puts(iter->data);
  2174. + }
  2175. +#else
  2176. + if (buff) {
  2177. + try_again:
  2178. + used_len = snprintf(buff, buff_len, "Package %s (%s) is installed on %s and has the following files:\n",
  2179. + pkg->name, pkg_version, pkg->dest->name) + 1;
  2180. + if (used_len > buff_len) {
  2181. + buff_len *= 2;
  2182. + buff = realloc (buff, buff_len);
  2183. + goto try_again;
  2184. + }
  2185. + for (iter = installed_files->head; iter; iter = iter->next) {
  2186. + used_len += strlen (iter->data) + 1;
  2187. + while (buff_len <= used_len) {
  2188. + buff_len *= 2;
  2189. + buff = realloc (buff, buff_len);
  2190. + }
  2191. + strncat(buff, iter->data, buff_len);
  2192. + strncat(buff, "\n", buff_len);
  2193. + }
  2194. + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
  2195. + buff,
  2196. + pkg_version_str_alloc(pkg),
  2197. + pkg->state_status,
  2198. + p_userdata);
  2199. + free(buff);
  2200. + }
  2201. +#endif
  2202. +
  2203. + free(pkg_version);
  2204. + pkg_free_installed_files(pkg);
  2205. +
  2206. + return 0;
  2207. +}
  2208. +
  2209. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2210. +{
  2211. +
  2212. + if (argc > 0) {
  2213. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2214. + const char *rel_str = "depends on";
  2215. + int i;
  2216. +
  2217. + pkg_info_preinstall_check(conf);
  2218. +
  2219. + if (conf->query_all)
  2220. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2221. + else
  2222. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2223. + for (i = 0; i < argc; i++) {
  2224. + const char *target = argv[i];
  2225. + int j;
  2226. +
  2227. + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
  2228. +
  2229. + for (j = 0; j < available_pkgs->len; j++) {
  2230. + pkg_t *pkg = available_pkgs->pkgs[j];
  2231. + if (fnmatch(target, pkg->name, 0) == 0) {
  2232. + int k;
  2233. + int count = pkg->depends_count + pkg->pre_depends_count;
  2234. + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
  2235. + target, pkg->architecture, rel_str);
  2236. + for (k = 0; k < count; k++) {
  2237. + compound_depend_t *cdepend = &pkg->depends[k];
  2238. + int l;
  2239. + for (l = 0; l < cdepend->possibility_count; l++) {
  2240. + depend_t *possibility = cdepend->possibilities[l];
  2241. + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
  2242. + if (conf->verbosity > 0) {
  2243. + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
  2244. + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
  2245. + if (possibility->version) {
  2246. + const char *typestr = NULL;
  2247. + switch (possibility->constraint) {
  2248. + case NONE: typestr = "none"; break;
  2249. + case EARLIER: typestr = "<"; break;
  2250. + case EARLIER_EQUAL: typestr = "<="; break;
  2251. + case EQUAL: typestr = "="; break;
  2252. + case LATER_EQUAL: typestr = ">="; break;
  2253. + case LATER: typestr = ">"; break;
  2254. + }
  2255. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2256. + }
  2257. + // free(ver);
  2258. + }
  2259. + ipkg_message(conf, IPKG_ERROR, "\n");
  2260. + }
  2261. + }
  2262. + }
  2263. + }
  2264. + }
  2265. + pkg_vec_free(available_pkgs);
  2266. + }
  2267. + return 0;
  2268. +}
  2269. +
  2270. +enum what_field_type {
  2271. + WHATDEPENDS,
  2272. + WHATCONFLICTS,
  2273. + WHATPROVIDES,
  2274. + WHATREPLACES,
  2275. + WHATRECOMMENDS,
  2276. + WHATSUGGESTS
  2277. +};
  2278. +
  2279. +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
  2280. +{
  2281. +
  2282. + if (argc > 0) {
  2283. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2284. + const char *rel_str = NULL;
  2285. + int i;
  2286. + int changed;
  2287. +
  2288. + switch (what_field_type) {
  2289. + case WHATDEPENDS: rel_str = "depends on"; break;
  2290. + case WHATCONFLICTS: rel_str = "conflicts with"; break;
  2291. + case WHATSUGGESTS: rel_str = "suggests"; break;
  2292. + case WHATRECOMMENDS: rel_str = "recommends"; break;
  2293. + case WHATPROVIDES: rel_str = "provides"; break;
  2294. + case WHATREPLACES: rel_str = "replaces"; break;
  2295. + }
  2296. +
  2297. + if (conf->query_all)
  2298. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2299. + else
  2300. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2301. +
  2302. + /* mark the root set */
  2303. + pkg_vec_clear_marks(available_pkgs);
  2304. + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
  2305. + for (i = 0; i < argc; i++) {
  2306. + const char *dependee_pattern = argv[i];
  2307. + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
  2308. + }
  2309. + for (i = 0; i < available_pkgs->len; i++) {
  2310. + pkg_t *pkg = available_pkgs->pkgs[i];
  2311. + if (pkg->state_flag & SF_MARKED) {
  2312. + /* mark the parent (abstract) package */
  2313. + pkg_mark_provides(pkg);
  2314. + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
  2315. + }
  2316. + }
  2317. +
  2318. + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
  2319. + do {
  2320. + int j;
  2321. + changed = 0;
  2322. +
  2323. + for (j = 0; j < available_pkgs->len; j++) {
  2324. + pkg_t *pkg = available_pkgs->pkgs[j];
  2325. + int k;
  2326. + int count = ((what_field_type == WHATCONFLICTS)
  2327. + ? pkg->conflicts_count
  2328. + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
  2329. + /* skip this package if it is already marked */
  2330. + if (pkg->parent->state_flag & SF_MARKED) {
  2331. + continue;
  2332. + }
  2333. + for (k = 0; k < count; k++) {
  2334. + compound_depend_t *cdepend =
  2335. + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
  2336. + int l;
  2337. + for (l = 0; l < cdepend->possibility_count; l++) {
  2338. + depend_t *possibility = cdepend->possibilities[l];
  2339. + if (possibility->pkg->state_flag & SF_MARKED) {
  2340. + /* mark the depending package so we won't visit it again */
  2341. + pkg->state_flag |= SF_MARKED;
  2342. + pkg_mark_provides(pkg);
  2343. + changed++;
  2344. +
  2345. + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
  2346. + if (conf->verbosity > 0) {
  2347. + char *ver = pkg_version_str_alloc(pkg);
  2348. + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
  2349. + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
  2350. + if (possibility->version) {
  2351. + const char *typestr = NULL;
  2352. + switch (possibility->constraint) {
  2353. + case NONE: typestr = "none"; break;
  2354. + case EARLIER: typestr = "<"; break;
  2355. + case EARLIER_EQUAL: typestr = "<="; break;
  2356. + case EQUAL: typestr = "="; break;
  2357. + case LATER_EQUAL: typestr = ">="; break;
  2358. + case LATER: typestr = ">"; break;
  2359. + }
  2360. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2361. + }
  2362. + free(ver);
  2363. + if (!pkg_dependence_satisfiable(possibility))
  2364. + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
  2365. + }
  2366. + ipkg_message(conf, IPKG_NOTICE, "\n");
  2367. + goto next_package;
  2368. + }
  2369. + }
  2370. + }
  2371. + next_package:
  2372. + ;
  2373. + }
  2374. + } while (changed && recursive);
  2375. + pkg_vec_free(available_pkgs);
  2376. + }
  2377. +
  2378. + return 0;
  2379. +}
  2380. +
  2381. +int pkg_mark_provides(pkg_t *pkg)
  2382. +{
  2383. + int provides_count = pkg->provides_count;
  2384. + abstract_pkg_t **provides = pkg->provides;
  2385. + int i;
  2386. + pkg->parent->state_flag |= SF_MARKED;
  2387. + for (i = 0; i < provides_count; i++) {
  2388. + provides[i]->state_flag |= SF_MARKED;
  2389. + }
  2390. + return 0;
  2391. +}
  2392. +
  2393. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2394. +{
  2395. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
  2396. +}
  2397. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2398. +{
  2399. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
  2400. +}
  2401. +
  2402. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2403. +{
  2404. + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
  2405. +}
  2406. +
  2407. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2408. +{
  2409. + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
  2410. +}
  2411. +
  2412. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2413. +{
  2414. + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
  2415. +}
  2416. +
  2417. +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
  2418. +{
  2419. +
  2420. + if (argc > 0) {
  2421. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2422. + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
  2423. + int i;
  2424. +
  2425. + pkg_info_preinstall_check(conf);
  2426. +
  2427. + if (conf->query_all)
  2428. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2429. + else
  2430. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2431. + for (i = 0; i < argc; i++) {
  2432. + const char *target = argv[i];
  2433. + int j;
  2434. +
  2435. + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
  2436. + rel_str, target);
  2437. + for (j = 0; j < available_pkgs->len; j++) {
  2438. + pkg_t *pkg = available_pkgs->pkgs[j];
  2439. + int k;
  2440. + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
  2441. + for (k = 0; k < count; k++) {
  2442. + abstract_pkg_t *apkg =
  2443. + ((what_field_type == WHATPROVIDES)
  2444. + ? pkg->provides[k]
  2445. + : pkg->replaces[k]);
  2446. + if (fnmatch(target, apkg->name, 0) == 0) {
  2447. + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
  2448. + if (strcmp(target, apkg->name) != 0)
  2449. + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
  2450. + ipkg_message(conf, IPKG_ERROR, "\n");
  2451. + }
  2452. + }
  2453. + }
  2454. + }
  2455. + pkg_vec_free(available_pkgs);
  2456. + }
  2457. + return 0;
  2458. +}
  2459. +
  2460. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2461. +{
  2462. + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
  2463. +}
  2464. +
  2465. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2466. +{
  2467. + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
  2468. +}
  2469. +
  2470. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2471. +{
  2472. + int i;
  2473. +
  2474. + pkg_vec_t *installed;
  2475. + pkg_t *pkg;
  2476. + str_list_t *installed_files;
  2477. + str_list_elt_t *iter;
  2478. + char *installed_file;
  2479. +
  2480. + if (argc < 1) {
  2481. + return EINVAL;
  2482. + }
  2483. +
  2484. + installed = pkg_vec_alloc();
  2485. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  2486. +
  2487. + for (i=0; i < installed->len; i++) {
  2488. + pkg = installed->pkgs[i];
  2489. +
  2490. + installed_files = pkg_get_installed_files(pkg);
  2491. +
  2492. + for (iter = installed_files->head; iter; iter = iter->next) {
  2493. + installed_file = iter->data;
  2494. + if (fnmatch(argv[0], installed_file, 0)==0) {
  2495. +#ifndef IPKG_LIB
  2496. + printf("%s: %s\n", pkg->name, installed_file);
  2497. +#else
  2498. + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
  2499. + installed_file,
  2500. + pkg_version_str_alloc(pkg),
  2501. + pkg->state_status, p_userdata);
  2502. +#endif
  2503. + }
  2504. + }
  2505. +
  2506. + pkg_free_installed_files(pkg);
  2507. + }
  2508. +
  2509. + /* XXX: CLEANUP: It's not obvious from the name of
  2510. + pkg_hash_fetch_all_installed that we need to call
  2511. + pkg_vec_free to avoid a memory leak. */
  2512. + pkg_vec_free(installed);
  2513. +
  2514. + return 0;
  2515. +}
  2516. +
  2517. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2518. +{
  2519. + if (argc == 3) {
  2520. + /* this is a bit gross */
  2521. + struct pkg p1, p2;
  2522. + parseVersion(&p1, argv[0]);
  2523. + parseVersion(&p2, argv[2]);
  2524. + return pkg_version_satisfied(&p1, &p2, argv[1]);
  2525. + } else {
  2526. + ipkg_message(conf, IPKG_ERROR,
  2527. + "ipkg compare_versions <v1> <op> <v2>\n"
  2528. + "<op> is one of <= >= << >> =\n");
  2529. + return -1;
  2530. + }
  2531. +}
  2532. +
  2533. +#ifndef HOST_CPU_STR
  2534. +#define HOST_CPU_STR__(X) #X
  2535. +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
  2536. +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
  2537. +#endif
  2538. +
  2539. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf)
  2540. +{
  2541. + nv_pair_list_elt_t *l;
  2542. +
  2543. + l = conf->arch_list.head;
  2544. + while (l) {
  2545. + nv_pair_t *nv = l->data;
  2546. + printf("arch %s %s\n", nv->name, nv->value);
  2547. + l = l->next;
  2548. + }
  2549. + return 0;
  2550. +}
  2551. +
  2552. +
  2553. diff -Nur busybox-1.13.4.orig/archival/libipkg/ipkg_cmd.h busybox-1.13.4/archival/libipkg/ipkg_cmd.h
  2554. --- busybox-1.13.4.orig/archival/libipkg/ipkg_cmd.h 1970-01-01 01:00:00.000000000 +0100
  2555. +++ busybox-1.13.4/archival/libipkg/ipkg_cmd.h 2009-05-31 15:40:37.021990539 +0200
  2556. @@ -0,0 +1,46 @@
  2557. +/* ipkg_cmd.h - the itsy package management system
  2558. +
  2559. + Carl D. Worth
  2560. +
  2561. + Copyright (C) 2001 University of Southern California
  2562. +
  2563. + This program is free software; you can redistribute it and/or
  2564. + modify it under the terms of the GNU General Public License as
  2565. + published by the Free Software Foundation; either version 2, or (at
  2566. + your option) any later version.
  2567. +
  2568. + This program is distributed in the hope that it will be useful, but
  2569. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2570. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2571. + General Public License for more details.
  2572. +*/
  2573. +
  2574. +#ifndef IPKG_CMD_H
  2575. +#define IPKG_CMD_H
  2576. +
  2577. +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
  2578. +
  2579. +struct ipkg_cmd
  2580. +{
  2581. + const char *name;
  2582. + int requires_args;
  2583. + ipkg_cmd_fun_t fun;
  2584. +};
  2585. +typedef struct ipkg_cmd ipkg_cmd_t;
  2586. +
  2587. +ipkg_cmd_t *ipkg_cmd_find(const char *name);
  2588. +#ifdef IPKG_LIB
  2589. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
  2590. + const char **argv, void *userdata);
  2591. +#else
  2592. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv);
  2593. +#endif
  2594. +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
  2595. +/* install any packges with state_want == SW_INSTALL */
  2596. +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
  2597. +/* ensure that all dependences are satisfied */
  2598. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
  2599. +
  2600. +int pkg_mark_provides(pkg_t *pkg);
  2601. +
  2602. +#endif
  2603. diff -Nur busybox-1.13.4.orig/archival/libipkg/ipkg_conf.c busybox-1.13.4/archival/libipkg/ipkg_conf.c
  2604. --- busybox-1.13.4.orig/archival/libipkg/ipkg_conf.c 1970-01-01 01:00:00.000000000 +0100
  2605. +++ busybox-1.13.4/archival/libipkg/ipkg_conf.c 2009-05-31 15:40:37.021990539 +0200
  2606. @@ -0,0 +1,711 @@
  2607. +/* ipkg_conf.c - the itsy package management system
  2608. +
  2609. + Carl D. Worth
  2610. +
  2611. + Copyright (C) 2001 University of Southern California
  2612. +
  2613. + This program is free software; you can redistribute it and/or
  2614. + modify it under the terms of the GNU General Public License as
  2615. + published by the Free Software Foundation; either version 2, or (at
  2616. + your option) any later version.
  2617. +
  2618. + This program is distributed in the hope that it will be useful, but
  2619. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2620. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2621. + General Public License for more details.
  2622. +*/
  2623. +
  2624. +#include <glob.h>
  2625. +
  2626. +#include "ipkg.h"
  2627. +#include "ipkg_conf.h"
  2628. +
  2629. +#include "xregex.h"
  2630. +#include "sprintf_alloc.h"
  2631. +#include "ipkg_conf.h"
  2632. +#include "ipkg_message.h"
  2633. +#include "file_util.h"
  2634. +#include "str_util.h"
  2635. +#include "xsystem.h"
  2636. +
  2637. +
  2638. +ipkg_conf_t *global_conf;
  2639. +
  2640. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  2641. + pkg_src_list_t *pkg_src_list,
  2642. + nv_pair_list_t *tmp_dest_nv_pair_list,
  2643. + char **tmp_lists_dir);
  2644. +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
  2645. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  2646. + const char *name, const char *value);
  2647. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2648. + const char *default_dest_name);
  2649. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
  2650. + pkg_src_list_t *nv_pair_list);
  2651. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
  2652. + nv_pair_list_t *nv_pair_list, char * lists_dir);
  2653. +
  2654. +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
  2655. +{
  2656. + ipkg_option_t tmp[] = {
  2657. + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
  2658. + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
  2659. + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
  2660. + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
  2661. + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
  2662. + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
  2663. + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
  2664. + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
  2665. + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
  2666. + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
  2667. + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
  2668. + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
  2669. + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
  2670. + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
  2671. + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
  2672. + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
  2673. + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
  2674. + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
  2675. + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
  2676. + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
  2677. + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
  2678. + { NULL }
  2679. + };
  2680. +
  2681. + *options = (ipkg_option_t *)malloc(sizeof(tmp));
  2682. + if ( options == NULL ){
  2683. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  2684. + return -1;
  2685. + }
  2686. +
  2687. + memcpy(*options, tmp, sizeof(tmp));
  2688. + return 0;
  2689. +};
  2690. +
  2691. +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
  2692. +{
  2693. + if (arg_str) {
  2694. + if (*conf_str) {
  2695. + free(*conf_str);
  2696. + }
  2697. + *conf_str = strdup(arg_str);
  2698. + }
  2699. +}
  2700. +
  2701. +static void ipkg_conf_free_string(char **conf_str)
  2702. +{
  2703. + if (*conf_str) {
  2704. + free(*conf_str);
  2705. + *conf_str = NULL;
  2706. + }
  2707. +}
  2708. +
  2709. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
  2710. +{
  2711. + int err;
  2712. + char *tmp_dir_base;
  2713. + nv_pair_list_t tmp_dest_nv_pair_list;
  2714. + char * lists_dir =NULL;
  2715. + glob_t globbuf;
  2716. + const char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
  2717. + char *pending_dir =NULL;
  2718. +
  2719. + memset(conf, 0, sizeof(ipkg_conf_t));
  2720. +
  2721. + pkg_src_list_init(&conf->pkg_src_list);
  2722. +
  2723. + nv_pair_list_init(&tmp_dest_nv_pair_list);
  2724. + pkg_dest_list_init(&conf->pkg_dest_list);
  2725. +
  2726. + nv_pair_list_init(&conf->arch_list);
  2727. +
  2728. + conf->restrict_to_default_dest = 0;
  2729. + conf->default_dest = NULL;
  2730. +
  2731. +
  2732. + if (args->tmp_dir)
  2733. + tmp_dir_base = args->tmp_dir;
  2734. + else
  2735. + tmp_dir_base = getenv("TMPDIR");
  2736. + sprintf_alloc(&conf->tmp_dir, "%s/%s",
  2737. + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
  2738. + IPKG_CONF_TMP_DIR_SUFFIX);
  2739. + conf->tmp_dir = mkdtemp(conf->tmp_dir);
  2740. + if (conf->tmp_dir == NULL) {
  2741. + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
  2742. + __FUNCTION__, conf->tmp_dir, strerror(errno));
  2743. + return errno;
  2744. + }
  2745. +
  2746. + conf->force_depends = 0;
  2747. + conf->force_defaults = 0;
  2748. + conf->force_overwrite = 0;
  2749. + conf->force_downgrade = 0;
  2750. + conf->force_reinstall = 0;
  2751. + conf->force_space = 0;
  2752. + conf->force_removal_of_essential_packages = 0;
  2753. + conf->force_removal_of_dependent_packages = 0;
  2754. + conf->nodeps = 0;
  2755. + conf->verbose_wget = 0;
  2756. + conf->offline_root = NULL;
  2757. + conf->offline_root_pre_script_cmd = NULL;
  2758. + conf->offline_root_post_script_cmd = NULL;
  2759. + conf->multiple_providers = 0;
  2760. + conf->verbosity = 1;
  2761. + conf->noaction = 0;
  2762. +
  2763. + conf->http_proxy = NULL;
  2764. + conf->ftp_proxy = NULL;
  2765. + conf->no_proxy = NULL;
  2766. + conf->proxy_user = NULL;
  2767. + conf->proxy_passwd = NULL;
  2768. +
  2769. + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2770. + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2771. + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2772. + lists_dir=(char *)malloc(1);
  2773. + lists_dir[0]='\0';
  2774. + if (args->conf_file) {
  2775. + struct stat stat_buf;
  2776. + err = stat(args->conf_file, &stat_buf);
  2777. + if (err == 0)
  2778. + if (ipkg_conf_parse_file(conf, args->conf_file,
  2779. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2780. + /* Memory leakage from ipkg_conf_parse-file */
  2781. + return -1;
  2782. + }
  2783. +
  2784. + }
  2785. +
  2786. + /* if (!lists_dir ){*/
  2787. + if (strlen(lists_dir)<=1 ){
  2788. + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
  2789. + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
  2790. + }
  2791. +
  2792. + if (args->offline_root) {
  2793. + char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
  2794. + sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
  2795. + free(lists_dir);
  2796. + lists_dir = tmp;
  2797. + }
  2798. +
  2799. + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
  2800. + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
  2801. +
  2802. + conf->lists_dir = strdup(lists_dir);
  2803. + conf->pending_dir = strdup(pending_dir);
  2804. +
  2805. + if (args->offline_root)
  2806. + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
  2807. + memset(&globbuf, 0, sizeof(globbuf));
  2808. + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
  2809. + if (!err) {
  2810. + int i;
  2811. + for (i = 0; i < globbuf.gl_pathc; i++) {
  2812. + if (globbuf.gl_pathv[i])
  2813. + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
  2814. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2815. + /* Memory leakage from ipkg_conf_parse-file */
  2816. + return -1;
  2817. + }
  2818. + }
  2819. + }
  2820. + globfree(&globbuf);
  2821. +
  2822. + /* if no architectures were defined, then default all, noarch, and host architecture */
  2823. + if (nv_pair_list_empty(&conf->arch_list)) {
  2824. + nv_pair_list_append(&conf->arch_list, "all", "1");
  2825. + nv_pair_list_append(&conf->arch_list, "noarch", "1");
  2826. + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
  2827. + }
  2828. +
  2829. + /* Even if there is no conf file, we'll need at least one dest. */
  2830. + if (tmp_dest_nv_pair_list.head == NULL) {
  2831. + nv_pair_list_append(&tmp_dest_nv_pair_list,
  2832. + IPKG_CONF_DEFAULT_DEST_NAME,
  2833. + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
  2834. + }
  2835. +
  2836. + /* After parsing the file, set options from command-line, (so that
  2837. + command-line arguments take precedence) */
  2838. + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
  2839. + really needs to be cleaned up. There is so much duplication
  2840. + right now it is ridiculous. Maybe ipkg_conf_t should just save
  2841. + a pointer to args_t (which could then not be freed), rather
  2842. + than duplicating every field here? */
  2843. + if (args->force_depends) {
  2844. + conf->force_depends = 1;
  2845. + }
  2846. + if (args->force_defaults) {
  2847. + conf->force_defaults = 1;
  2848. + }
  2849. + if (args->force_overwrite) {
  2850. + conf->force_overwrite = 1;
  2851. + }
  2852. + if (args->force_downgrade) {
  2853. + conf->force_downgrade = 1;
  2854. + }
  2855. + if (args->force_reinstall) {
  2856. + conf->force_reinstall = 1;
  2857. + }
  2858. + if (args->force_removal_of_dependent_packages) {
  2859. + conf->force_removal_of_dependent_packages = 1;
  2860. + }
  2861. + if (args->force_removal_of_essential_packages) {
  2862. + conf->force_removal_of_essential_packages = 1;
  2863. + }
  2864. + if (args->nodeps) {
  2865. + conf->nodeps = 1;
  2866. + }
  2867. + if (args->noaction) {
  2868. + conf->noaction = 1;
  2869. + }
  2870. + if (args->query_all) {
  2871. + conf->query_all = 1;
  2872. + }
  2873. + if (args->verbose_wget) {
  2874. + conf->verbose_wget = 1;
  2875. + }
  2876. + if (args->multiple_providers) {
  2877. + conf->multiple_providers = 1;
  2878. + }
  2879. + if (args->verbosity != conf->verbosity) {
  2880. + conf->verbosity = args->verbosity;
  2881. + }
  2882. +
  2883. + ipkg_conf_override_string(&conf->offline_root,
  2884. + args->offline_root);
  2885. + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
  2886. + args->offline_root_pre_script_cmd);
  2887. + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
  2888. + args->offline_root_post_script_cmd);
  2889. +
  2890. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  2891. + read anything from there.
  2892. +*/
  2893. + if ( !(args->nocheckfordirorfile)){
  2894. + /* need to run load the source list before dest list -Jamey */
  2895. + if ( !(args->noreadfeedsfile))
  2896. + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
  2897. +
  2898. + /* Now that we have resolved conf->offline_root, we can commit to
  2899. + the directory names for the dests and load in all the package
  2900. + lists. */
  2901. + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
  2902. +
  2903. + if (args->dest) {
  2904. + err = ipkg_conf_set_default_dest(conf, args->dest);
  2905. + if (err) {
  2906. + return err;
  2907. + }
  2908. + }
  2909. + }
  2910. + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
  2911. + free(lists_dir);
  2912. + free(pending_dir);
  2913. +
  2914. + return 0;
  2915. +}
  2916. +
  2917. +void ipkg_conf_deinit(ipkg_conf_t *conf)
  2918. +{
  2919. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  2920. +#error
  2921. + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
  2922. + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  2923. + __FUNCTION__, conf->tmp_dir);
  2924. +#else
  2925. + int err;
  2926. +
  2927. + err = rmdir(conf->tmp_dir);
  2928. + if (err) {
  2929. + if (errno == ENOTEMPTY) {
  2930. + char *cmd;
  2931. + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
  2932. + err = xsystem(cmd);
  2933. + free(cmd);
  2934. + }
  2935. + if (err)
  2936. + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
  2937. + }
  2938. +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
  2939. +
  2940. + free(conf->tmp_dir); /*XXX*/
  2941. +
  2942. + pkg_src_list_deinit(&conf->pkg_src_list);
  2943. + pkg_dest_list_deinit(&conf->pkg_dest_list);
  2944. + nv_pair_list_deinit(&conf->arch_list);
  2945. + if (&conf->pkg_hash)
  2946. + pkg_hash_deinit(&conf->pkg_hash);
  2947. + if (&conf->file_hash)
  2948. + hash_table_deinit(&conf->file_hash);
  2949. + if (&conf->obs_file_hash)
  2950. + hash_table_deinit(&conf->obs_file_hash);
  2951. +
  2952. + ipkg_conf_free_string(&conf->offline_root);
  2953. + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
  2954. + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
  2955. +
  2956. + if (conf->verbosity > 1) {
  2957. + int i;
  2958. + hash_table_t *hashes[] = {
  2959. + &conf->pkg_hash,
  2960. + &conf->file_hash,
  2961. + &conf->obs_file_hash };
  2962. + for (i = 0; i < 3; i++) {
  2963. + hash_table_t *hash = hashes[i];
  2964. + int c = 0;
  2965. + int n_conflicts = 0;
  2966. + int j;
  2967. + for (j = 0; j < hash->n_entries; j++) {
  2968. + int len = 0;
  2969. + hash_entry_t *e = &hash->entries[j];
  2970. + if (e->next)
  2971. + n_conflicts++;
  2972. + while (e && e->key) {
  2973. + len++;
  2974. + e = e->next;
  2975. + }
  2976. + if (len > c)
  2977. + c = len;
  2978. + }
  2979. + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
  2980. + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
  2981. + hash_table_deinit(hash);
  2982. + }
  2983. + }
  2984. +}
  2985. +
  2986. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2987. + const char *default_dest_name)
  2988. +{
  2989. + pkg_dest_list_elt_t *iter;
  2990. + pkg_dest_t *dest;
  2991. +
  2992. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  2993. + dest = iter->data;
  2994. + if (strcmp(dest->name, default_dest_name) == 0) {
  2995. + conf->default_dest = dest;
  2996. + conf->restrict_to_default_dest = 1;
  2997. + return 0;
  2998. + }
  2999. + }
  3000. +
  3001. + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
  3002. +
  3003. + return 1;
  3004. +}
  3005. +
  3006. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
  3007. +{
  3008. + pkg_src_list_elt_t *iter;
  3009. + pkg_src_t *src;
  3010. + char *list_file;
  3011. +
  3012. + for (iter = pkg_src_list->head; iter; iter = iter->next) {
  3013. + src = iter->data;
  3014. + if (src == NULL) {
  3015. + continue;
  3016. + }
  3017. +
  3018. + sprintf_alloc(&list_file, "%s/%s",
  3019. + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
  3020. + src->name);
  3021. +
  3022. + if (file_exists(list_file)) {
  3023. + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
  3024. + }
  3025. + free(list_file);
  3026. + }
  3027. +
  3028. + return 0;
  3029. +}
  3030. +
  3031. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
  3032. +{
  3033. + nv_pair_list_elt_t *iter;
  3034. + nv_pair_t *nv_pair;
  3035. + pkg_dest_t *dest;
  3036. + char *root_dir;
  3037. +
  3038. + for (iter = nv_pair_list->head; iter; iter = iter->next) {
  3039. + nv_pair = iter->data;
  3040. +
  3041. + if (conf->offline_root) {
  3042. + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
  3043. + } else {
  3044. + root_dir = strdup(nv_pair->value);
  3045. + }
  3046. + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
  3047. + free(root_dir);
  3048. + if (dest == NULL) {
  3049. + continue;
  3050. + }
  3051. + if (conf->default_dest == NULL) {
  3052. + conf->default_dest = dest;
  3053. + }
  3054. + if (file_exists(dest->status_file_name)) {
  3055. + pkg_hash_add_from_file(conf, dest->status_file_name,
  3056. + NULL, dest, 1);
  3057. + }
  3058. + }
  3059. +
  3060. + return 0;
  3061. +}
  3062. +
  3063. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  3064. + pkg_src_list_t *pkg_src_list,
  3065. + nv_pair_list_t *tmp_dest_nv_pair_list,
  3066. + char **lists_dir)
  3067. +{
  3068. + ipkg_option_t * options;
  3069. + FILE *file = fopen(filename, "r");
  3070. + regex_t valid_line_re, comment_re;
  3071. +#define regmatch_size 12
  3072. + regmatch_t regmatch[regmatch_size];
  3073. +
  3074. + if (ipkg_init_options_array(conf, &options)<0)
  3075. + return ENOMEM;
  3076. +
  3077. + if (file == NULL) {
  3078. + fprintf(stderr, "%s: failed to open %s: %s\n",
  3079. + __FUNCTION__, filename, strerror(errno));
  3080. + free(options);
  3081. + return errno;
  3082. + }
  3083. + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
  3084. +
  3085. + xregcomp(&comment_re,
  3086. + "^[[:space:]]*(#.*|[[:space:]]*)$",
  3087. + REG_EXTENDED);
  3088. + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
  3089. +
  3090. + while(1) {
  3091. + int line_num = 0;
  3092. + char *line;
  3093. + char *type, *name, *value, *extra;
  3094. +
  3095. + line = file_read_line_alloc(file);
  3096. + line_num++;
  3097. + if (line == NULL) {
  3098. + break;
  3099. + }
  3100. +
  3101. + str_chomp(line);
  3102. +
  3103. + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
  3104. + goto NEXT_LINE;
  3105. + }
  3106. +
  3107. + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
  3108. + str_chomp(line);
  3109. + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
  3110. + filename, line_num, line);
  3111. + goto NEXT_LINE;
  3112. + }
  3113. +
  3114. + /* This has to be so ugly to deal with optional quotation marks */
  3115. + if (regmatch[2].rm_so > 0) {
  3116. + type = strndup(line + regmatch[2].rm_so,
  3117. + regmatch[2].rm_eo - regmatch[2].rm_so);
  3118. + } else {
  3119. + type = strndup(line + regmatch[3].rm_so,
  3120. + regmatch[3].rm_eo - regmatch[3].rm_so);
  3121. + }
  3122. + if (regmatch[5].rm_so > 0) {
  3123. + name = strndup(line + regmatch[5].rm_so,
  3124. + regmatch[5].rm_eo - regmatch[5].rm_so);
  3125. + } else {
  3126. + name = strndup(line + regmatch[6].rm_so,
  3127. + regmatch[6].rm_eo - regmatch[6].rm_so);
  3128. + }
  3129. + if (regmatch[8].rm_so > 0) {
  3130. + value = strndup(line + regmatch[8].rm_so,
  3131. + regmatch[8].rm_eo - regmatch[8].rm_so);
  3132. + } else {
  3133. + value = strndup(line + regmatch[9].rm_so,
  3134. + regmatch[9].rm_eo - regmatch[9].rm_so);
  3135. + }
  3136. + extra = NULL;
  3137. + if (regmatch[11].rm_so > 0) {
  3138. + extra = strndup (line + regmatch[11].rm_so,
  3139. + regmatch[11].rm_eo - regmatch[11].rm_so);
  3140. + }
  3141. +
  3142. + /* We use the tmp_dest_nv_pair_list below instead of
  3143. + conf->pkg_dest_list because we might encounter an
  3144. + offline_root option later and that would invalidate the
  3145. + directories we would have computed in
  3146. + pkg_dest_list_init. (We do a similar thing with
  3147. + tmp_src_nv_pair_list for sake of symmetry.) */
  3148. + if (strcmp(type, "option") == 0) {
  3149. + ipkg_conf_set_option(options, name, value);
  3150. + } else if (strcmp(type, "src") == 0) {
  3151. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  3152. + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
  3153. + } else {
  3154. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  3155. + name, value);
  3156. + }
  3157. + } else if (strcmp(type, "src/gz") == 0) {
  3158. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  3159. + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
  3160. + } else {
  3161. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  3162. + name, value);
  3163. + }
  3164. + } else if (strcmp(type, "dest") == 0) {
  3165. + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
  3166. + } else if (strcmp(type, "lists_dir") == 0) {
  3167. + *lists_dir = realloc(*lists_dir,strlen(value)+1);
  3168. + if (*lists_dir == NULL) {
  3169. + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
  3170. + free(options);
  3171. + return EINVAL;
  3172. + }
  3173. + sprintf (*lists_dir,"%s",value);
  3174. + } else if (strcmp(type, "arch") == 0) {
  3175. + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
  3176. + if (!value) {
  3177. + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
  3178. + value = strdup("10");
  3179. + }
  3180. + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
  3181. + } else {
  3182. + fprintf(stderr, "WARNING: Ignoring unknown configuration "
  3183. + "parameter: %s %s %s\n", type, name, value);
  3184. + free(options);
  3185. + return EINVAL;
  3186. + }
  3187. +
  3188. + free(type);
  3189. + free(name);
  3190. + free(value);
  3191. + if (extra)
  3192. + free (extra);
  3193. +
  3194. + NEXT_LINE:
  3195. + free(line);
  3196. + }
  3197. +
  3198. + free(options);
  3199. + regfree(&comment_re);
  3200. + regfree(&valid_line_re);
  3201. + fclose(file);
  3202. +
  3203. + return 0;
  3204. +}
  3205. +
  3206. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  3207. + const char *name, const char *value)
  3208. +{
  3209. + int i = 0;
  3210. + while (options[i].name) {
  3211. + if (strcmp(options[i].name, name) == 0) {
  3212. + switch (options[i].type) {
  3213. + case IPKG_OPT_TYPE_BOOL:
  3214. + *((int *)options[i].value) = 1;
  3215. + return 0;
  3216. + case IPKG_OPT_TYPE_INT:
  3217. + if (value) {
  3218. + *((int *)options[i].value) = atoi(value);
  3219. + return 0;
  3220. + } else {
  3221. + printf("%s: Option %s need an argument\n",
  3222. + __FUNCTION__, name);
  3223. + return EINVAL;
  3224. + }
  3225. + case IPKG_OPT_TYPE_STRING:
  3226. + if (value) {
  3227. + *((char **)options[i].value) = strdup(value);
  3228. + return 0;
  3229. + } else {
  3230. + printf("%s: Option %s need an argument\n",
  3231. + __FUNCTION__, name);
  3232. + return EINVAL;
  3233. + }
  3234. + }
  3235. + }
  3236. + i++;
  3237. + }
  3238. +
  3239. + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
  3240. + __FUNCTION__, name, value);
  3241. + return EINVAL;
  3242. +}
  3243. +
  3244. +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
  3245. +{
  3246. + pkg_dest_list_elt_t *iter;
  3247. + pkg_dest_t *dest;
  3248. + pkg_vec_t *all;
  3249. + pkg_t *pkg;
  3250. + register int i;
  3251. + int err;
  3252. +
  3253. + if (conf->noaction)
  3254. + return 0;
  3255. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3256. + dest = iter->data;
  3257. + dest->status_file = fopen(dest->status_file_tmp_name, "w");
  3258. + if (dest->status_file == NULL) {
  3259. + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
  3260. + __FUNCTION__, dest->status_file_name, strerror(errno));
  3261. + }
  3262. + }
  3263. +
  3264. + all = pkg_vec_alloc();
  3265. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  3266. +
  3267. + for(i = 0; i < all->len; i++) {
  3268. + pkg = all->pkgs[i];
  3269. + /* We don't need most uninstalled packages in the status file */
  3270. + if (pkg->state_status == SS_NOT_INSTALLED
  3271. + && (pkg->state_want == SW_UNKNOWN
  3272. + || pkg->state_want == SW_DEINSTALL
  3273. + || pkg->state_want == SW_PURGE)) {
  3274. + continue;
  3275. + }
  3276. + if (!pkg) {
  3277. + fprintf(stderr, "Null package\n");
  3278. + }
  3279. + if (pkg->dest == NULL) {
  3280. + fprintf(stderr, "%s: ERROR: Can't write status for "
  3281. + "package %s since it has a NULL dest\n",
  3282. + __FUNCTION__, pkg->name);
  3283. + continue;
  3284. + }
  3285. + if (pkg->dest->status_file) {
  3286. + pkg_print_status(pkg, pkg->dest->status_file);
  3287. + }
  3288. + }
  3289. +
  3290. + pkg_vec_free(all);
  3291. +
  3292. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3293. + dest = iter->data;
  3294. + if (dest->status_file) {
  3295. + err = ferror(dest->status_file);
  3296. + fclose(dest->status_file);
  3297. + dest->status_file = NULL;
  3298. + if (!err) {
  3299. + file_move(dest->status_file_tmp_name, dest->status_file_name);
  3300. + } else {
  3301. + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
  3302. + "retaining old %s\n", __FUNCTION__,
  3303. + dest->status_file_tmp_name, dest->status_file_name);
  3304. + }
  3305. + }
  3306. + }
  3307. +
  3308. + return 0;
  3309. +}
  3310. +
  3311. +
  3312. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
  3313. +{
  3314. + char *root_filename;
  3315. + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
  3316. + return root_filename;
  3317. +}
  3318. diff -Nur busybox-1.13.4.orig/archival/libipkg/ipkg_conf.h busybox-1.13.4/archival/libipkg/ipkg_conf.h
  3319. --- busybox-1.13.4.orig/archival/libipkg/ipkg_conf.h 1970-01-01 01:00:00.000000000 +0100
  3320. +++ busybox-1.13.4/archival/libipkg/ipkg_conf.h 2009-05-31 15:40:37.025991328 +0200
  3321. @@ -0,0 +1,107 @@
  3322. +/* ipkg_conf.h - the itsy package management system
  3323. +
  3324. + Carl D. Worth
  3325. +
  3326. + Copyright (C) 2001 University of Southern California
  3327. +
  3328. + This program is free software; you can redistribute it and/or
  3329. + modify it under the terms of the GNU General Public License as
  3330. + published by the Free Software Foundation; either version 2, or (at
  3331. + your option) any later version.
  3332. +
  3333. + This program is distributed in the hope that it will be useful, but
  3334. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3335. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3336. + General Public License for more details.
  3337. +*/
  3338. +
  3339. +#ifndef IPKG_CONF_H
  3340. +#define IPKG_CONF_H
  3341. +
  3342. +typedef struct ipkg_conf ipkg_conf_t;
  3343. +
  3344. +#include "hash_table.h"
  3345. +#include "ipkg.h"
  3346. +#include "args.h"
  3347. +#include "pkg.h"
  3348. +#include "pkg_hash.h"
  3349. +#include "pkg_src_list.h"
  3350. +#include "pkg_dest_list.h"
  3351. +#include "nv_pair_list.h"
  3352. +
  3353. +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
  3354. +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
  3355. +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
  3356. +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
  3357. +
  3358. +/* In case the config file defines no dest */
  3359. +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
  3360. +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
  3361. +
  3362. +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
  3363. +
  3364. +struct ipkg_conf
  3365. +{
  3366. + pkg_src_list_t pkg_src_list;
  3367. + pkg_dest_list_t pkg_dest_list;
  3368. + nv_pair_list_t arch_list;
  3369. +
  3370. + int restrict_to_default_dest;
  3371. + pkg_dest_t *default_dest;
  3372. +
  3373. + char *tmp_dir;
  3374. + char *lists_dir;
  3375. + char *pending_dir;
  3376. +
  3377. + /* options */
  3378. + int force_depends;
  3379. + int force_defaults;
  3380. + int force_overwrite;
  3381. + int force_downgrade;
  3382. + int force_reinstall;
  3383. + int force_space;
  3384. + int force_removal_of_dependent_packages;
  3385. + int force_removal_of_essential_packages;
  3386. + int nodeps; /* do not follow dependences */
  3387. + int verbose_wget;
  3388. + int multiple_providers;
  3389. + char *offline_root;
  3390. + char *offline_root_pre_script_cmd;
  3391. + char *offline_root_post_script_cmd;
  3392. + int query_all;
  3393. + int verbosity;
  3394. + int noaction;
  3395. +
  3396. + /* proxy options */
  3397. + char *http_proxy;
  3398. + char *ftp_proxy;
  3399. + char *no_proxy;
  3400. + char *proxy_user;
  3401. + char *proxy_passwd;
  3402. +
  3403. + hash_table_t pkg_hash;
  3404. + hash_table_t file_hash;
  3405. + hash_table_t obs_file_hash;
  3406. +};
  3407. +
  3408. +enum ipkg_option_type {
  3409. + IPKG_OPT_TYPE_BOOL,
  3410. + IPKG_OPT_TYPE_INT,
  3411. + IPKG_OPT_TYPE_STRING
  3412. +};
  3413. +typedef enum ipkg_option_type ipkg_option_type_t;
  3414. +
  3415. +typedef struct ipkg_option ipkg_option_t;
  3416. +struct ipkg_option {
  3417. + const char *name;
  3418. + const ipkg_option_type_t type;
  3419. + const void *value;
  3420. +};
  3421. +
  3422. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
  3423. +void ipkg_conf_deinit(ipkg_conf_t *conf);
  3424. +
  3425. +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
  3426. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
  3427. +
  3428. +#endif
  3429. diff -Nur busybox-1.13.4.orig/archival/libipkg/ipkg_configure.c busybox-1.13.4/archival/libipkg/ipkg_configure.c
  3430. --- busybox-1.13.4.orig/archival/libipkg/ipkg_configure.c 1970-01-01 01:00:00.000000000 +0100
  3431. +++ busybox-1.13.4/archival/libipkg/ipkg_configure.c 2009-05-31 15:40:37.025991328 +0200
  3432. @@ -0,0 +1,40 @@
  3433. +/* ipkg_configure.c - the itsy package management system
  3434. +
  3435. + Carl D. Worth
  3436. +
  3437. + Copyright (C) 2001 University of Southern California
  3438. +
  3439. + This program is free software; you can redistribute it and/or
  3440. + modify it under the terms of the GNU General Public License as
  3441. + published by the Free Software Foundation; either version 2, or (at
  3442. + your option) any later version.
  3443. +
  3444. + This program is distributed in the hope that it will be useful, but
  3445. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3446. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3447. + General Public License for more details.
  3448. +*/
  3449. +
  3450. +#include "ipkg.h"
  3451. +
  3452. +#include "ipkg_configure.h"
  3453. +
  3454. +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
  3455. +{
  3456. + int err;
  3457. +
  3458. + /* DPKG_INCOMPATIBILITY:
  3459. + dpkg actually does some conffile handling here, rather than at the
  3460. + end of ipkg_install(). Do we care? */
  3461. + /* DPKG_INCOMPATIBILITY:
  3462. + dpkg actually includes a version number to this script call */
  3463. + err = pkg_run_script(conf, pkg, "postinst", "configure");
  3464. + if (err) {
  3465. + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
  3466. + return err;
  3467. + }
  3468. +
  3469. + ipkg_state_changed++;
  3470. + return 0;
  3471. +}
  3472. +
  3473. diff -Nur busybox-1.13.4.orig/archival/libipkg/ipkg_configure.h busybox-1.13.4/archival/libipkg/ipkg_configure.h
  3474. --- busybox-1.13.4.orig/archival/libipkg/ipkg_configure.h 1970-01-01 01:00:00.000000000 +0100
  3475. +++ busybox-1.13.4/archival/libipkg/ipkg_configure.h 2009-05-31 15:40:37.025991328 +0200
  3476. @@ -0,0 +1,25 @@
  3477. +/* ipkg_configure.h - the itsy package management system
  3478. +
  3479. + Carl D. Worth
  3480. +
  3481. + Copyright (C) 2001 University of Southern California
  3482. +
  3483. + This program is free software; you can redistribute it and/or
  3484. + modify it under the terms of the GNU General Public License as
  3485. + published by the Free Software Foundation; either version 2, or (at
  3486. + your option) any later version.
  3487. +
  3488. + This program is distributed in the hope that it will be useful, but
  3489. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3490. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3491. + General Public License for more details.
  3492. +*/
  3493. +
  3494. +#ifndef IPKG_CONFIGURE_H
  3495. +#define IPKG_CONFIGURE_H
  3496. +
  3497. +#include "ipkg_conf.h"
  3498. +
  3499. +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
  3500. +
  3501. +#endif
  3502. diff -Nur busybox-1.13.4.orig/archival/libipkg/ipkg_download.c busybox-1.13.4/archival/libipkg/ipkg_download.c
  3503. --- busybox-1.13.4.orig/archival/libipkg/ipkg_download.c 1970-01-01 01:00:00.000000000 +0100
  3504. +++ busybox-1.13.4/archival/libipkg/ipkg_download.c 2009-05-31 15:42:41.497770134 +0200
  3505. @@ -0,0 +1,195 @@
  3506. +/* ipkg_download.c - the itsy package management system
  3507. +
  3508. + Carl D. Worth
  3509. +
  3510. + Copyright (C) 2001 University of Southern California
  3511. +
  3512. + This program is free software; you can redistribute it and/or
  3513. + modify it under the terms of the GNU General Public License as
  3514. + published by the Free Software Foundation; either version 2, or (at
  3515. + your option) any later version.
  3516. +
  3517. + This program is distributed in the hope that it will be useful, but
  3518. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3519. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3520. + General Public License for more details.
  3521. +*/
  3522. +
  3523. +#include "ipkg.h"
  3524. +#include "ipkg_download.h"
  3525. +#include "ipkg_message.h"
  3526. +
  3527. +#include "sprintf_alloc.h"
  3528. +#include "xsystem.h"
  3529. +#include "file_util.h"
  3530. +#include "str_util.h"
  3531. +
  3532. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
  3533. +{
  3534. + int err = 0;
  3535. +
  3536. + char *src_basec = strdup(src);
  3537. + char *src_base = basename(src_basec);
  3538. + char *tmp_file_location;
  3539. + char *cmd;
  3540. +
  3541. + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
  3542. +
  3543. + fflush(stdout);
  3544. +
  3545. + if (str_starts_with(src, "file:")) {
  3546. + int ret;
  3547. + const char *file_src = src + 5;
  3548. + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
  3549. + ret = file_copy(src + 5, dest_file_name);
  3550. + ipkg_message(conf,IPKG_INFO,"Done.\n");
  3551. + return ret;
  3552. + }
  3553. +
  3554. + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
  3555. + err = unlink(tmp_file_location);
  3556. + if (err && errno != ENOENT) {
  3557. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
  3558. + __FUNCTION__, tmp_file_location, strerror(errno));
  3559. + free(tmp_file_location);
  3560. + return errno;
  3561. + }
  3562. +
  3563. + if (conf->http_proxy) {
  3564. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
  3565. + setenv("http_proxy", conf->http_proxy, 1);
  3566. + }
  3567. + if (conf->ftp_proxy) {
  3568. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
  3569. + setenv("ftp_proxy", conf->ftp_proxy, 1);
  3570. + }
  3571. + if (conf->no_proxy) {
  3572. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
  3573. + setenv("no_proxy", conf->no_proxy, 1);
  3574. + }
  3575. +
  3576. + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
  3577. + sprintf_alloc(&cmd, "wget %s %s%s %s%s %s -P %s %s",
  3578. + (conf->http_proxy || conf->ftp_proxy) ? "-Y on" : "",
  3579. + conf->proxy_user ? "--proxy-user=" : "",
  3580. + conf->proxy_user ? conf->proxy_user : "",
  3581. + conf->proxy_passwd ? "--proxy-passwd=" : "",
  3582. + conf->proxy_passwd ? conf->proxy_passwd : "",
  3583. + conf->verbose_wget ? "" : "-q",
  3584. + conf->tmp_dir,
  3585. + src);
  3586. + err = xsystem(cmd);
  3587. + if (err) {
  3588. + if (err != -1) {
  3589. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
  3590. + __FUNCTION__, err, cmd);
  3591. + }
  3592. + unlink(tmp_file_location);
  3593. + free(tmp_file_location);
  3594. + free(src_basec);
  3595. + free(cmd);
  3596. + return EINVAL;
  3597. + }
  3598. + free(cmd);
  3599. +
  3600. + err = file_move(tmp_file_location, dest_file_name);
  3601. +
  3602. + free(tmp_file_location);
  3603. + free(src_basec);
  3604. +
  3605. + if (err) {
  3606. + return err;
  3607. + }
  3608. +
  3609. + return 0;
  3610. +}
  3611. +
  3612. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
  3613. +{
  3614. + int err;
  3615. + char *url;
  3616. +
  3617. + if (pkg->src == NULL) {
  3618. + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
  3619. + pkg->name, pkg->parent->name);
  3620. + return -1;
  3621. + }
  3622. +
  3623. + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
  3624. +
  3625. + /* XXX: BUG: The pkg->filename might be something like
  3626. + "../../foo.ipk". While this is correct, and exactly what we
  3627. + want to use to construct url above, here we actually need to
  3628. + use just the filename part, without any directory. */
  3629. + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
  3630. +
  3631. + err = ipkg_download(conf, url, pkg->local_filename);
  3632. + free(url);
  3633. +
  3634. + return err;
  3635. +}
  3636. +
  3637. +/*
  3638. + * Downloads file from url, installs in package database, return package name.
  3639. + */
  3640. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
  3641. +{
  3642. + int err = 0;
  3643. + pkg_t *pkg;
  3644. + pkg = pkg_new();
  3645. + if (pkg == NULL)
  3646. + return ENOMEM;
  3647. +
  3648. + if (str_starts_with(url, "http://")
  3649. + || str_starts_with(url, "ftp://")) {
  3650. + char *tmp_file;
  3651. + char *file_basec = strdup(url);
  3652. + char *file_base = basename(file_basec);
  3653. +
  3654. + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
  3655. + err = ipkg_download(conf, url, tmp_file);
  3656. + if (err)
  3657. + return err;
  3658. +
  3659. + err = pkg_init_from_file(pkg, tmp_file);
  3660. + if (err)
  3661. + return err;
  3662. + pkg->local_filename = strdup(tmp_file);
  3663. +
  3664. + free(tmp_file);
  3665. + free(file_basec);
  3666. +
  3667. + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
  3668. + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
  3669. +
  3670. + err = pkg_init_from_file(pkg, url);
  3671. + if (err)
  3672. + return err;
  3673. + pkg->local_filename = strdup(url);
  3674. + ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand (%s).\n", pkg->name,pkg->local_filename);
  3675. + pkg->provided_by_hand = 1;
  3676. +
  3677. + } else {
  3678. + pkg_deinit(pkg);
  3679. + free(pkg);
  3680. + return 0;
  3681. + }
  3682. +
  3683. + if (!pkg->architecture) {
  3684. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3685. + return -EINVAL;
  3686. + }
  3687. +
  3688. + pkg->dest = conf->default_dest;
  3689. + pkg->state_want = SW_INSTALL;
  3690. + pkg->state_flag |= SF_PREFER;
  3691. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3692. + if ( pkg == NULL ){
  3693. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  3694. + return 0;
  3695. + }
  3696. + if (namep) {
  3697. + *namep = strdup(pkg->name);
  3698. + }
  3699. + return 0;
  3700. +}
  3701. diff -Nur busybox-1.13.4.orig/archival/libipkg/ipkg_download.h busybox-1.13.4/archival/libipkg/ipkg_download.h
  3702. --- busybox-1.13.4.orig/archival/libipkg/ipkg_download.h 1970-01-01 01:00:00.000000000 +0100
  3703. +++ busybox-1.13.4/archival/libipkg/ipkg_download.h 2009-05-31 15:40:37.033992625 +0200
  3704. @@ -0,0 +1,30 @@
  3705. +/* ipkg_download.h - the itsy package management system
  3706. +
  3707. + Carl D. Worth
  3708. +
  3709. + Copyright (C) 2001 University of Southern California
  3710. +
  3711. + This program is free software; you can redistribute it and/or
  3712. + modify it under the terms of the GNU General Public License as
  3713. + published by the Free Software Foundation; either version 2, or (at
  3714. + your option) any later version.
  3715. +
  3716. + This program is distributed in the hope that it will be useful, but
  3717. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3718. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3719. + General Public License for more details.
  3720. +*/
  3721. +
  3722. +#ifndef IPKG_DOWNLOAD_H
  3723. +#define IPKG_DOWNLOAD_H
  3724. +
  3725. +#include "ipkg_conf.h"
  3726. +
  3727. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
  3728. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
  3729. +/*
  3730. + * Downloads file from url, installs in package database, return package name.
  3731. + */
  3732. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
  3733. +
  3734. +#endif
  3735. diff -Nur busybox-1.13.4.orig/archival/libipkg/ipkg_includes.h busybox-1.13.4/archival/libipkg/ipkg_includes.h
  3736. --- busybox-1.13.4.orig/archival/libipkg/ipkg_includes.h 1970-01-01 01:00:00.000000000 +0100
  3737. +++ busybox-1.13.4/archival/libipkg/ipkg_includes.h 2009-05-31 15:40:37.041993644 +0200
  3738. @@ -0,0 +1,79 @@
  3739. +#ifndef IPKG_INCLUDES_H
  3740. +#define IPKG_INCLUDES_H
  3741. +
  3742. +/* Define to 1 if you have the <memory.h> header file. */
  3743. +#define HAVE_MEMORY_H 1
  3744. +
  3745. +/* Define to 1 if you have the <regex.h> header file. */
  3746. +#define HAVE_REGEX_H 1
  3747. +
  3748. +/* Define to 1 if you have the <stdlib.h> header file. */
  3749. +#define HAVE_STDLIB_H 1
  3750. +
  3751. +/* Define to 1 if you have the <strings.h> header file. */
  3752. +#define HAVE_STRINGS_H 1
  3753. +
  3754. +/* Define to 1 if you have the <string.h> header file. */
  3755. +#define HAVE_STRING_H 1
  3756. +
  3757. +/* Define to 1 if you have the <sys/stat.h> header file. */
  3758. +#define HAVE_SYS_STAT_H 1
  3759. +
  3760. +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
  3761. +#define HAVE_SYS_WAIT_H 1
  3762. +
  3763. +/* Define to 1 if you have the <unistd.h> header file. */
  3764. +#define HAVE_UNISTD_H 1
  3765. +
  3766. +/* Define to 1 if you have the ANSI C header files. */
  3767. +#define STDC_HEADERS 1
  3768. +
  3769. +
  3770. +#include <stdio.h>
  3771. +
  3772. +#if STDC_HEADERS
  3773. +# include <stdlib.h>
  3774. +# include <stdarg.h>
  3775. +# include <stddef.h>
  3776. +# include <ctype.h>
  3777. +# include <errno.h>
  3778. +#else
  3779. +# if HAVE_STDLIB_H
  3780. +# include <stdlib.h>
  3781. +# endif
  3782. +#endif
  3783. +
  3784. +#if HAVE_REGEX_H
  3785. +# include <regex.h>
  3786. +#endif
  3787. +
  3788. +#if HAVE_STRING_H
  3789. +# if !STDC_HEADERS && HAVE_MEMORY_H
  3790. +# include <memory.h>
  3791. +# endif
  3792. +/* XXX: What's the right way to pick up GNU's strndup declaration? */
  3793. +# if __GNUC__
  3794. +# define __USE_GNU 1
  3795. +# endif
  3796. +# include <string.h>
  3797. +# undef __USE_GNU
  3798. +#endif
  3799. +
  3800. +#if HAVE_STRINGS_H
  3801. +# include <strings.h>
  3802. +#endif
  3803. +
  3804. +#if HAVE_SYS_STAT_H
  3805. +# include <sys/stat.h>
  3806. +#endif
  3807. +
  3808. +#if HAVE_SYS_WAIT_H
  3809. +# include <sys/wait.h>
  3810. +#endif
  3811. +
  3812. +#if HAVE_UNISTD_H
  3813. +# include <sys/types.h>
  3814. +# include <unistd.h>
  3815. +#endif
  3816. +
  3817. +#endif /* IPKG_INCLUDES_H */
  3818. diff -Nur busybox-1.13.4.orig/archival/libipkg/ipkg_install.c busybox-1.13.4/archival/libipkg/ipkg_install.c
  3819. --- busybox-1.13.4.orig/archival/libipkg/ipkg_install.c 1970-01-01 01:00:00.000000000 +0100
  3820. +++ busybox-1.13.4/archival/libipkg/ipkg_install.c 2009-05-31 15:40:37.045994712 +0200
  3821. @@ -0,0 +1,1982 @@
  3822. +/* ipkg_install.c - the itsy package management system
  3823. +
  3824. + Carl D. Worth
  3825. +
  3826. + Copyright (C) 2001 University of Southern California
  3827. +
  3828. + This program is free software; you can redistribute it and/or
  3829. + modify it under the terms of the GNU General Public License as
  3830. + published by the Free Software Foundation; either version 2, or (at
  3831. + your option) any later version.
  3832. +
  3833. + This program is distributed in the hope that it will be useful, but
  3834. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3835. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3836. + General Public License for more details.
  3837. +*/
  3838. +
  3839. +#include "ipkg.h"
  3840. +#include <errno.h>
  3841. +#include <dirent.h>
  3842. +#include <glob.h>
  3843. +#include <time.h>
  3844. +#include <signal.h>
  3845. +typedef void (*sighandler_t)(int);
  3846. +
  3847. +#include "pkg.h"
  3848. +#include "pkg_hash.h"
  3849. +#include "pkg_extract.h"
  3850. +
  3851. +#include "ipkg_install.h"
  3852. +#include "ipkg_configure.h"
  3853. +#include "ipkg_download.h"
  3854. +#include "ipkg_remove.h"
  3855. +
  3856. +#include "ipkg_utils.h"
  3857. +#include "ipkg_message.h"
  3858. +
  3859. +#include "sprintf_alloc.h"
  3860. +#include "file_util.h"
  3861. +#include "str_util.h"
  3862. +#include "xsystem.h"
  3863. +#include "user.h"
  3864. +
  3865. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  3866. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
  3867. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
  3868. +
  3869. +/*
  3870. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3871. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3872. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3873. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3874. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3875. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3876. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3877. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
  3878. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3879. +*/
  3880. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3881. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3882. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg);
  3883. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3884. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg);
  3885. +
  3886. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3887. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3888. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
  3889. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
  3890. +
  3891. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
  3892. +
  3893. +static int user_prefers_old_conffile(const char *file, const char *backup);
  3894. +
  3895. +static char *backup_filename_alloc(const char *file_name);
  3896. +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
  3897. +static int backup_exists_for(const char *file_name);
  3898. +static int backup_remove(const char *file_name);
  3899. +
  3900. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees);
  3901. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3902. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3903. +
  3904. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
  3905. +{
  3906. + int err, cmp;
  3907. + pkg_t *pkg, *old;
  3908. + char *old_version, *new_version;
  3909. +
  3910. + pkg = pkg_new();
  3911. + if (pkg == NULL) {
  3912. + return ENOMEM;
  3913. + }
  3914. +
  3915. + err = pkg_init_from_file(pkg, filename);
  3916. + if (err) {
  3917. + return err;
  3918. + }
  3919. +
  3920. + if (!pkg->architecture) {
  3921. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3922. + return -EINVAL;
  3923. + }
  3924. +
  3925. + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
  3926. + freeing the pkg that we pass in. It might be nice to clean this up
  3927. + if possible. */
  3928. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3929. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  3930. +
  3931. + pkg->local_filename = strdup(filename);
  3932. +
  3933. + if (old) {
  3934. + old_version = pkg_version_str_alloc(old);
  3935. + new_version = pkg_version_str_alloc(pkg);
  3936. +
  3937. + cmp = pkg_compare_versions(old, pkg);
  3938. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3939. + cmp = -1 ; /* then we force ipkg to downgrade */
  3940. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3941. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3942. + }
  3943. + if (cmp > 0) {
  3944. + ipkg_message(conf, IPKG_NOTICE,
  3945. + "Not downgrading package %s on %s from %s to %s.\n",
  3946. + old->name, old->dest->name, old_version, new_version);
  3947. + pkg->state_want = SW_DEINSTALL;
  3948. + pkg->state_flag |= SF_OBSOLETE;
  3949. + free(old_version);
  3950. + free(new_version);
  3951. + return 0;
  3952. + } else {
  3953. + free(old_version);
  3954. + free(new_version);
  3955. + }
  3956. + }
  3957. +
  3958. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3959. + return ipkg_install_pkg(conf, pkg,0);
  3960. +}
  3961. +
  3962. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3963. +{
  3964. + int cmp;
  3965. + pkg_t *old, *new;
  3966. + char *old_version, *new_version;
  3967. +
  3968. + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
  3969. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  3970. + if ( old )
  3971. + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
  3972. +
  3973. + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
  3974. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  3975. + if ( new )
  3976. + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
  3977. +
  3978. +/* Pigi Basically here is broken the version stuff.
  3979. + What's happening is that nothing provide the version to differents
  3980. + functions, so the returned struct is always the latest.
  3981. + That's why the install by name don't work.
  3982. +*/
  3983. + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
  3984. +
  3985. + if ( old )
  3986. + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
  3987. + if ( new )
  3988. + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
  3989. + ipkg_message(conf, IPKG_DEBUG2, " \n");
  3990. +
  3991. + if (new == NULL) {
  3992. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3993. + }
  3994. +
  3995. + new->state_flag |= SF_USER;
  3996. + if (old) {
  3997. + old_version = pkg_version_str_alloc(old);
  3998. + new_version = pkg_version_str_alloc(new);
  3999. +
  4000. + cmp = pkg_compare_versions(old, new);
  4001. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4002. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
  4003. + cmp = -1 ; /* then we force ipkg to downgrade */
  4004. + /* We need to use a value < 0 because in the 0 case we are asking to */
  4005. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4006. + }
  4007. + ipkg_message(conf, IPKG_DEBUG,
  4008. + "Comparing visible versions of pkg %s:"
  4009. + "\n\t%s is installed "
  4010. + "\n\t%s is available "
  4011. + "\n\t%d was comparison result\n",
  4012. + pkg_name, old_version, new_version, cmp);
  4013. + if (cmp == 0 && !conf->force_reinstall) {
  4014. + ipkg_message(conf, IPKG_NOTICE,
  4015. + "Package %s (%s) installed in %s is up to date.\n",
  4016. + old->name, old_version, old->dest->name);
  4017. + free(old_version);
  4018. + free(new_version);
  4019. + return 0;
  4020. + } else if (cmp > 0) {
  4021. + ipkg_message(conf, IPKG_NOTICE,
  4022. + "Not downgrading package %s on %s from %s to %s.\n",
  4023. + old->name, old->dest->name, old_version, new_version);
  4024. + free(old_version);
  4025. + free(new_version);
  4026. + return 0;
  4027. + } else if (cmp < 0) {
  4028. + new->dest = old->dest;
  4029. + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
  4030. + }
  4031. + }
  4032. +
  4033. + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
  4034. + supposed to be an ipkg_error_t, but ipkg_install_pkg could
  4035. + return any kind of integer, (might be errno from a syscall,
  4036. + etc.). This is a real mess and will need to be cleaned up if
  4037. + anyone ever wants to make a nice libipkg. */
  4038. +
  4039. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4040. + return ipkg_install_pkg(conf, new,0);
  4041. +}
  4042. +
  4043. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
  4044. +{
  4045. + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
  4046. + int i;
  4047. + ipkg_error_t err;
  4048. + abstract_pkg_t *ppkg ;
  4049. +
  4050. + if (providers == NULL)
  4051. + return IPKG_PKG_HAS_NO_CANDIDATE;
  4052. +
  4053. + for (i = 0; i < providers->len; i++) {
  4054. + ppkg = abstract_pkg_vec_get(providers, i);
  4055. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
  4056. + err = ipkg_install_by_name(conf, ppkg->name);
  4057. + if (err)
  4058. + return err;
  4059. +/* XXX Maybe ppkg should be freed ? */
  4060. + }
  4061. + return 0;
  4062. +}
  4063. +
  4064. +/*
  4065. + * Walk dependence graph starting with pkg, collect packages to be
  4066. + * installed into pkgs_needed, in dependence order.
  4067. + */
  4068. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
  4069. +{
  4070. + int i, err;
  4071. + pkg_vec_t *depends = pkg_vec_alloc();
  4072. + char **unresolved = NULL;
  4073. + int ndepends;
  4074. +
  4075. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  4076. + pkg, depends,
  4077. + &unresolved);
  4078. +
  4079. + if (unresolved) {
  4080. + ipkg_message(conf, IPKG_ERROR,
  4081. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  4082. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  4083. + while (*unresolved) {
  4084. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  4085. + unresolved++;
  4086. + }
  4087. + ipkg_message(conf, IPKG_ERROR, "\n");
  4088. + if (! conf->force_depends) {
  4089. + ipkg_message(conf, IPKG_INFO,
  4090. + "This could mean that your package list is out of date or that the packages\n"
  4091. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4092. + "of this problem try again with the '-force-depends' option.\n");
  4093. + pkg_vec_free(depends);
  4094. + return IPKG_PKG_DEPS_UNSATISFIED;
  4095. + }
  4096. + }
  4097. +
  4098. + if (ndepends <= 0) {
  4099. + pkg_vec_free(depends);
  4100. + return 0;
  4101. + }
  4102. +
  4103. + for (i = 0; i < depends->len; i++) {
  4104. + pkg_t *dep = depends->pkgs[i];
  4105. + /* The package was uninstalled when we started, but another
  4106. + dep earlier in this loop may have depended on it and pulled
  4107. + it in, so check first. */
  4108. + if ((dep->state_status != SS_INSTALLED)
  4109. + && (dep->state_status != SS_UNPACKED)
  4110. + && (dep->state_want != SW_INSTALL)) {
  4111. +
  4112. + /* Mark packages as to-be-installed */
  4113. + dep->state_want = SW_INSTALL;
  4114. +
  4115. + /* Dependencies should be installed the same place as pkg */
  4116. + if (dep->dest == NULL) {
  4117. + dep->dest = pkg->dest;
  4118. + }
  4119. +
  4120. + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
  4121. + if (err) {
  4122. + pkg_vec_free(depends);
  4123. + return err;
  4124. + }
  4125. + }
  4126. + }
  4127. + if (pkgs_needed)
  4128. + pkg_vec_insert(pkgs_needed, pkg);
  4129. +
  4130. + pkg_vec_free(depends);
  4131. +
  4132. + return 0;
  4133. +}
  4134. +
  4135. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
  4136. +{
  4137. + int cmp;
  4138. + pkg_t *old, *new;
  4139. + char *old_version, *new_version;
  4140. +
  4141. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  4142. +
  4143. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  4144. + if (new == NULL) {
  4145. + return IPKG_PKG_HAS_NO_CANDIDATE;
  4146. + }
  4147. + if (old) {
  4148. + old_version = pkg_version_str_alloc(old);
  4149. + new_version = pkg_version_str_alloc(new);
  4150. +
  4151. + cmp = pkg_compare_versions(old, new);
  4152. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4153. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
  4154. + cmp = -1 ; /* then we force ipkg to downgrade */
  4155. + /* We need to use a value < 0 because in the 0 case we are asking to */
  4156. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4157. + }
  4158. + ipkg_message(conf, IPKG_DEBUG,
  4159. + "comparing visible versions of pkg %s:"
  4160. + "\n\t%s is installed "
  4161. + "\n\t%s is available "
  4162. + "\n\t%d was comparison result\n",
  4163. + pkg_name, old_version, new_version, cmp);
  4164. + if (cmp == 0 && !conf->force_reinstall) {
  4165. + ipkg_message(conf, IPKG_NOTICE,
  4166. + "Package %s (%s) installed in %s is up to date.\n",
  4167. + old->name, old_version, old->dest->name);
  4168. + free(old_version);
  4169. + free(new_version);
  4170. + return 0;
  4171. + } else if (cmp > 0) {
  4172. + ipkg_message(conf, IPKG_NOTICE,
  4173. + "Not downgrading package %s on %s from %s to %s.\n",
  4174. + old->name, old->dest->name, old_version, new_version);
  4175. + free(old_version);
  4176. + free(new_version);
  4177. + return 0;
  4178. + } else if (cmp < 0) {
  4179. + new->dest = old->dest;
  4180. + old->state_want = SW_DEINSTALL;
  4181. + old->state_flag |= SF_OBSOLETE;
  4182. + }
  4183. + }
  4184. + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
  4185. +}
  4186. +
  4187. +
  4188. +
  4189. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
  4190. +{
  4191. + int i, err;
  4192. + pkg_vec_t *depends = pkg_vec_alloc();
  4193. + pkg_t *dep;
  4194. + char **unresolved = NULL;
  4195. + int ndepends;
  4196. +
  4197. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  4198. + pkg, depends,
  4199. + &unresolved);
  4200. +
  4201. + if (unresolved) {
  4202. + ipkg_message(conf, IPKG_ERROR,
  4203. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  4204. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  4205. + while (*unresolved) {
  4206. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  4207. + unresolved++;
  4208. + }
  4209. + ipkg_message(conf, IPKG_ERROR, "\n");
  4210. + if (! conf->force_depends) {
  4211. + ipkg_message(conf, IPKG_INFO,
  4212. + "This could mean that your package list is out of date or that the packages\n"
  4213. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4214. + "of this problem try again with the '-force-depends' option.\n");
  4215. + pkg_vec_free(depends);
  4216. + return IPKG_PKG_DEPS_UNSATISFIED;
  4217. + }
  4218. + }
  4219. +
  4220. + if (ndepends <= 0) {
  4221. + return 0;
  4222. + }
  4223. +
  4224. + /* Mark packages as to-be-installed */
  4225. + for (i=0; i < depends->len; i++) {
  4226. + /* Dependencies should be installed the same place as pkg */
  4227. + if (depends->pkgs[i]->dest == NULL) {
  4228. + depends->pkgs[i]->dest = pkg->dest;
  4229. + }
  4230. + depends->pkgs[i]->state_want = SW_INSTALL;
  4231. + }
  4232. +
  4233. + for (i = 0; i < depends->len; i++) {
  4234. + dep = depends->pkgs[i];
  4235. + /* The package was uninstalled when we started, but another
  4236. + dep earlier in this loop may have depended on it and pulled
  4237. + it in, so check first. */
  4238. + if ((dep->state_status != SS_INSTALLED)
  4239. + && (dep->state_status != SS_UNPACKED)) {
  4240. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4241. + err = ipkg_install_pkg(conf, dep,0);
  4242. + if (err) {
  4243. + pkg_vec_free(depends);
  4244. + return err;
  4245. + }
  4246. + }
  4247. + }
  4248. +
  4249. + pkg_vec_free(depends);
  4250. +
  4251. + return 0;
  4252. +}
  4253. +
  4254. +
  4255. +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
  4256. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
  4257. +{
  4258. + if (conf->nodeps == 0) {
  4259. + int i;
  4260. + pkg_vec_t *installed = pkg_vec_alloc();
  4261. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  4262. + for (i = 0; i < installed->len; i++) {
  4263. + pkg_t *pkg = installed->pkgs[i];
  4264. + satisfy_dependencies_for(conf, pkg);
  4265. + }
  4266. + pkg_vec_free(installed);
  4267. + }
  4268. + return 0;
  4269. +}
  4270. +
  4271. +
  4272. +
  4273. +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
  4274. +{
  4275. + int i;
  4276. + pkg_vec_t *conflicts = NULL;
  4277. + int level;
  4278. + const char *prefix;
  4279. + if (conf->force_depends) {
  4280. + level = IPKG_NOTICE;
  4281. + prefix = "Warning";
  4282. + } else {
  4283. + level = IPKG_ERROR;
  4284. + prefix = "ERROR";
  4285. + }
  4286. +
  4287. + if (!conf->force_depends)
  4288. + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(pkg);
  4289. +
  4290. + if (conflicts) {
  4291. + ipkg_message(conf, level,
  4292. + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
  4293. + i = 0;
  4294. + while (i < conflicts->len)
  4295. + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
  4296. + ipkg_message(conf, level, "\n");
  4297. + pkg_vec_free(conflicts);
  4298. + return IPKG_PKG_DEPS_UNSATISFIED;
  4299. + }
  4300. + return 0;
  4301. +}
  4302. +
  4303. +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
  4304. +{
  4305. + str_list_t *new_list = pkg_get_installed_files(new_pkg);
  4306. + str_list_elt_t *iter;
  4307. +
  4308. + for (iter = new_list->head; iter; iter = iter->next) {
  4309. + char *new_file = iter->data;
  4310. + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
  4311. + if (!new_file)
  4312. + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
  4313. + if (!owner || (owner == old_pkg))
  4314. + file_hash_set_file_owner(conf, new_file, new_pkg);
  4315. + }
  4316. + if (old_pkg) {
  4317. + str_list_t *old_list = pkg_get_installed_files(old_pkg);
  4318. + for (iter = old_list->head; iter; iter = iter->next) {
  4319. + char *old_file = iter->data;
  4320. + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
  4321. + if (owner == old_pkg) {
  4322. + /* obsolete */
  4323. + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
  4324. + }
  4325. + }
  4326. + }
  4327. + return 0;
  4328. +}
  4329. +
  4330. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
  4331. +{
  4332. + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
  4333. +
  4334. + /* sma 6.20.02: yup; here's the first bit */
  4335. + /*
  4336. + * XXX: BUG easy for cworth
  4337. + * 1) please point the call below to the correct current root destination
  4338. + * 2) we need to resolve how to check the required space for a pending pkg,
  4339. + * my diddling with the .ipk file size below isn't going to cut it.
  4340. + * 3) return a proper error code instead of 1
  4341. + */
  4342. + int comp_size, blocks_available;
  4343. +
  4344. + if (!conf->force_space && pkg->installed_size != NULL) {
  4345. + blocks_available = get_available_blocks(conf->default_dest->root_dir);
  4346. +
  4347. + comp_size = strtoul(pkg->installed_size, NULL, 0);
  4348. + /* round up a blocks count without doing fancy-but-slow casting jazz */
  4349. + comp_size = (int)((comp_size + 1023) / 1024);
  4350. +
  4351. + if (comp_size >= blocks_available) {
  4352. + ipkg_message(conf, IPKG_ERROR,
  4353. + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
  4354. + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
  4355. + return ENOSPC;
  4356. + }
  4357. + }
  4358. + return 0;
  4359. +}
  4360. +
  4361. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
  4362. +{
  4363. + int err;
  4364. + char *conffiles_file_name;
  4365. + char *root_dir;
  4366. + FILE *conffiles_file;
  4367. +
  4368. + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
  4369. +
  4370. + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
  4371. + if (pkg->tmp_unpack_dir == NULL) {
  4372. + ipkg_message(conf, IPKG_ERROR,
  4373. + "%s: Failed to create temporary directory '%s': %s\n",
  4374. + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
  4375. + return errno;
  4376. + }
  4377. +
  4378. + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
  4379. + if (err) {
  4380. + return err;
  4381. + }
  4382. +
  4383. + /* XXX: CLEANUP: There might be a cleaner place to read in the
  4384. + conffiles. Seems like I should be able to get everything to go
  4385. + through pkg_init_from_file. If so, maybe it would make sense to
  4386. + move all of unpack_pkg_control_files to that function. */
  4387. +
  4388. + /* Don't need to re-read conffiles if we already have it */
  4389. + if (pkg->conffiles.head) {
  4390. + return 0;
  4391. + }
  4392. +
  4393. + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
  4394. + if (! file_exists(conffiles_file_name)) {
  4395. + free(conffiles_file_name);
  4396. + return 0;
  4397. + }
  4398. +
  4399. + conffiles_file = fopen(conffiles_file_name, "r");
  4400. + if (conffiles_file == NULL) {
  4401. + fprintf(stderr, "%s: failed to open %s: %s\n",
  4402. + __FUNCTION__, conffiles_file_name, strerror(errno));
  4403. + free(conffiles_file_name);
  4404. + return errno;
  4405. + }
  4406. + free(conffiles_file_name);
  4407. +
  4408. + while (1) {
  4409. + char *cf_name;
  4410. + char *cf_name_in_dest;
  4411. +
  4412. + cf_name = file_read_line_alloc(conffiles_file);
  4413. + if (cf_name == NULL) {
  4414. + break;
  4415. + }
  4416. + str_chomp(cf_name);
  4417. + if (cf_name[0] == '\0') {
  4418. + continue;
  4419. + }
  4420. +
  4421. + /* Prepend dest->root_dir to conffile name.
  4422. + Take pains to avoid multiple slashes. */
  4423. + root_dir = pkg->dest->root_dir;
  4424. + if (conf->offline_root)
  4425. + /* skip the offline_root prefix */
  4426. + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
  4427. + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
  4428. + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
  4429. +
  4430. + /* Can't get an md5sum now, (file isn't extracted yet).
  4431. + We'll wait until resolve_conffiles */
  4432. + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
  4433. +
  4434. + free(cf_name);
  4435. + free(cf_name_in_dest);
  4436. + }
  4437. +
  4438. + fclose(conffiles_file);
  4439. +
  4440. + return 0;
  4441. +}
  4442. +
  4443. +/* returns number of installed replacees */
  4444. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees)
  4445. +{
  4446. + abstract_pkg_t **replaces = pkg->replaces;
  4447. + int replaces_count = pkg->replaces_count;
  4448. + int i, j;
  4449. + for (i = 0; i < replaces_count; i++) {
  4450. + abstract_pkg_t *ab_pkg = replaces[i];
  4451. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  4452. + if (pkg_vec) {
  4453. + for (j = 0; j < pkg_vec->len; j++) {
  4454. + pkg_t *replacee = pkg_vec->pkgs[j];
  4455. + if (!pkg_conflicts(pkg, replacee))
  4456. + continue;
  4457. + if (replacee->state_status == SS_INSTALLED) {
  4458. + pkg_vec_insert(installed_replacees, replacee);
  4459. + }
  4460. + }
  4461. + }
  4462. + }
  4463. + return installed_replacees->len;
  4464. +}
  4465. +
  4466. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4467. +{
  4468. + int i;
  4469. + int replaces_count = replacees->len;
  4470. + for (i = 0; i < replaces_count; i++) {
  4471. + pkg_t *replacee = replacees->pkgs[i];
  4472. + int err;
  4473. + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
  4474. + err = ipkg_remove_pkg(conf, replacee,0);
  4475. + if (err)
  4476. + return err;
  4477. + }
  4478. + return 0;
  4479. +}
  4480. +
  4481. +/* to unwind the removal: make sure they are installed */
  4482. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4483. +{
  4484. + int i, err;
  4485. + int replaces_count = replacees->len;
  4486. + for (i = 0; i < replaces_count; i++) {
  4487. + pkg_t *replacee = replacees->pkgs[i];
  4488. + if (replacee->state_status != SS_INSTALLED) {
  4489. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4490. + err = ipkg_install_pkg(conf, replacee,0);
  4491. + if (err)
  4492. + return err;
  4493. + }
  4494. + }
  4495. + return 0;
  4496. +}
  4497. +
  4498. +int caught_sigint = 0;
  4499. +static void ipkg_install_pkg_sigint_handler(int sig)
  4500. +{
  4501. + caught_sigint = sig;
  4502. +}
  4503. +
  4504. +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
  4505. +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
  4506. +{
  4507. + if (old_pkg) {
  4508. + char message_out[15];
  4509. + char *old_version = pkg_version_str_alloc(old_pkg);
  4510. + char *new_version = pkg_version_str_alloc(pkg);
  4511. + int cmp = pkg_compare_versions(old_pkg, pkg);
  4512. + int rc = 0;
  4513. +
  4514. + memset(message_out,'\x0',15);
  4515. + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
  4516. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4517. + cmp = -1 ; /* then we force ipkg to downgrade */
  4518. + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
  4519. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4520. + }
  4521. +
  4522. + if (cmp > 0) {
  4523. + ipkg_message(conf, IPKG_NOTICE,
  4524. + "Not downgrading package %s on %s from %s to %s.\n",
  4525. + old_pkg->name, old_pkg->dest->name, old_version, new_version);
  4526. + rc = 1;
  4527. + } else if (cmp < 0) {
  4528. + ipkg_message(conf, IPKG_NOTICE,
  4529. + "%s%s on %s from %s to %s...\n",
  4530. + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
  4531. + pkg->dest = old_pkg->dest;
  4532. + rc = 0;
  4533. + } else /* cmp == 0 */ {
  4534. + if (conf->force_reinstall) {
  4535. + ipkg_message(conf, IPKG_NOTICE,
  4536. + "Reinstalling %s (%s) on %s...\n",
  4537. + pkg->name, new_version, old_pkg->dest->name);
  4538. + pkg->dest = old_pkg->dest;
  4539. + rc = 0;
  4540. + } else {
  4541. + ipkg_message(conf, IPKG_NOTICE,
  4542. + "Not installing %s (%s) on %s -- already installed.\n",
  4543. + pkg->name, new_version, old_pkg->dest->name);
  4544. + rc = 1;
  4545. + }
  4546. + }
  4547. + free(old_version);
  4548. + free(new_version);
  4549. + return rc;
  4550. + } else {
  4551. + char message_out[15], *version ;
  4552. + memset(message_out,'\x0',15);
  4553. + if ( message )
  4554. + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
  4555. + else
  4556. + strncpy( message_out,"Installing ",strlen("Installing ") );
  4557. + version = pkg_version_str_alloc(pkg);
  4558. +
  4559. + ipkg_message(conf, IPKG_NOTICE,
  4560. + "%s%s (%s) to %s...\n", message_out,
  4561. + pkg->name, version, pkg->dest->name);
  4562. + free(version);
  4563. + return 0;
  4564. + }
  4565. +}
  4566. +
  4567. +/* and now the meat... */
  4568. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
  4569. +{
  4570. + int err = 0;
  4571. + int message = 0;
  4572. + pkg_t *old_pkg = NULL;
  4573. + pkg_vec_t *replacees;
  4574. + abstract_pkg_t *ab_pkg = NULL;
  4575. + int old_state_flag;
  4576. + uint8_t *file_md5;
  4577. +
  4578. +
  4579. + if ( from_upgrade )
  4580. + message = 1; /* Coming from an upgrade, and should change the output message */
  4581. +
  4582. + if (!pkg) {
  4583. + ipkg_message(conf, IPKG_ERROR,
  4584. + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
  4585. + return -EINVAL;
  4586. + }
  4587. +
  4588. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
  4589. +
  4590. + if (!pkg_arch_supported(conf, pkg)) {
  4591. + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
  4592. + pkg->architecture, pkg->name);
  4593. + return -EINVAL;
  4594. + }
  4595. + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
  4596. + err = satisfy_dependencies_for(conf, pkg);
  4597. + if (err) { return err; }
  4598. +
  4599. + ipkg_message(conf, IPKG_NOTICE,
  4600. + "Package %s is already installed in %s.\n",
  4601. + pkg->name, pkg->dest->name);
  4602. + return 0;
  4603. + }
  4604. +
  4605. + if (pkg->dest == NULL) {
  4606. + pkg->dest = conf->default_dest;
  4607. + }
  4608. +
  4609. + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  4610. +
  4611. + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
  4612. + if (err) { return err; }
  4613. +
  4614. + pkg->state_want = SW_INSTALL;
  4615. + if (old_pkg){
  4616. + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
  4617. + }
  4618. +
  4619. +
  4620. + /* Abhaya: conflicts check */
  4621. + err = check_conflicts_for(conf, pkg);
  4622. + if (err) { return err; }
  4623. +
  4624. + /* this setup is to remove the upgrade scenario in the end when
  4625. + installing pkg A, A deps B & B deps on A. So both B and A are
  4626. + installed. Then A's installation is started resulting in an
  4627. + uncecessary upgrade */
  4628. + if (pkg->state_status == SS_INSTALLED
  4629. + && conf->force_reinstall == 0) return 0;
  4630. +
  4631. + err = verify_pkg_installable(conf, pkg);
  4632. + if (err) { return err; }
  4633. +
  4634. + if (pkg->local_filename == NULL) {
  4635. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  4636. + if (err) {
  4637. + ipkg_message(conf, IPKG_ERROR,
  4638. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  4639. + pkg->name);
  4640. + return err;
  4641. + }
  4642. + }
  4643. +
  4644. +/* Check for md5 values */
  4645. + if (pkg->md5sum)
  4646. + {
  4647. + file_md5 = file_md5sum_alloc(pkg->local_filename);
  4648. + if (strcmp((char *)file_md5, pkg->md5sum))
  4649. + {
  4650. + ipkg_message(conf, IPKG_ERROR,
  4651. + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
  4652. + pkg->name);
  4653. + free(file_md5);
  4654. + return err;
  4655. + }
  4656. + free(file_md5);
  4657. + }
  4658. +
  4659. + if (pkg->tmp_unpack_dir == NULL) {
  4660. + unpack_pkg_control_files(conf, pkg);
  4661. + }
  4662. +
  4663. + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
  4664. +/* Pigi: check if it will pass from here when replacing. It seems to fail */
  4665. +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
  4666. + err = update_file_ownership(conf, pkg, old_pkg);
  4667. + if (err) { return err; }
  4668. +
  4669. + if (conf->nodeps == 0) {
  4670. + err = satisfy_dependencies_for(conf, pkg);
  4671. + if (err) { return err; }
  4672. + }
  4673. +
  4674. + replacees = pkg_vec_alloc();
  4675. + pkg_get_installed_replacees(pkg, replacees);
  4676. +
  4677. + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
  4678. + {
  4679. + sigset_t newset, oldset;
  4680. + sighandler_t old_handler = NULL;
  4681. + int use_signal = 0;
  4682. + caught_sigint = 0;
  4683. + if (use_signal) {
  4684. + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
  4685. + } else {
  4686. + sigemptyset(&newset);
  4687. + sigaddset(&newset, SIGINT);
  4688. + sigprocmask(SIG_BLOCK, &newset, &oldset);
  4689. + }
  4690. +
  4691. + ipkg_state_changed++;
  4692. + pkg->state_flag |= SF_FILELIST_CHANGED;
  4693. +
  4694. + /* XXX: BUG: we really should treat replacement more like an upgrade
  4695. + * Instead, we're going to remove the replacees
  4696. + */
  4697. + err = pkg_remove_installed_replacees(conf, replacees);
  4698. + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
  4699. +
  4700. + /*
  4701. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  4702. + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
  4703. +
  4704. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  4705. + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
  4706. + */
  4707. +
  4708. + err = preinst_configure(conf, pkg, old_pkg);
  4709. + /*
  4710. + if (err) goto UNWIND_PREINST_CONFIGURE;
  4711. + */
  4712. +
  4713. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  4714. + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
  4715. +
  4716. + err = check_data_file_clashes(conf, pkg, old_pkg);
  4717. + /*
  4718. + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
  4719. +
  4720. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  4721. + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
  4722. + */
  4723. +
  4724. + if (conf->noaction) return 0;
  4725. +
  4726. + /* point of no return: no unwinding after this */
  4727. + if (old_pkg && !conf->force_reinstall) {
  4728. + old_pkg->state_want = SW_DEINSTALL;
  4729. +
  4730. + if (old_pkg->state_flag & SF_NOPRUNE) {
  4731. + ipkg_message(conf, IPKG_INFO,
  4732. + " not removing obsolesced files because package marked noprune\n");
  4733. + } else {
  4734. + ipkg_message(conf, IPKG_INFO,
  4735. + " removing obsolesced files\n");
  4736. + remove_obsolesced_files(conf, pkg, old_pkg);
  4737. + }
  4738. + /* removing files from old package, to avoid ghost files */
  4739. + remove_data_files_and_list(conf, old_pkg);
  4740. +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
  4741. + remove_maintainer_scripts_except_postrm(conf, old_pkg);
  4742. + remove_postrm(conf, old_pkg);
  4743. +/* Pigi */
  4744. +
  4745. + }
  4746. +
  4747. +
  4748. + ipkg_message(conf, IPKG_INFO,
  4749. + " installing maintainer scripts\n");
  4750. + install_maintainer_scripts(conf, pkg, old_pkg);
  4751. +
  4752. + /* the following just returns 0
  4753. + remove_disappeared(conf, pkg);
  4754. + */
  4755. +
  4756. + ipkg_message(conf, IPKG_INFO,
  4757. + " installing data files\n");
  4758. + install_data_files(conf, pkg);
  4759. +
  4760. +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
  4761. + err = check_data_file_clashes_change(conf, pkg);
  4762. +
  4763. + ipkg_message(conf, IPKG_INFO,
  4764. + " resolving conf files\n");
  4765. + resolve_conffiles(conf, pkg);
  4766. +
  4767. + pkg->state_status = SS_UNPACKED;
  4768. + old_state_flag = pkg->state_flag;
  4769. + pkg->state_flag &= ~SF_PREFER;
  4770. + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
  4771. +
  4772. + if (old_pkg && !conf->force_reinstall) {
  4773. + old_pkg->state_status = SS_NOT_INSTALLED;
  4774. + }
  4775. +
  4776. + time(&pkg->installed_time);
  4777. +
  4778. + ipkg_message(conf, IPKG_INFO,
  4779. + " cleanup temp files\n");
  4780. + cleanup_temporary_files(conf, pkg);
  4781. +
  4782. + ab_pkg = pkg->parent;
  4783. + if (ab_pkg)
  4784. + ab_pkg->state_status = pkg->state_status;
  4785. +
  4786. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  4787. +
  4788. + if (use_signal)
  4789. + signal(SIGINT, old_handler);
  4790. + else
  4791. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4792. +
  4793. + return 0;
  4794. +
  4795. +
  4796. + /*
  4797. + UNWIND_POSTRM_UPGRADE_OLD_PKG:
  4798. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4799. + UNWIND_CHECK_DATA_FILE_CLASHES:
  4800. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  4801. + */
  4802. + UNWIND_BACKUP_MODIFIED_CONFFILES:
  4803. + backup_modified_conffiles_unwind(pkg, old_pkg);
  4804. + /*
  4805. + UNWIND_PREINST_CONFIGURE:
  4806. + preinst_configure_unwind(conf, pkg, old_pkg);
  4807. + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
  4808. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  4809. + UNWIND_PRERM_UPGRADE_OLD_PKG:
  4810. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4811. + */
  4812. + UNWIND_REMOVE_INSTALLED_REPLACEES:
  4813. + pkg_remove_installed_replacees_unwind(conf, replacees);
  4814. +
  4815. + ipkg_message(conf, IPKG_INFO,
  4816. + " cleanup temp files\n");
  4817. + cleanup_temporary_files(conf, pkg);
  4818. +
  4819. + ipkg_message(conf, IPKG_INFO,
  4820. + "Failed.\n");
  4821. + if (use_signal)
  4822. + signal(SIGINT, old_handler);
  4823. + else
  4824. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4825. +
  4826. + return err;
  4827. + }
  4828. +}
  4829. +
  4830. +/*
  4831. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4832. +{
  4833. + DPKG_INCOMPATIBILITY:
  4834. + dpkg does some things here that we don't do yet. Do we care?
  4835. +
  4836. + 1. If a version of the package is already installed, call
  4837. + old-prerm upgrade new-version
  4838. + 2. If the script runs but exits with a non-zero exit status
  4839. + new-prerm failed-upgrade old-version
  4840. + Error unwind, for both the above cases:
  4841. + old-postinst abort-upgrade new-version
  4842. + return 0;
  4843. +}
  4844. +*/
  4845. +
  4846. +/*
  4847. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4848. +{
  4849. + DPKG_INCOMPATIBILITY:
  4850. + dpkg does some things here that we don't do yet. Do we care?
  4851. + (See prerm_upgrade_old_package for details)
  4852. +
  4853. + return 0;
  4854. +}
  4855. +*/
  4856. +
  4857. +/*
  4858. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4859. +{
  4860. + DPKG_INCOMPATIBILITY:
  4861. + dpkg does some things here that we don't do yet. Do we care?
  4862. + 2. If a 'conflicting' package is being removed at the same time:
  4863. + 1. If any packages depended on that conflicting package and
  4864. + --auto-deconfigure is specified, call, for each such package:
  4865. + deconfigured's-prerm deconfigure \
  4866. + in-favour package-being-installed version \
  4867. + removing conflicting-package version
  4868. + Error unwind:
  4869. + deconfigured's-postinst abort-deconfigure \
  4870. + in-favour package-being-installed-but-failed version \
  4871. + removing conflicting-package version
  4872. +
  4873. + The deconfigured packages are marked as requiring
  4874. + configuration, so that if --install is used they will be
  4875. + configured again if possible.
  4876. + 2. To prepare for removal of the conflicting package, call:
  4877. + conflictor's-prerm remove in-favour package new-version
  4878. + Error unwind:
  4879. + conflictor's-postinst abort-remove in-favour package new-version
  4880. + return 0;
  4881. +}
  4882. +*/
  4883. +
  4884. +/*
  4885. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4886. +{
  4887. + DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
  4888. + do yet. Do we care? (See prerm_deconfigure_conflictors for
  4889. + details)
  4890. + return 0;
  4891. +}
  4892. +*/
  4893. +
  4894. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4895. +{
  4896. + int err;
  4897. + char *preinst_args;
  4898. +
  4899. + if (old_pkg) {
  4900. + char *old_version = pkg_version_str_alloc(old_pkg);
  4901. + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
  4902. + free(old_version);
  4903. + } else if (pkg->state_status == SS_CONFIG_FILES) {
  4904. + char *pkg_version = pkg_version_str_alloc(pkg);
  4905. + sprintf_alloc(&preinst_args, "install %s", pkg_version);
  4906. + free(pkg_version);
  4907. + } else {
  4908. + preinst_args = strdup("install");
  4909. + }
  4910. +
  4911. + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
  4912. + if (err) {
  4913. + ipkg_message(conf, IPKG_ERROR,
  4914. + "Aborting installation of %s\n", pkg->name);
  4915. + return 1;
  4916. + }
  4917. +
  4918. + free(preinst_args);
  4919. +
  4920. + return 0;
  4921. +}
  4922. +
  4923. +/*
  4924. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4925. +{
  4926. + DPKG_INCOMPATIBILITY:
  4927. + dpkg does the following error unwind, should we?
  4928. + pkg->postrm abort-upgrade old-version
  4929. + OR pkg->postrm abort-install old-version
  4930. + OR pkg->postrm abort-install
  4931. + return 0;
  4932. +}
  4933. +*/
  4934. +
  4935. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4936. +{
  4937. + int err;
  4938. + conffile_list_elt_t *iter;
  4939. + conffile_t *cf;
  4940. +
  4941. + if (conf->noaction) return 0;
  4942. +
  4943. + /* Backup all modified conffiles */
  4944. + if (old_pkg) {
  4945. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4946. + char *cf_name;
  4947. +
  4948. + cf = iter->data;
  4949. + cf_name = root_filename_alloc(conf, cf->name);
  4950. +
  4951. + /* Don't worry if the conffile is just plain gone */
  4952. + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
  4953. + err = backup_make_backup(conf, cf_name);
  4954. + if (err) {
  4955. + return err;
  4956. + }
  4957. + }
  4958. + free(cf_name);
  4959. + }
  4960. + }
  4961. +
  4962. + /* Backup all conffiles that were not conffiles in old_pkg */
  4963. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4964. + char *cf_name;
  4965. + cf = iter->data;
  4966. + cf_name = root_filename_alloc(conf, cf->name);
  4967. + /* Ignore if this was a conffile in old_pkg as well */
  4968. + if (pkg_get_conffile(old_pkg, cf->name)) {
  4969. + continue;
  4970. + }
  4971. +
  4972. + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
  4973. + err = backup_make_backup(conf, cf_name);
  4974. + if (err) {
  4975. + return err;
  4976. + }
  4977. + }
  4978. + free(cf_name);
  4979. + }
  4980. +
  4981. + return 0;
  4982. +}
  4983. +
  4984. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg)
  4985. +{
  4986. + conffile_list_elt_t *iter;
  4987. +
  4988. + if (old_pkg) {
  4989. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4990. + backup_remove(iter->data->name);
  4991. + }
  4992. + }
  4993. +
  4994. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4995. + backup_remove(iter->data->name);
  4996. + }
  4997. +
  4998. + return 0;
  4999. +}
  5000. +
  5001. +
  5002. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5003. +{
  5004. + /* DPKG_INCOMPATIBILITY:
  5005. + ipkg takes a slightly different approach than dpkg at this
  5006. + point. dpkg installs each file in the new package while
  5007. + creating a backup for any file that is replaced, (so that it
  5008. + can unwind if necessary). To avoid complexity and redundant
  5009. + storage, ipkg doesn't do any installation until later, (at the
  5010. + point at which dpkg removes the backups.
  5011. +
  5012. + But, we do have to check for data file clashes, since after
  5013. + installing a package with a file clash, removing either of the
  5014. + packages involved in the clash has the potential to break the
  5015. + other package.
  5016. + */
  5017. + str_list_t *files_list;
  5018. + str_list_elt_t *iter;
  5019. +
  5020. + int clashes = 0;
  5021. +
  5022. + files_list = pkg_get_installed_files(pkg);
  5023. + for (iter = files_list->head; iter; iter = iter->next) {
  5024. + char *root_filename;
  5025. + char *filename = iter->data;
  5026. + root_filename = root_filename_alloc(conf, filename);
  5027. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  5028. + pkg_t *owner;
  5029. + pkg_t *obs;
  5030. + /* Pre-existing conffiles are OK */
  5031. + /* @@@@ should have way to check that it is a conffile -Jamey */
  5032. + if (backup_exists_for(root_filename)) {
  5033. + continue;
  5034. + }
  5035. +
  5036. + /* Pre-existing files are OK if force-overwrite was asserted. */
  5037. + if (conf->force_overwrite) {
  5038. + /* but we need to change who owns this file */
  5039. + file_hash_set_file_owner(conf, filename, pkg);
  5040. + continue;
  5041. + }
  5042. +
  5043. + owner = file_hash_get_file_owner(conf, filename);
  5044. +
  5045. + /* Pre-existing files are OK if owned by the pkg being upgraded. */
  5046. + if (owner && old_pkg) {
  5047. + if (strcmp(owner->name, old_pkg->name) == 0) {
  5048. + continue;
  5049. + }
  5050. + }
  5051. +
  5052. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  5053. + if (owner) {
  5054. + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
  5055. + if (pkg_replaces(pkg, owner)) {
  5056. + continue;
  5057. + }
  5058. +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
  5059. + then it's ok to overwrite. */
  5060. + if (strcmp(owner->name,pkg->name)==0){
  5061. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  5062. + continue;
  5063. + }
  5064. + }
  5065. +
  5066. + /* Pre-existing files are OK if they are obsolete */
  5067. + obs = hash_table_get(&conf->obs_file_hash, filename);
  5068. + if (obs) {
  5069. + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
  5070. + continue;
  5071. + }
  5072. +
  5073. + /* We have found a clash. */
  5074. + ipkg_message(conf, IPKG_ERROR,
  5075. + "Package %s wants to install file %s\n"
  5076. + "\tBut that file is already provided by package ",
  5077. + pkg->name, filename);
  5078. + if (owner) {
  5079. + ipkg_message(conf, IPKG_ERROR,
  5080. + "%s\n", owner->name);
  5081. + } else {
  5082. + ipkg_message(conf, IPKG_ERROR,
  5083. + "<no package>\nPlease move this file out of the way and try again.\n");
  5084. + }
  5085. + clashes++;
  5086. + }
  5087. + free(root_filename);
  5088. + }
  5089. + pkg_free_installed_files(pkg);
  5090. +
  5091. + return clashes;
  5092. +}
  5093. +
  5094. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg)
  5095. +{
  5096. + /* Basically that's the worst hack I could do to be able to change ownership of
  5097. + file list, but, being that we have no way to unwind the mods, due to structure
  5098. + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
  5099. + What we do here is change the ownership of file in hash if a replace ( or similar events
  5100. + happens )
  5101. + Only the action that are needed to change name should be considered.
  5102. + @@@ To change after 1.0 release.
  5103. + */
  5104. + str_list_t *files_list;
  5105. + str_list_elt_t *iter;
  5106. +
  5107. + int clashes = 0;
  5108. +
  5109. + files_list = pkg_get_installed_files(pkg);
  5110. + for (iter = files_list->head; iter; iter = iter->next) {
  5111. + char *root_filename;
  5112. + char *filename = iter->data;
  5113. + root_filename = root_filename_alloc(conf, filename);
  5114. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  5115. + pkg_t *owner;
  5116. +
  5117. + if (conf->force_overwrite) {
  5118. + /* but we need to change who owns this file */
  5119. + file_hash_set_file_owner(conf, filename, pkg);
  5120. + continue;
  5121. + }
  5122. +
  5123. + owner = file_hash_get_file_owner(conf, filename);
  5124. +
  5125. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  5126. + if (owner) {
  5127. + if (pkg_replaces(pkg, owner)) {
  5128. +/* It's now time to change the owner of that file.
  5129. + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
  5130. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  5131. + file_hash_set_file_owner(conf, filename, pkg);
  5132. + continue;
  5133. + }
  5134. + }
  5135. +
  5136. + }
  5137. + free(root_filename);
  5138. + }
  5139. + pkg_free_installed_files(pkg);
  5140. +
  5141. + return clashes;
  5142. +}
  5143. +
  5144. +/*
  5145. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5146. +{
  5147. + Nothing to do since check_data_file_clashes doesn't change state
  5148. + return 0;
  5149. +}
  5150. +*/
  5151. +
  5152. +/*
  5153. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5154. +{
  5155. + DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
  5156. + 1. If the package is being upgraded, call
  5157. + old-postrm upgrade new-version
  5158. + 2. If this fails, attempt:
  5159. + new-postrm failed-upgrade old-version
  5160. + Error unwind, for both cases:
  5161. + old-preinst abort-upgrade new-version
  5162. + return 0;
  5163. +}
  5164. +*/
  5165. +
  5166. +/*
  5167. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5168. +{
  5169. + DPKG_INCOMPATIBILITY:
  5170. + dpkg does some things here that we don't do yet. Do we care?
  5171. + (See postrm_upgrade_old_pkg for details)
  5172. + return 0;
  5173. +}
  5174. +*/
  5175. +
  5176. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5177. +{
  5178. + int err;
  5179. + str_list_t *old_files;
  5180. + str_list_elt_t *of;
  5181. + str_list_t *new_files;
  5182. + str_list_elt_t *nf;
  5183. +
  5184. + if (old_pkg == NULL) {
  5185. + return 0;
  5186. + }
  5187. +
  5188. + old_files = pkg_get_installed_files(old_pkg);
  5189. + new_files = pkg_get_installed_files(pkg);
  5190. +
  5191. + for (of = old_files->head; of; of = of->next) {
  5192. + pkg_t *owner;
  5193. + char *old, *new;
  5194. + old = of->data;
  5195. + for (nf = new_files->head; nf; nf = nf->next) {
  5196. + new = nf->data;
  5197. + if (strcmp(old, new) == 0) {
  5198. + goto NOT_OBSOLETE;
  5199. + }
  5200. + }
  5201. + if (file_is_dir(old)) {
  5202. + continue;
  5203. + }
  5204. + owner = file_hash_get_file_owner(conf, old);
  5205. + if (owner != old_pkg) {
  5206. + /* in case obsolete file no longer belongs to old_pkg */
  5207. + continue;
  5208. + }
  5209. +
  5210. + /* old file is obsolete */
  5211. + ipkg_message(conf, IPKG_INFO,
  5212. + " removing obsolete file %s\n", old);
  5213. + if (!conf->noaction) {
  5214. + err = unlink(old);
  5215. + if (err) {
  5216. + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
  5217. + strerror(errno));
  5218. + }
  5219. + }
  5220. +
  5221. + NOT_OBSOLETE:
  5222. + ;
  5223. + }
  5224. +
  5225. + pkg_free_installed_files(old_pkg);
  5226. + pkg_free_installed_files(pkg);
  5227. +
  5228. + return 0;
  5229. +}
  5230. +
  5231. +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5232. +{
  5233. + int i;
  5234. + int err = 0;
  5235. + char *globpattern;
  5236. + glob_t globbuf;
  5237. + if (0) {
  5238. + if (!pkg->dest) {
  5239. + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
  5240. + return -1;
  5241. + }
  5242. + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
  5243. + err = glob(globpattern, 0, NULL, &globbuf);
  5244. + free(globpattern);
  5245. + if (err) {
  5246. + return err;
  5247. + }
  5248. + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
  5249. + for (i = 0; i < globbuf.gl_pathc; i++) {
  5250. + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
  5251. + globbuf.gl_pathv[i], old_pkg->name);
  5252. + if (!conf->noaction)
  5253. + unlink(globbuf.gl_pathv[i]);
  5254. + }
  5255. + globfree(&globbuf);
  5256. + }
  5257. + return err;
  5258. +}
  5259. +
  5260. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5261. +{
  5262. + int ret;
  5263. + char *prefix;
  5264. +
  5265. + if (old_pkg)
  5266. + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
  5267. + sprintf_alloc(&prefix, "%s.", pkg->name);
  5268. + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
  5269. + pkg->dest->info_dir,
  5270. + prefix);
  5271. + free(prefix);
  5272. + return ret;
  5273. +}
  5274. +
  5275. +/*
  5276. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
  5277. +{
  5278. + DPKG_INCOMPATIBILITY:
  5279. + This is a fairly sophisticated dpkg operation. Shall we
  5280. + skip it?
  5281. +
  5282. + Any packages all of whose files have been overwritten during the
  5283. + installation, and which aren't required for dependencies, are
  5284. + considered to have been removed. For each such package
  5285. + 1. disappearer's-postrm disappear overwriter overwriter-version
  5286. + 2. The package's maintainer scripts are removed
  5287. + 3. It is noted in the status database as being in a sane state,
  5288. + namely not installed (any conffiles it may have are ignored,
  5289. + rather than being removed by dpkg). Note that disappearing
  5290. + packages do not have their prerm called, because dpkg doesn't
  5291. + know in advance that the package is going to vanish.
  5292. +
  5293. +
  5294. + return 0;
  5295. +}
  5296. +*/
  5297. +
  5298. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
  5299. +{
  5300. + int err;
  5301. +
  5302. + /* ipkg takes a slightly different approach to data file backups
  5303. + than dpkg. Rather than removing backups at this point, we
  5304. + actually do the data file installation now. See comments in
  5305. + check_data_file_clashes() for more details. */
  5306. +
  5307. + ipkg_message(conf, IPKG_INFO,
  5308. + " extracting data files to %s\n", pkg->dest->root_dir);
  5309. + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
  5310. + if (err) {
  5311. + return err;
  5312. + }
  5313. +
  5314. + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
  5315. + so we can't save ourself from removing important packages
  5316. + At this point we (should) have extracted the .control file, so it
  5317. + would be a good idea to reload the data in it, and set the Essential
  5318. + state in *pkg. From now on the Essential is back in status file and
  5319. + we can protect again.
  5320. + We should operate this way:
  5321. + fopen the file ( pkg->dest->root_dir/pkg->name.control )
  5322. + check for "Essential" in it
  5323. + set the value in pkg->essential.
  5324. + This new routine could be useful also for every other flag
  5325. + Pigi: 16/03/2004 */
  5326. + set_flags_from_control(conf, pkg) ;
  5327. +
  5328. + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
  5329. + err = pkg_write_filelist(conf, pkg);
  5330. + if (err)
  5331. + return err;
  5332. +
  5333. + /* XXX: FEATURE: ipkg should identify any files which existed
  5334. + before installation and which were overwritten, (see
  5335. + check_data_file_clashes()). What it must do is remove any such
  5336. + files from the filelist of the old package which provided the
  5337. + file. Otherwise, if the old package were removed at some point
  5338. + it would break the new package. Removing the new package will
  5339. + also break the old one, but this cannot be helped since the old
  5340. + package's file has already been deleted. This is the importance
  5341. + of check_data_file_clashes(), and only allowing ipkg to install
  5342. + a clashing package with a user force. */
  5343. +
  5344. + return 0;
  5345. +}
  5346. +
  5347. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
  5348. +{
  5349. + conffile_list_elt_t *iter;
  5350. + conffile_t *cf;
  5351. + char *cf_backup;
  5352. + uint8_t *md5sum;
  5353. +
  5354. +
  5355. + if (conf->noaction) return 0;
  5356. +
  5357. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  5358. + char *root_filename;
  5359. + cf = iter->data;
  5360. + root_filename = root_filename_alloc(conf, cf->name);
  5361. +
  5362. + /* Might need to initialize the md5sum for each conffile */
  5363. + if (cf->value == NULL) {
  5364. + cf->value = (char *)file_md5sum_alloc(root_filename);
  5365. + }
  5366. +
  5367. + if (!file_exists(root_filename)) {
  5368. + free(root_filename);
  5369. + continue;
  5370. + }
  5371. +
  5372. + cf_backup = backup_filename_alloc(root_filename);
  5373. +
  5374. +
  5375. + if (file_exists(cf_backup)) {
  5376. + /* Let's compute md5 to test if files are changed */
  5377. + md5sum = file_md5sum_alloc(cf_backup);
  5378. + if (strcmp( cf->value, (char *)md5sum) != 0 ) {
  5379. + if (conf->force_defaults
  5380. + || user_prefers_old_conffile(cf->name, cf_backup) ) {
  5381. + rename(cf_backup, root_filename);
  5382. + }
  5383. + }
  5384. + unlink(cf_backup);
  5385. + free(md5sum);
  5386. + }
  5387. +
  5388. + free(cf_backup);
  5389. + free(root_filename);
  5390. + }
  5391. +
  5392. + return 0;
  5393. +}
  5394. +
  5395. +static int user_prefers_old_conffile(const char *file_name, const char *backup)
  5396. +{
  5397. + char *response;
  5398. + const char *short_file_name;
  5399. +
  5400. + short_file_name = strrchr(file_name, '/');
  5401. + if (short_file_name) {
  5402. + short_file_name++;
  5403. + } else {
  5404. + short_file_name = file_name;
  5405. + }
  5406. +
  5407. + while (1) {
  5408. + response = get_user_response(" Configuration file '%s'\n"
  5409. + " ==> File on system created by you or by a script.\n"
  5410. + " ==> File also in package provided by package maintainer.\n"
  5411. + " What would you like to do about it ? Your options are:\n"
  5412. + " Y or I : install the package maintainer's version\n"
  5413. + " N or O : keep your currently-installed version\n"
  5414. +#ifdef CONFIG_DIFF
  5415. + " D : show the differences between the versions\n"
  5416. +#endif
  5417. + " The default action is to keep your current version.\n"
  5418. + " *** %s (Y/I/N/O"
  5419. +#ifdef CONFIG_DIFF
  5420. + "/D"
  5421. +#endif
  5422. + ") [default=N] ? ", file_name, short_file_name);
  5423. + if (strcmp(response, "y") == 0
  5424. + || strcmp(response, "i") == 0
  5425. + || strcmp(response, "yes") == 0) {
  5426. + free(response);
  5427. + return 0;
  5428. + }
  5429. +
  5430. +#ifdef CONFIG_DIFF
  5431. + if (strcmp(response, "d") == 0) {
  5432. + char *cmd;
  5433. +
  5434. + free(response);
  5435. + /* XXX: BUG rewrite to use exec or busybox's internal diff */
  5436. + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
  5437. + xsystem(cmd);
  5438. + free(cmd);
  5439. + printf(" [Press ENTER to continue]\n");
  5440. + response = file_read_line_alloc(stdin);
  5441. + free(response);
  5442. + continue;
  5443. + }
  5444. +#endif
  5445. +
  5446. + free(response);
  5447. + return 1;
  5448. + }
  5449. +}
  5450. +
  5451. +/* XXX: CLEANUP: I'd like to move all of the code for
  5452. + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
  5453. + it would make sense to cleanup pkg->tmp_unpack_dir directly from
  5454. + pkg_deinit for example). */
  5455. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
  5456. +{
  5457. + DIR *tmp_dir;
  5458. + struct dirent *dirent;
  5459. + char *tmp_file;
  5460. +
  5461. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  5462. +#error
  5463. + ipkg_message(conf, IPKG_DEBUG,
  5464. + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  5465. + __FUNCTION__, pkg->tmp_unpack_dir);
  5466. + return 0;
  5467. +#endif
  5468. +
  5469. + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
  5470. + tmp_dir = opendir(pkg->tmp_unpack_dir);
  5471. + if (tmp_dir) {
  5472. + while (1) {
  5473. + dirent = readdir(tmp_dir);
  5474. + if (dirent == NULL) {
  5475. + break;
  5476. + }
  5477. + sprintf_alloc(&tmp_file, "%s/%s",
  5478. + pkg->tmp_unpack_dir, dirent->d_name);
  5479. + if (! file_is_dir(tmp_file)) {
  5480. + unlink(tmp_file);
  5481. + }
  5482. + free(tmp_file);
  5483. + }
  5484. + closedir(tmp_dir);
  5485. + rmdir(pkg->tmp_unpack_dir);
  5486. + free(pkg->tmp_unpack_dir);
  5487. + pkg->tmp_unpack_dir = NULL;
  5488. + }
  5489. + }
  5490. +
  5491. + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
  5492. + pkg->name, pkg->local_filename, conf->tmp_dir);
  5493. + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
  5494. + unlink(pkg->local_filename);
  5495. + free(pkg->local_filename);
  5496. + pkg->local_filename = NULL;
  5497. + }
  5498. +
  5499. + return 0;
  5500. +}
  5501. +
  5502. +static char *backup_filename_alloc(const char *file_name)
  5503. +{
  5504. + char *backup;
  5505. +
  5506. + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
  5507. +
  5508. + return backup;
  5509. +}
  5510. +
  5511. +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
  5512. +{
  5513. + int err;
  5514. + char *backup;
  5515. +
  5516. + backup = backup_filename_alloc(file_name);
  5517. + err = file_copy(file_name, backup);
  5518. + if (err) {
  5519. + ipkg_message(conf, IPKG_ERROR,
  5520. + "%s: Failed to copy %s to %s\n",
  5521. + __FUNCTION__, file_name, backup);
  5522. + }
  5523. +
  5524. + free(backup);
  5525. +
  5526. + return err;
  5527. +}
  5528. +
  5529. +static int backup_exists_for(const char *file_name)
  5530. +{
  5531. + int ret;
  5532. + char *backup;
  5533. +
  5534. + backup = backup_filename_alloc(file_name);
  5535. +
  5536. + ret = file_exists(backup);
  5537. +
  5538. + free(backup);
  5539. +
  5540. + return ret;
  5541. +}
  5542. +
  5543. +static int backup_remove(const char *file_name)
  5544. +{
  5545. + char *backup;
  5546. +
  5547. + backup = backup_filename_alloc(file_name);
  5548. + unlink(backup);
  5549. + free(backup);
  5550. +
  5551. + return 0;
  5552. +}
  5553. +
  5554. +
  5555. +
  5556. +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
  5557. +
  5558. +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
  5559. +{
  5560. + /* first, remove the packages that need removing */
  5561. + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
  5562. + pkg_t *pkg = pkgs_to_remove->pkgs[i];
  5563. + err = ipkg_remove_pkg(conf, pkg,0);
  5564. + if (err) return err;
  5565. + }
  5566. + return 0;
  5567. +}
  5568. +
  5569. +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)
  5570. +{
  5571. + int i;
  5572. + /* now one more pass checking on the ones that need to be installed */
  5573. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5574. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5575. + if (pkg->dest == NULL)
  5576. + pkg->dest = conf->default_dest;
  5577. +
  5578. + pkg->state_want = SW_INSTALL;
  5579. +
  5580. + /* Abhaya: conflicts check */
  5581. + err = check_conflicts_for(conf, pkg);
  5582. + if (err) { return err; }
  5583. + }
  5584. + return 0;
  5585. +}
  5586. +
  5587. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5588. +{
  5589. + int i;
  5590. + /* now one more pass checking on the ones that need to be installed */
  5591. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5592. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5593. +
  5594. + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
  5595. + pkg_vec_t *replacees = pkg_vec_alloc();
  5596. + pkg_get_installed_replacees(pkg, replacees);
  5597. +
  5598. + /* XXX: BUG: we really should treat replacement more like an upgrade
  5599. + * Instead, we're going to remove the replacees
  5600. + */
  5601. + err = pkg_remove_installed_replacees(conf, replacees);
  5602. + if (err) return err;
  5603. + pkg->state_flag |= SF_REMOVED_REPLACEES;
  5604. + }
  5605. + return 0;
  5606. +}
  5607. +
  5608. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5609. +{
  5610. + int i;
  5611. + /* now one more pass checking on the ones that need to be installed */
  5612. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5613. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5614. + if (pkg->local_filename == NULL) {
  5615. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  5616. + if (err) {
  5617. + ipkg_message(conf, IPKG_ERROR,
  5618. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  5619. + pkg->name);
  5620. + return err;
  5621. + }
  5622. + }
  5623. + if (pkg->tmp_unpack_dir == NULL) {
  5624. + err = unpack_pkg_control_files(conf, pkg);
  5625. + if (err) return err;
  5626. + }
  5627. + }
  5628. + return 0;
  5629. +}
  5630. +
  5631. +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5632. +{
  5633. + int i;
  5634. + /* now one more pass checking on the ones that need to be installed */
  5635. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5636. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5637. + pkg_t *old_pkg = pkg->old_pkg;
  5638. +
  5639. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  5640. + if (err) return err;
  5641. +
  5642. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  5643. + if (err) return err;
  5644. +
  5645. + err = preinst_configure(conf, pkg, old_pkg);
  5646. + if (err) return err;
  5647. +
  5648. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  5649. + if (err) return err;
  5650. +
  5651. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  5652. + if (err) return err;
  5653. + }
  5654. + return 0;
  5655. +}
  5656. +
  5657. +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5658. +{
  5659. + int i;
  5660. + /* now one more pass checking on the ones that need to be installed */
  5661. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5662. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5663. + pkg_t *old_pkg = pkg->old_pkg;
  5664. +
  5665. + if (old_pkg) {
  5666. + old_pkg->state_want = SW_DEINSTALL;
  5667. +
  5668. + if (old_pkg->state_flag & SF_NOPRUNE) {
  5669. + ipkg_message(conf, IPKG_INFO,
  5670. + " not removing obsolesced files because package marked noprune\n");
  5671. + } else {
  5672. + ipkg_message(conf, IPKG_INFO,
  5673. + " removing obsolesced files\n");
  5674. + remove_obsolesced_files(conf, pkg, old_pkg);
  5675. + }
  5676. + }
  5677. +
  5678. + ipkg_message(conf, IPKG_INFO,
  5679. + " installing maintainer scripts\n");
  5680. + install_maintainer_scripts(conf, pkg, old_pkg);
  5681. +
  5682. + /* the following just returns 0 */
  5683. + remove_disappeared(conf, pkg);
  5684. +
  5685. + ipkg_message(conf, IPKG_INFO,
  5686. + " installing data files\n");
  5687. + install_data_files(conf, pkg);
  5688. +
  5689. + ipkg_message(conf, IPKG_INFO,
  5690. + " resolving conf files\n");
  5691. + resolve_conffiles(conf, pkg);
  5692. +
  5693. + pkg->state_status = SS_UNPACKED;
  5694. +
  5695. + if (old_pkg) {
  5696. + old_pkg->state_status = SS_NOT_INSTALLED;
  5697. + }
  5698. +
  5699. + time(&pkg->installed_time);
  5700. +
  5701. + ipkg_message(conf, IPKG_INFO,
  5702. + " cleanup temp files\n");
  5703. + cleanup_temporary_files(conf, pkg);
  5704. +
  5705. + if (pkg->parent)
  5706. + pkg->parent->state_status = pkg->state_status;
  5707. + }
  5708. + return 0;
  5709. +}
  5710. +
  5711. +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5712. +{
  5713. + int i;
  5714. + /* now one more pass checking on the ones that need to be installed */
  5715. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5716. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5717. + pkg_t *old_pkg = pkg->old_pkg;
  5718. +
  5719. + if (old_pkg) {
  5720. + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
  5721. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5722. + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
  5723. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  5724. + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
  5725. + backup_modified_conffiles_unwind(pkg, old_pkg);
  5726. + */
  5727. + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
  5728. + preinst_configure_unwind(conf, pkg, old_pkg);
  5729. + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
  5730. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  5731. + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
  5732. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5733. + */
  5734. +
  5735. + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
  5736. + remove_installed_replacees_unwind(conf, pkg, old_pkg);
  5737. +
  5738. + }
  5739. + }
  5740. + return 0;
  5741. +}
  5742. +
  5743. +/*
  5744. + * Perform all the actions.
  5745. + *
  5746. + * pkgs_to_remove are packages marked for removal.
  5747. + * pkgs_superseded are the old packages being replaced by upgrades.
  5748. + *
  5749. + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
  5750. + */
  5751. +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)
  5752. +{
  5753. + int err;
  5754. + int i;
  5755. +
  5756. + err = ipkg_remove_packages(conf, pkgs_to_remove);
  5757. + if (err) return err;
  5758. +
  5759. + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
  5760. + if (err) return err;
  5761. +
  5762. + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
  5763. + if (err) goto UNWIND;
  5764. +
  5765. + /* @@@@ look at ipkg_install_pkg for handling replacements */
  5766. + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
  5767. + if (err) goto UNWIND;
  5768. +
  5769. + /*
  5770. + * Now that we have the packages unpacked, we can look for data
  5771. + * file clashes. First, we mark the files from the superseded
  5772. + * packages as obsolete. Then we scan the files in
  5773. + * pkgs_to_install, and only complain about clashes with
  5774. + * non-obsolete files.
  5775. + */
  5776. +
  5777. + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
  5778. + if (err) goto UNWIND;
  5779. +
  5780. + /* this was before checking data file clashes */
  5781. + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
  5782. + if (err) goto UNWIND;
  5783. +
  5784. + /* point of no return: no unwinding after this */
  5785. + err = ipkg_process_actions_install(conf, pkgs_to_install);
  5786. + if (err) return err;
  5787. +
  5788. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  5789. + return 0;
  5790. +
  5791. + UNWIND:
  5792. + ipkg_process_actions_unwind(conf, pkgs_to_install);
  5793. +
  5794. + ipkg_message(conf, IPKG_INFO,
  5795. + " cleanup temp files\n");
  5796. + cleanup_temporary_files(conf, pkg);
  5797. +
  5798. + ipkg_message(conf, IPKG_INFO,
  5799. + "Failed.\n");
  5800. + return err;
  5801. +}
  5802. +
  5803. +#endif
  5804. diff -Nur busybox-1.13.4.orig/archival/libipkg/ipkg_install.h busybox-1.13.4/archival/libipkg/ipkg_install.h
  5805. --- busybox-1.13.4.orig/archival/libipkg/ipkg_install.h 1970-01-01 01:00:00.000000000 +0100
  5806. +++ busybox-1.13.4/archival/libipkg/ipkg_install.h 2009-05-31 15:40:37.049992428 +0200
  5807. @@ -0,0 +1,35 @@
  5808. +/* ipkg_install.h - the itsy package management system
  5809. +
  5810. + Carl D. Worth
  5811. +
  5812. + Copyright (C) 2001 University of Southern California
  5813. +
  5814. + This program is free software; you can redistribute it and/or
  5815. + modify it under the terms of the GNU General Public License as
  5816. + published by the Free Software Foundation; either version 2, or (at
  5817. + your option) any later version.
  5818. +
  5819. + This program is distributed in the hope that it will be useful, but
  5820. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5821. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5822. + General Public License for more details.
  5823. +*/
  5824. +
  5825. +#ifndef IPKG_INSTALL_H
  5826. +#define IPKG_INSTALL_H
  5827. +
  5828. +#include "pkg.h"
  5829. +#include "ipkg_conf.h"
  5830. +
  5831. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5832. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5833. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
  5834. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
  5835. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  5836. +
  5837. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
  5838. +
  5839. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
  5840. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
  5841. +
  5842. +#endif
  5843. diff -Nur busybox-1.13.4.orig/archival/libipkg/ipkg_message.c busybox-1.13.4/archival/libipkg/ipkg_message.c
  5844. --- busybox-1.13.4.orig/archival/libipkg/ipkg_message.c 1970-01-01 01:00:00.000000000 +0100
  5845. +++ busybox-1.13.4/archival/libipkg/ipkg_message.c 2009-05-31 15:40:37.053992938 +0200
  5846. @@ -0,0 +1,61 @@
  5847. +/* ipkg_message.c - the itsy package management system
  5848. +
  5849. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5850. +
  5851. + This program is free software; you can redistribute it and/or
  5852. + modify it under the terms of the GNU General Public License as
  5853. + published by the Free Software Foundation; either version 2, or (at
  5854. + your option) any later version.
  5855. +
  5856. + This program is distributed in the hope that it will be useful, but
  5857. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5858. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5859. + General Public License for more details.
  5860. +*/
  5861. +
  5862. +
  5863. +#include "ipkg.h"
  5864. +#include "ipkg_conf.h"
  5865. +#include "ipkg_message.h"
  5866. +
  5867. +#ifndef IPKG_LIB
  5868. +
  5869. +void
  5870. +ipkg_message (ipkg_conf_t * conf, message_level_t level, char *fmt, ...)
  5871. +{
  5872. + va_list ap;
  5873. +
  5874. + if (conf && (conf->verbosity < level))
  5875. + {
  5876. + return;
  5877. + }
  5878. + else
  5879. + {
  5880. +
  5881. + va_start (ap, fmt);
  5882. + vprintf (fmt, ap);
  5883. + va_end (ap);
  5884. + }
  5885. +}
  5886. +
  5887. +#else
  5888. +
  5889. +#include "libipkg.h"
  5890. +
  5891. +//#define ipkg_message(conf, level, fmt, arg...) ipkg_cb_message(conf, level, fmt, ## arg)
  5892. +
  5893. +void
  5894. +ipkg_message (ipkg_conf_t * conf, message_level_t level, const char *fmt, ...)
  5895. +{
  5896. + va_list ap;
  5897. + char ts[256];
  5898. +
  5899. + if (ipkg_cb_message)
  5900. + {
  5901. + va_start (ap, fmt);
  5902. + vsnprintf (ts,256,fmt, ap);
  5903. + va_end (ap);
  5904. + ipkg_cb_message(conf,level,ts);
  5905. + }
  5906. +}
  5907. +#endif
  5908. diff -Nur busybox-1.13.4.orig/archival/libipkg/ipkg_message.h busybox-1.13.4/archival/libipkg/ipkg_message.h
  5909. --- busybox-1.13.4.orig/archival/libipkg/ipkg_message.h 1970-01-01 01:00:00.000000000 +0100
  5910. +++ busybox-1.13.4/archival/libipkg/ipkg_message.h 2009-05-31 15:40:37.057994007 +0200
  5911. @@ -0,0 +1,32 @@
  5912. +/* ipkg_message.h - the itsy package management system
  5913. +
  5914. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5915. +
  5916. + This program is free software; you can redistribute it and/or
  5917. + modify it under the terms of the GNU General Public License as
  5918. + published by the Free Software Foundation; either version 2, or (at
  5919. + your option) any later version.
  5920. +
  5921. + This program is distributed in the hope that it will be useful, but
  5922. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5923. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5924. + General Public License for more details.
  5925. +*/
  5926. +
  5927. +#ifndef _IPKG_MESSAGE_H_
  5928. +#define _IPKG_MESSAGE_H_
  5929. +
  5930. +#include "ipkg.h"
  5931. +#include "ipkg_conf.h"
  5932. +
  5933. +typedef enum {
  5934. + IPKG_ERROR, /* error conditions */
  5935. + IPKG_NOTICE, /* normal but significant condition */
  5936. + IPKG_INFO, /* informational message */
  5937. + IPKG_DEBUG, /* debug level message */
  5938. + IPKG_DEBUG2, /* more debug level message */
  5939. +} message_level_t;
  5940. +
  5941. +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, const char *fmt, ...);
  5942. +
  5943. +#endif /* _IPKG_MESSAGE_H_ */
  5944. diff -Nur busybox-1.13.4.orig/archival/libipkg/ipkg_remove.c busybox-1.13.4/archival/libipkg/ipkg_remove.c
  5945. --- busybox-1.13.4.orig/archival/libipkg/ipkg_remove.c 1970-01-01 01:00:00.000000000 +0100
  5946. +++ busybox-1.13.4/archival/libipkg/ipkg_remove.c 2009-05-31 15:40:37.061994238 +0200
  5947. @@ -0,0 +1,385 @@
  5948. +/* ipkg_remove.c - the itsy package management system
  5949. +
  5950. + Carl D. Worth
  5951. +
  5952. + Copyright (C) 2001 University of Southern California
  5953. +
  5954. + This program is free software; you can redistribute it and/or
  5955. + modify it under the terms of the GNU General Public License as
  5956. + published by the Free Software Foundation; either version 2, or (at
  5957. + your option) any later version.
  5958. +
  5959. + This program is distributed in the hope that it will be useful, but
  5960. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5961. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5962. + General Public License for more details.
  5963. +*/
  5964. +
  5965. +#include "ipkg.h"
  5966. +#include "ipkg_message.h"
  5967. +
  5968. +#include <glob.h>
  5969. +
  5970. +#include "ipkg_remove.h"
  5971. +
  5972. +#include "file_util.h"
  5973. +#include "sprintf_alloc.h"
  5974. +#include "str_util.h"
  5975. +
  5976. +#include "ipkg_cmd.h"
  5977. +
  5978. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents);
  5979. +
  5980. +/*
  5981. + * Returns number of the number of packages depending on the packages provided by this package.
  5982. + * Every package implicitly provides itself.
  5983. + */
  5984. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents)
  5985. +{
  5986. + int nprovides = pkg->provides_count;
  5987. + abstract_pkg_t **provides = pkg->provides;
  5988. + int n_installed_dependents = 0;
  5989. + int i;
  5990. + for (i = 0; i <= nprovides; i++) {
  5991. + abstract_pkg_t *providee = provides[i];
  5992. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5993. + abstract_pkg_t *dep_ab_pkg;
  5994. + if (dependers == NULL)
  5995. + continue;
  5996. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5997. + if (dep_ab_pkg->state_status == SS_INSTALLED){
  5998. + n_installed_dependents++;
  5999. + }
  6000. + }
  6001. +
  6002. + }
  6003. + /* if caller requested the set of installed dependents */
  6004. + if (pdependents) {
  6005. + int p = 0;
  6006. + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
  6007. +
  6008. + if ( dependents == NULL ){
  6009. + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
  6010. + return -1;
  6011. + }
  6012. +
  6013. + *pdependents = dependents;
  6014. + for (i = 0; i <= nprovides; i++) {
  6015. + abstract_pkg_t *providee = provides[i];
  6016. + abstract_pkg_t **dependers = providee->depended_upon_by;
  6017. + abstract_pkg_t *dep_ab_pkg;
  6018. + if (dependers == NULL)
  6019. + continue;
  6020. + while ((dep_ab_pkg = *dependers++) != NULL) {
  6021. + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
  6022. + dependents[p++] = dep_ab_pkg;
  6023. + dep_ab_pkg->state_flag |= SF_MARKED;
  6024. + }
  6025. + }
  6026. + }
  6027. + dependents[p] = NULL;
  6028. + /* now clear the marks */
  6029. + for (i = 0; i < p; i++) {
  6030. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  6031. + dep_ab_pkg->state_flag &= ~SF_MARKED;
  6032. + }
  6033. + }
  6034. + return n_installed_dependents;
  6035. +}
  6036. +
  6037. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  6038. +{
  6039. + int i;
  6040. + int a;
  6041. + int count;
  6042. + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
  6043. + abstract_pkg_t * ab_pkg;
  6044. +
  6045. + if((ab_pkg = pkg->parent) == NULL){
  6046. + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
  6047. + __FUNCTION__, pkg->name);
  6048. + return 0;
  6049. + }
  6050. +
  6051. + if (dependents == NULL)
  6052. + return 0;
  6053. +
  6054. + // here i am using the dependencies_checked
  6055. + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
  6056. + return 0; // has already been encountered in the process
  6057. + // of marking packages for removal - Karthik
  6058. + ab_pkg->dependencies_checked = 2;
  6059. +
  6060. + i = 0;
  6061. + count = 1;
  6062. + while (dependents [i] != NULL) {
  6063. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  6064. +
  6065. + if (dep_ab_pkg->dependencies_checked == 2){
  6066. + i++;
  6067. + continue;
  6068. + }
  6069. + if (dep_ab_pkg->state_status == SS_INSTALLED) {
  6070. + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
  6071. + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
  6072. + if (dep_pkg->state_status == SS_INSTALLED) {
  6073. + pkg_vec_insert(dependent_pkgs, dep_pkg);
  6074. + count++;
  6075. + }
  6076. + }
  6077. + }
  6078. + i++;
  6079. + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
  6080. + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
  6081. + }
  6082. +
  6083. + if (count == 1)
  6084. + return 0;
  6085. +
  6086. +
  6087. + for (i = 0; i < dependent_pkgs->len; i++) {
  6088. + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
  6089. + if (err)
  6090. + return err;
  6091. + }
  6092. + return 0;
  6093. +}
  6094. +
  6095. +static int user_prefers_removing_dependents(ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  6096. +{
  6097. + abstract_pkg_t *dep_ab_pkg;
  6098. + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
  6099. + while ((dep_ab_pkg = *dependents++) != NULL) {
  6100. + if (dep_ab_pkg->state_status == SS_INSTALLED)
  6101. + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
  6102. + }
  6103. + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
  6104. + ipkg_message(conf, IPKG_ERROR, "");
  6105. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
  6106. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
  6107. + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
  6108. + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
  6109. + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
  6110. + return 0;
  6111. +}
  6112. +
  6113. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
  6114. +{
  6115. +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
  6116. + thus I wan't check for essential, as I'm upgrading.
  6117. + I hope it won't break anything :)
  6118. +*/
  6119. + int err;
  6120. + abstract_pkg_t *parent_pkg = NULL;
  6121. +
  6122. + if (pkg->essential && !message) {
  6123. + if (conf->force_removal_of_essential_packages) {
  6124. + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
  6125. + "\tIf your system breaks, you get to keep both pieces\n",
  6126. + pkg->name);
  6127. + } else {
  6128. + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
  6129. + "\tRemoving an essential package may lead to an unusable system, but if\n"
  6130. + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
  6131. + "\tits will with the option: -force-removal-of-essential-packages\n",
  6132. + pkg->name);
  6133. + return IPKG_PKG_IS_ESSENTIAL;
  6134. + }
  6135. + }
  6136. +
  6137. + if ((parent_pkg = pkg->parent) == NULL)
  6138. + return 0;
  6139. +
  6140. + /* only attempt to remove dependent installed packages if
  6141. + * force_depends is not specified or the package is being
  6142. + * replaced.
  6143. + */
  6144. + if (!conf->force_depends
  6145. + && !(pkg->state_flag & SF_REPLACE)) {
  6146. + abstract_pkg_t **dependents;
  6147. + int has_installed_dependents =
  6148. + pkg_has_installed_dependents(pkg, &dependents);
  6149. +
  6150. + if (has_installed_dependents) {
  6151. + /*
  6152. + * if this package is depended up by others, then either we should
  6153. + * not remove it or we should remove it and all of its dependents
  6154. + */
  6155. +
  6156. + if (!conf->force_removal_of_dependent_packages
  6157. + && !user_prefers_removing_dependents(conf, pkg, dependents)) {
  6158. + return IPKG_PKG_HAS_DEPENDENTS;
  6159. + }
  6160. +
  6161. + /* remove packages depending on this package - Karthik */
  6162. + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
  6163. + free(dependents);
  6164. + if (err) return err;
  6165. + }
  6166. + }
  6167. +
  6168. + if ( message==0 ){
  6169. + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
  6170. + fflush(stdout);
  6171. + }
  6172. + pkg->state_flag |= SF_FILELIST_CHANGED;
  6173. +
  6174. + pkg->state_want = SW_DEINSTALL;
  6175. + ipkg_state_changed++;
  6176. +
  6177. + pkg_run_script(conf, pkg, "prerm", "remove");
  6178. +
  6179. + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
  6180. + maintains an empty filelist rather than deleting it. That seems
  6181. + like a big pain, and I don't see that that should make a big
  6182. + difference, but for anyone who wants tighter compatibility,
  6183. + feel free to fix this. */
  6184. + remove_data_files_and_list(conf, pkg);
  6185. +
  6186. + pkg_run_script(conf, pkg, "postrm", "remove");
  6187. +
  6188. + remove_maintainer_scripts_except_postrm(conf, pkg);
  6189. +
  6190. + /* Aman Gupta - Since ipkg is made for handheld devices with limited
  6191. + * space, it doesn't make sense to leave extra configurations, files,
  6192. + * and maintainer scripts left around. So, we make remove like purge,
  6193. + * and take out all the crap :) */
  6194. +
  6195. + remove_postrm(conf, pkg);
  6196. + pkg->state_status = SS_NOT_INSTALLED;
  6197. +
  6198. + if (parent_pkg)
  6199. + parent_pkg->state_status = SS_NOT_INSTALLED;
  6200. +
  6201. + return 0;
  6202. +}
  6203. +
  6204. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
  6205. +{
  6206. + ipkg_remove_pkg(conf, pkg,0);
  6207. + return 0;
  6208. +}
  6209. +
  6210. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
  6211. +{
  6212. + str_list_t installed_dirs;
  6213. + str_list_t *installed_files;
  6214. + str_list_elt_t *iter;
  6215. + char *file_name;
  6216. + conffile_t *conffile;
  6217. + int removed_a_dir;
  6218. + pkg_t *owner;
  6219. +
  6220. + str_list_init(&installed_dirs);
  6221. + installed_files = pkg_get_installed_files(pkg);
  6222. +
  6223. + for (iter = installed_files->head; iter; iter = iter->next) {
  6224. + file_name = iter->data;
  6225. +
  6226. + if (file_is_dir(file_name)) {
  6227. + str_list_append(&installed_dirs, strdup(file_name));
  6228. + continue;
  6229. + }
  6230. +
  6231. + conffile = pkg_get_conffile(pkg, file_name);
  6232. + if (conffile) {
  6233. + /* XXX: QUESTION: Is this right? I figure we only need to
  6234. + save the conffile if it has been modified. Is that what
  6235. + dpkg does? Or does dpkg preserve all conffiles? If so,
  6236. + this seems like a better thing to do to conserve
  6237. + space. */
  6238. + if (conffile_has_been_modified(conf, conffile)) {
  6239. + printf(" not deleting modified conffile %s\n", file_name);
  6240. + fflush(stdout);
  6241. + continue;
  6242. + }
  6243. + }
  6244. +
  6245. + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
  6246. + if (!conf->noaction)
  6247. + unlink(file_name);
  6248. + }
  6249. +
  6250. + if (!conf->noaction) {
  6251. + do {
  6252. + removed_a_dir = 0;
  6253. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6254. + file_name = iter->data;
  6255. +
  6256. + if (rmdir(file_name) == 0) {
  6257. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
  6258. + removed_a_dir = 1;
  6259. + str_list_remove(&installed_dirs, &iter);
  6260. + }
  6261. + }
  6262. + } while (removed_a_dir);
  6263. + }
  6264. +
  6265. + pkg_free_installed_files(pkg);
  6266. + /* We have to remove the file list now, so that
  6267. + find_pkg_owning_file does not always just report this package */
  6268. + pkg_remove_installed_files_list(conf, pkg);
  6269. +
  6270. + /* Don't print warning for dirs that are provided by other packages */
  6271. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6272. + file_name = iter->data;
  6273. +
  6274. + owner = file_hash_get_file_owner(conf, file_name);
  6275. + if (owner) {
  6276. + free(iter->data);
  6277. + iter->data = NULL;
  6278. + str_list_remove(&installed_dirs, &iter);
  6279. + }
  6280. + }
  6281. +
  6282. + /* cleanup */
  6283. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6284. + free(iter->data);
  6285. + iter->data = NULL;
  6286. + }
  6287. + str_list_deinit(&installed_dirs);
  6288. +
  6289. + return 0;
  6290. +}
  6291. +
  6292. +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6293. +{
  6294. + int i, err;
  6295. + char *globpattern;
  6296. + glob_t globbuf;
  6297. +
  6298. + if (conf->noaction) return 0;
  6299. +
  6300. + sprintf_alloc(&globpattern, "%s/%s.*",
  6301. + pkg->dest->info_dir, pkg->name);
  6302. + err = glob(globpattern, 0, NULL, &globbuf);
  6303. + free(globpattern);
  6304. + if (err) {
  6305. + return 0;
  6306. + }
  6307. +
  6308. + for (i = 0; i < globbuf.gl_pathc; i++) {
  6309. + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
  6310. + continue;
  6311. + }
  6312. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
  6313. + unlink(globbuf.gl_pathv[i]);
  6314. + }
  6315. + globfree(&globbuf);
  6316. +
  6317. + return 0;
  6318. +}
  6319. +
  6320. +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6321. +{
  6322. + char *postrm_file_name;
  6323. +
  6324. + if (conf->noaction) return 0;
  6325. +
  6326. + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
  6327. + pkg->dest->info_dir, pkg->name);
  6328. + unlink(postrm_file_name);
  6329. + free(postrm_file_name);
  6330. +
  6331. + return 0;
  6332. +}
  6333. diff -Nur busybox-1.13.4.orig/archival/libipkg/ipkg_remove.h busybox-1.13.4/archival/libipkg/ipkg_remove.h
  6334. --- busybox-1.13.4.orig/archival/libipkg/ipkg_remove.h 1970-01-01 01:00:00.000000000 +0100
  6335. +++ busybox-1.13.4/archival/libipkg/ipkg_remove.h 2009-05-31 15:40:37.061994238 +0200
  6336. @@ -0,0 +1,33 @@
  6337. +/* ipkg_remove.h - the itsy package management system
  6338. +
  6339. + Carl D. Worth
  6340. +
  6341. + Copyright (C) 2001 University of Southern California
  6342. +
  6343. + This program is free software; you can redistribute it and/or
  6344. + modify it under the terms of the GNU General Public License as
  6345. + published by the Free Software Foundation; either version 2, or (at
  6346. + your option) any later version.
  6347. +
  6348. + This program is distributed in the hope that it will be useful, but
  6349. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6350. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6351. + General Public License for more details.
  6352. +*/
  6353. +
  6354. +#ifndef IPKG_REMOVE_H
  6355. +#define IPKG_REMOVE_H
  6356. +
  6357. +#include "pkg.h"
  6358. +#include "ipkg_conf.h"
  6359. +
  6360. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
  6361. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
  6362. +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
  6363. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents);
  6364. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
  6365. +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6366. +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6367. +
  6368. +
  6369. +#endif
  6370. diff -Nur busybox-1.13.4.orig/archival/libipkg/ipkg_upgrade.c busybox-1.13.4/archival/libipkg/ipkg_upgrade.c
  6371. --- busybox-1.13.4.orig/archival/libipkg/ipkg_upgrade.c 1970-01-01 01:00:00.000000000 +0100
  6372. +++ busybox-1.13.4/archival/libipkg/ipkg_upgrade.c 2009-05-31 15:40:37.061994238 +0200
  6373. @@ -0,0 +1,79 @@
  6374. +/* ipkg_upgrade.c - the itsy package management system
  6375. +
  6376. + Carl D. Worth
  6377. + Copyright (C) 2001 University of Southern California
  6378. +
  6379. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6380. +
  6381. + This program is free software; you can redistribute it and/or
  6382. + modify it under the terms of the GNU General Public License as
  6383. + published by the Free Software Foundation; either version 2, or (at
  6384. + your option) any later version.
  6385. +
  6386. + This program is distributed in the hope that it will be useful, but
  6387. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6388. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6389. + General Public License for more details.
  6390. +*/
  6391. +
  6392. +#include "ipkg.h"
  6393. +#include "ipkg_install.h"
  6394. +#include "ipkg_message.h"
  6395. +
  6396. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6397. +
  6398. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
  6399. +{
  6400. + pkg_t *new;
  6401. + int cmp;
  6402. + char *old_version, *new_version;
  6403. +
  6404. + if (old->state_flag & SF_HOLD) {
  6405. + ipkg_message(conf, IPKG_NOTICE,
  6406. + "Not upgrading package %s which is marked "
  6407. + "hold (flags=%#x)\n", old->name, old->state_flag);
  6408. + return 0;
  6409. + }
  6410. +
  6411. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
  6412. + if (new == NULL) {
  6413. + old_version = pkg_version_str_alloc(old);
  6414. + ipkg_message(conf, IPKG_NOTICE,
  6415. + "Assuming locally installed package %s (%s) "
  6416. + "is up to date.\n", old->name, old_version);
  6417. + free(old_version);
  6418. + return 0;
  6419. + }
  6420. +
  6421. + old_version = pkg_version_str_alloc(old);
  6422. + new_version = pkg_version_str_alloc(new);
  6423. +
  6424. + cmp = pkg_compare_versions(old, new);
  6425. + ipkg_message(conf, IPKG_DEBUG,
  6426. + "comparing visible versions of pkg %s:"
  6427. + "\n\t%s is installed "
  6428. + "\n\t%s is available "
  6429. + "\n\t%d was comparison result\n",
  6430. + old->name, old_version, new_version, cmp);
  6431. + if (cmp == 0) {
  6432. + ipkg_message(conf, IPKG_INFO,
  6433. + "Package %s (%s) installed in %s is up to date.\n",
  6434. + old->name, old_version, old->dest->name);
  6435. + free(old_version);
  6436. + free(new_version);
  6437. + return 0;
  6438. + } else if (cmp > 0) {
  6439. + ipkg_message(conf, IPKG_NOTICE,
  6440. + "Not downgrading package %s on %s from %s to %s.\n",
  6441. + old->name, old->dest->name, old_version, new_version);
  6442. + free(old_version);
  6443. + free(new_version);
  6444. + return 0;
  6445. + } else if (cmp < 0) {
  6446. + new->dest = old->dest;
  6447. + old->state_want = SW_DEINSTALL;
  6448. + }
  6449. +
  6450. + new->state_flag |= SF_USER;
  6451. + return ipkg_install_pkg(conf, new,1);
  6452. +}
  6453. diff -Nur busybox-1.13.4.orig/archival/libipkg/ipkg_upgrade.h busybox-1.13.4/archival/libipkg/ipkg_upgrade.h
  6454. --- busybox-1.13.4.orig/archival/libipkg/ipkg_upgrade.h 1970-01-01 01:00:00.000000000 +0100
  6455. +++ busybox-1.13.4/archival/libipkg/ipkg_upgrade.h 2009-05-31 15:40:37.061994238 +0200
  6456. @@ -0,0 +1,18 @@
  6457. +/* ipkg_upgrade.c - the itsy package management system
  6458. +
  6459. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6460. +
  6461. + This program is free software; you can redistribute it and/or
  6462. + modify it under the terms of the GNU General Public License as
  6463. + published by the Free Software Foundation; either version 2, or (at
  6464. + your option) any later version.
  6465. +
  6466. + This program is distributed in the hope that it will be useful, but
  6467. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6468. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6469. + General Public License for more details.
  6470. +*/
  6471. +
  6472. +#include "ipkg.h"
  6473. +
  6474. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6475. diff -Nur busybox-1.13.4.orig/archival/libipkg/ipkg_utils.c busybox-1.13.4/archival/libipkg/ipkg_utils.c
  6476. --- busybox-1.13.4.orig/archival/libipkg/ipkg_utils.c 1970-01-01 01:00:00.000000000 +0100
  6477. +++ busybox-1.13.4/archival/libipkg/ipkg_utils.c 2009-05-31 15:40:37.065994189 +0200
  6478. @@ -0,0 +1,185 @@
  6479. +/* ipkg_utils.c - the itsy package management system
  6480. +
  6481. + Steven M. Ayer
  6482. +
  6483. + Copyright (C) 2002 Compaq Computer Corporation
  6484. +
  6485. + This program is free software; you can redistribute it and/or
  6486. + modify it under the terms of the GNU General Public License as
  6487. + published by the Free Software Foundation; either version 2, or (at
  6488. + your option) any later version.
  6489. +
  6490. + This program is distributed in the hope that it will be useful, but
  6491. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6492. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6493. + General Public License for more details.
  6494. +*/
  6495. +
  6496. +#include "ipkg.h"
  6497. +#include <errno.h>
  6498. +#include <ctype.h>
  6499. +#include <sys/vfs.h>
  6500. +
  6501. +#include "ipkg_utils.h"
  6502. +#include "pkg.h"
  6503. +#include "pkg_hash.h"
  6504. +
  6505. +void push_error_list(struct errlist ** errors, char * msg);
  6506. +void reverse_error_list(struct errlist **errors);
  6507. +void free_error_list(struct errlist **errors);
  6508. +
  6509. +struct errlist* error_list;
  6510. +
  6511. +int get_available_blocks(char * filesystem)
  6512. +{
  6513. + struct statfs sfs;
  6514. +
  6515. + if(statfs(filesystem, &sfs)){
  6516. + fprintf(stderr, "bad statfs\n");
  6517. + return 0;
  6518. + }
  6519. + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
  6520. + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
  6521. +}
  6522. +
  6523. +char **read_raw_pkgs_from_file(const char *file_name)
  6524. +{
  6525. + FILE *fp;
  6526. + char **ret;
  6527. +
  6528. + if(!(fp = fopen(file_name, "r"))){
  6529. + fprintf(stderr, "can't get %s open for read\n", file_name);
  6530. + return NULL;
  6531. + }
  6532. +
  6533. + ret = read_raw_pkgs_from_stream(fp);
  6534. +
  6535. + fclose(fp);
  6536. +
  6537. + return ret;
  6538. +}
  6539. +
  6540. +char **read_raw_pkgs_from_stream(FILE *fp)
  6541. +{
  6542. + char **raw = NULL, *buf, *scout;
  6543. + int count = 0;
  6544. + size_t size = 512;
  6545. +
  6546. + buf = malloc (size);
  6547. +
  6548. + while (fgets(buf, size, fp)) {
  6549. + while (strlen (buf) == (size - 1)
  6550. + && buf[size-2] != '\n') {
  6551. + size_t o = size - 1;
  6552. + size *= 2;
  6553. + buf = realloc (buf, size);
  6554. + if (fgets (buf + o, size - o, fp) == NULL)
  6555. + break;
  6556. + }
  6557. +
  6558. + if(!(count % 50))
  6559. + raw = realloc(raw, (count + 50) * sizeof(char *));
  6560. +
  6561. + if((scout = strchr(buf, '\n')))
  6562. + *scout = '\0';
  6563. +
  6564. + raw[count++] = strdup(buf);
  6565. + }
  6566. +
  6567. + raw = realloc(raw, (count + 1) * sizeof(char *));
  6568. + raw[count] = NULL;
  6569. +
  6570. + free (buf);
  6571. +
  6572. + return raw;
  6573. +}
  6574. +
  6575. +/* something to remove whitespace, a hash pooper */
  6576. +char *trim_alloc(char *line)
  6577. +{
  6578. + char *new;
  6579. + char *dest, *src, *end;
  6580. +
  6581. + new = malloc(strlen(line) + 1);
  6582. + if ( new == NULL ){
  6583. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  6584. + return NULL;
  6585. + }
  6586. + dest = new, src = line, end = line + (strlen(line) - 1);
  6587. +
  6588. + /* remove it from the front */
  6589. + while(src &&
  6590. + isspace(*src) &&
  6591. + *src)
  6592. + src++;
  6593. + /* and now from the back */
  6594. + while((end > src) &&
  6595. + isspace(*end))
  6596. + end--;
  6597. + end++;
  6598. + *end = '\0';
  6599. + strcpy(new, src);
  6600. + /* this does from the first space
  6601. + * blasting away any versions stuff in depends
  6602. + while(src &&
  6603. + !isspace(*src) &&
  6604. + *src)
  6605. + *dest++ = *src++;
  6606. + *dest = '\0';
  6607. + */
  6608. +
  6609. + return new;
  6610. +}
  6611. +
  6612. +int line_is_blank(const char *line)
  6613. +{
  6614. + const char *s;
  6615. +
  6616. + for (s = line; *s; s++) {
  6617. + if (!isspace(*s))
  6618. + return 0;
  6619. + }
  6620. + return 1;
  6621. +}
  6622. +
  6623. +void push_error_list(struct errlist ** errors, char * msg){
  6624. + struct errlist *err_lst_tmp;
  6625. +
  6626. +
  6627. + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
  6628. + err_lst_tmp->errmsg=strdup(msg) ;
  6629. + err_lst_tmp->next = *errors;
  6630. + *errors = err_lst_tmp;
  6631. +}
  6632. +
  6633. +
  6634. +void reverse_error_list(struct errlist **errors){
  6635. + struct errlist *result=NULL;
  6636. + struct errlist *current= *errors;
  6637. + struct errlist *next;
  6638. +
  6639. + while ( current != NULL ) {
  6640. + next = current->next;
  6641. + current->next=result;
  6642. + result=current;
  6643. + current=next;
  6644. + }
  6645. + *errors=result;
  6646. +
  6647. +}
  6648. +
  6649. +
  6650. +void free_error_list(struct errlist **errors){
  6651. + struct errlist *current = *errors;
  6652. +
  6653. + while (current != NULL) {
  6654. + free(current->errmsg);
  6655. + current = (*errors)->next;
  6656. + free(*errors);
  6657. + *errors = current;
  6658. + }
  6659. +
  6660. +
  6661. +}
  6662. +
  6663. +
  6664. diff -Nur busybox-1.13.4.orig/archival/libipkg/ipkg_utils.h busybox-1.13.4/archival/libipkg/ipkg_utils.h
  6665. --- busybox-1.13.4.orig/archival/libipkg/ipkg_utils.h 1970-01-01 01:00:00.000000000 +0100
  6666. +++ busybox-1.13.4/archival/libipkg/ipkg_utils.h 2009-05-31 15:40:37.065994189 +0200
  6667. @@ -0,0 +1,29 @@
  6668. +/* ipkg_utils.h - the itsy package management system
  6669. +
  6670. + Steven M. Ayer
  6671. +
  6672. + Copyright (C) 2002 Compaq Computer Corporation
  6673. +
  6674. + This program is free software; you can redistribute it and/or
  6675. + modify it under the terms of the GNU General Public License as
  6676. + published by the Free Software Foundation; either version 2, or (at
  6677. + your option) any later version.
  6678. +
  6679. + This program is distributed in the hope that it will be useful, but
  6680. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6681. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6682. + General Public License for more details.
  6683. +*/
  6684. +
  6685. +#ifndef IPKG_UTILS_H
  6686. +#define IPKG_UTILS_H
  6687. +
  6688. +#include "pkg.h"
  6689. +
  6690. +int get_available_blocks(char * filesystem);
  6691. +char **read_raw_pkgs_from_file(const char *file_name);
  6692. +char **read_raw_pkgs_from_stream(FILE *fp);
  6693. +char *trim_alloc(char * line);
  6694. +int line_is_blank(const char *line);
  6695. +
  6696. +#endif
  6697. diff -Nur busybox-1.13.4.orig/archival/libipkg/libipkg.c busybox-1.13.4/archival/libipkg/libipkg.c
  6698. --- busybox-1.13.4.orig/archival/libipkg/libipkg.c 1970-01-01 01:00:00.000000000 +0100
  6699. +++ busybox-1.13.4/archival/libipkg/libipkg.c 2009-05-31 15:40:37.069994700 +0200
  6700. @@ -0,0 +1,532 @@
  6701. +/* ipkglib.c - the itsy package management system
  6702. +
  6703. + Florina Boor
  6704. +
  6705. + Copyright (C) 2003 kernel concepts
  6706. +
  6707. + This program is free software; you can redistribute it and/or
  6708. + modify it under the terms of the GNU General Public License as
  6709. + published by the Free Software Foundation; either version 2, or (at
  6710. + your option) any later version.
  6711. +
  6712. + This program is distributed in the hope that it will be useful, but
  6713. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6714. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6715. + General Public License for more details.
  6716. +*/
  6717. +
  6718. +#ifdef IPKG_LIB
  6719. +
  6720. +#include "ipkg.h"
  6721. +#include "ipkg_includes.h"
  6722. +#include "libipkg.h"
  6723. +
  6724. +#include "args.h"
  6725. +#include "ipkg_conf.h"
  6726. +#include "ipkg_cmd.h"
  6727. +#include "file_util.h"
  6728. +
  6729. +int ipkg_file_what(args_t *args, const char *file, const char* command);
  6730. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  6731. + char *msg);
  6732. +int default_ipkg_list_callback(char *name, char *desc, char *version);
  6733. +int default_ipkg_files_callback(char *desc);
  6734. +int default_ipkg_status_callback(char *desc);
  6735. +char* default_ipkg_response_callback(char *question);
  6736. +
  6737. +
  6738. +ipkg_message_callback ipkg_cb_message = NULL;
  6739. +ipkg_response_callback ipkg_cb_response = NULL;
  6740. +ipkg_status_callback ipkg_cb_status = NULL;
  6741. +ipkg_list_callback ipkg_cb_list = NULL;
  6742. +
  6743. +
  6744. +int
  6745. +ipkg_init (ipkg_message_callback mcall,
  6746. + ipkg_response_callback rcall,
  6747. + args_t * args)
  6748. +{
  6749. + ipkg_cb_message = mcall;
  6750. + ipkg_cb_response = rcall;
  6751. +
  6752. + args_init (args);
  6753. +
  6754. + return 0;
  6755. +}
  6756. +
  6757. +
  6758. +int
  6759. +ipkg_deinit (args_t * args)
  6760. +{
  6761. + args_deinit (args);
  6762. + ipkg_cb_message = NULL;
  6763. + ipkg_cb_response = NULL;
  6764. +
  6765. + /* place other cleanup stuff here */
  6766. +
  6767. + return 0;
  6768. +}
  6769. +
  6770. +
  6771. +int
  6772. +ipkg_packages_list(args_t *args,
  6773. + const char *packages,
  6774. + ipkg_list_callback cblist,
  6775. + void *userdata)
  6776. +{
  6777. + ipkg_cmd_t *cmd;
  6778. + ipkg_conf_t ipkg_conf;
  6779. + int err;
  6780. +
  6781. + err = ipkg_conf_init (&ipkg_conf, args);
  6782. + if (err)
  6783. + {
  6784. + return err;
  6785. + }
  6786. +
  6787. + ipkg_cb_list = cblist;
  6788. + /* we need to do this because of static declarations,
  6789. + * maybe a good idea to change */
  6790. + cmd = ipkg_cmd_find ("list");
  6791. + if (packages)
  6792. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6793. + else
  6794. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6795. + ipkg_cb_list = NULL;
  6796. + ipkg_conf_deinit (&ipkg_conf);
  6797. + return (err);
  6798. +}
  6799. +
  6800. +
  6801. +int
  6802. +ipkg_packages_status(args_t *args,
  6803. + const char *packages,
  6804. + ipkg_status_callback cbstatus,
  6805. + void *userdata)
  6806. +{
  6807. + ipkg_cmd_t *cmd;
  6808. + ipkg_conf_t ipkg_conf;
  6809. + int err;
  6810. +
  6811. + err = ipkg_conf_init (&ipkg_conf, args);
  6812. + if (err)
  6813. + {
  6814. + return err;
  6815. + }
  6816. +
  6817. + ipkg_cb_status = cbstatus;
  6818. +
  6819. + /* we need to do this because of static declarations,
  6820. + * maybe a good idea to change */
  6821. + cmd = ipkg_cmd_find ("status");
  6822. + if (packages)
  6823. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6824. + else
  6825. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6826. +
  6827. + ipkg_cb_status = NULL;
  6828. + ipkg_conf_deinit (&ipkg_conf);
  6829. + return (err);
  6830. +}
  6831. +
  6832. +
  6833. +int
  6834. +ipkg_packages_info(args_t *args,
  6835. + const char *packages,
  6836. + ipkg_status_callback cbstatus,
  6837. + void *userdata)
  6838. +{
  6839. + ipkg_cmd_t *cmd;
  6840. + ipkg_conf_t ipkg_conf;
  6841. + int err;
  6842. +
  6843. + err = ipkg_conf_init (&ipkg_conf, args);
  6844. + if (err)
  6845. + {
  6846. + return err;
  6847. + }
  6848. +
  6849. + ipkg_cb_status = cbstatus;
  6850. +
  6851. + /* we need to do this because of static declarations,
  6852. + * maybe a good idea to change */
  6853. + cmd = ipkg_cmd_find ("info");
  6854. + if (packages)
  6855. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6856. + else
  6857. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6858. +
  6859. + ipkg_cb_status = NULL;
  6860. + ipkg_conf_deinit (&ipkg_conf);
  6861. + return (err);
  6862. +}
  6863. +
  6864. +
  6865. +int
  6866. +ipkg_packages_install (args_t * args, const char *name)
  6867. +{
  6868. + ipkg_cmd_t *cmd;
  6869. + ipkg_conf_t ipkg_conf;
  6870. + int err;
  6871. +
  6872. + /* this error should be handled in application */
  6873. + if (!name || !strlen (name))
  6874. + return (-1);
  6875. +
  6876. + err = ipkg_conf_init (&ipkg_conf, args);
  6877. + if (err)
  6878. + {
  6879. + return err;
  6880. + }
  6881. +
  6882. + /* we need to do this because of static declarations,
  6883. + * maybe a good idea to change */
  6884. + cmd = ipkg_cmd_find ("install");
  6885. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6886. +
  6887. + ipkg_conf_deinit(&ipkg_conf);
  6888. + return (err);
  6889. +}
  6890. +
  6891. +
  6892. +int
  6893. +ipkg_packages_remove(args_t *args, const char *name, int purge)
  6894. +{
  6895. + ipkg_cmd_t *cmd;
  6896. + ipkg_conf_t ipkg_conf;
  6897. + int err;
  6898. +
  6899. + /* this error should be handled in application */
  6900. + if (!name || !strlen (name))
  6901. + return (-1);
  6902. +
  6903. + err = ipkg_conf_init (&ipkg_conf, args);
  6904. + if (err)
  6905. + {
  6906. + return err;
  6907. + }
  6908. +
  6909. + /* we need to do this because of static declarations,
  6910. + * maybe a good idea to change */
  6911. + if (purge)
  6912. + cmd = ipkg_cmd_find ("purge");
  6913. + else
  6914. + cmd = ipkg_cmd_find ("remove");
  6915. +
  6916. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6917. +
  6918. + ipkg_conf_deinit(&ipkg_conf);
  6919. + return (err);
  6920. +}
  6921. +
  6922. +
  6923. +int
  6924. +ipkg_lists_update(args_t *args)
  6925. +{
  6926. + ipkg_cmd_t *cmd;
  6927. + ipkg_conf_t ipkg_conf;
  6928. + int err;
  6929. +
  6930. + err = ipkg_conf_init (&ipkg_conf, args);
  6931. + if (err)
  6932. + {
  6933. + return err;
  6934. + }
  6935. +
  6936. + /* we need to do this because of static declarations,
  6937. + * maybe a good idea to change */
  6938. + cmd = ipkg_cmd_find ("update");
  6939. +
  6940. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6941. +
  6942. + ipkg_conf_deinit(&ipkg_conf);
  6943. + return (err);
  6944. +}
  6945. +
  6946. +
  6947. +int
  6948. +ipkg_packages_upgrade(args_t *args)
  6949. +{
  6950. + ipkg_cmd_t *cmd;
  6951. + ipkg_conf_t ipkg_conf;
  6952. + int err;
  6953. +
  6954. + err = ipkg_conf_init (&ipkg_conf, args);
  6955. + if (err)
  6956. + {
  6957. + return err;
  6958. + }
  6959. +
  6960. + /* we need to do this because of static declarations,
  6961. + * maybe a good idea to change */
  6962. + cmd = ipkg_cmd_find ("upgrade");
  6963. +
  6964. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6965. +
  6966. + ipkg_conf_deinit(&ipkg_conf);
  6967. + return (err);
  6968. +}
  6969. +
  6970. +
  6971. +int
  6972. +ipkg_packages_download (args_t * args, const char *name)
  6973. +{
  6974. + ipkg_cmd_t *cmd;
  6975. + ipkg_conf_t ipkg_conf;
  6976. + int err;
  6977. +
  6978. + /* this error should be handled in application */
  6979. + if (!name || !strlen (name))
  6980. + return (-1);
  6981. +
  6982. + err = ipkg_conf_init (&ipkg_conf, args);
  6983. + if (err)
  6984. + {
  6985. + return err;
  6986. + }
  6987. +
  6988. + /* we need to do this because of static declarations,
  6989. + * maybe a good idea to change */
  6990. + cmd = ipkg_cmd_find ("download");
  6991. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6992. +
  6993. + ipkg_conf_deinit(&ipkg_conf);
  6994. + return (err);
  6995. +}
  6996. +
  6997. +
  6998. +int
  6999. +ipkg_package_files(args_t *args,
  7000. + const char *name,
  7001. + ipkg_list_callback cblist,
  7002. + void *userdata)
  7003. +{
  7004. + ipkg_cmd_t *cmd;
  7005. + ipkg_conf_t ipkg_conf;
  7006. + int err;
  7007. +
  7008. + /* this error should be handled in application */
  7009. + if (!name || !strlen (name))
  7010. + return (-1);
  7011. +
  7012. + err = ipkg_conf_init (&ipkg_conf, args);
  7013. + if (err)
  7014. + {
  7015. + return err;
  7016. + }
  7017. +
  7018. + ipkg_cb_list = cblist;
  7019. +
  7020. + /* we need to do this because of static declarations,
  7021. + * maybe a good idea to change */
  7022. + cmd = ipkg_cmd_find ("files");
  7023. +
  7024. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
  7025. +
  7026. + ipkg_cb_list = NULL;
  7027. + ipkg_conf_deinit(&ipkg_conf);
  7028. + return (err);
  7029. +}
  7030. +
  7031. +
  7032. +int
  7033. +ipkg_file_search(args_t *args,
  7034. + const char *file,
  7035. + ipkg_list_callback cblist,
  7036. + void *userdata)
  7037. +{
  7038. + ipkg_cmd_t *cmd;
  7039. + ipkg_conf_t ipkg_conf;
  7040. + int err;
  7041. +
  7042. + /* this error should be handled in application */
  7043. + if (!file || !strlen (file))
  7044. + return (-1);
  7045. +
  7046. + err = ipkg_conf_init (&ipkg_conf, args);
  7047. + if (err)
  7048. + {
  7049. + return err;
  7050. + }
  7051. +
  7052. + ipkg_cb_list = cblist;
  7053. +
  7054. + /* we need to do this because of static declarations,
  7055. + * maybe a good idea to change */
  7056. + cmd = ipkg_cmd_find ("search");
  7057. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
  7058. +
  7059. + ipkg_cb_list = NULL;
  7060. + ipkg_conf_deinit(&ipkg_conf);
  7061. + return(err);
  7062. +}
  7063. +
  7064. +
  7065. +int
  7066. +ipkg_file_what(args_t *args, const char *file, const char* command)
  7067. +{
  7068. + ipkg_cmd_t *cmd;
  7069. + ipkg_conf_t ipkg_conf;
  7070. + int err;
  7071. +
  7072. + /* this error should be handled in application */
  7073. + if (!file || !strlen (file))
  7074. + return (-1);
  7075. +
  7076. + err = ipkg_conf_init (&ipkg_conf, args);
  7077. + if (err)
  7078. + {
  7079. + return err;
  7080. + }
  7081. +
  7082. + /* we need to do this because of static declarations,
  7083. + * maybe a good idea to change */
  7084. + cmd = ipkg_cmd_find (command);
  7085. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
  7086. +
  7087. + ipkg_conf_deinit(&ipkg_conf);
  7088. + return(err);
  7089. +}
  7090. +
  7091. +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
  7092. +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
  7093. +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
  7094. +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
  7095. +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
  7096. +
  7097. +
  7098. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  7099. + char *msg)
  7100. +{
  7101. + if (conf && (conf->verbosity < level)) {
  7102. + return 0;
  7103. + } else {
  7104. +#ifdef IPKG_LIB
  7105. + if ( level == IPKG_ERROR ){
  7106. + push_error_list(&error_list, msg);
  7107. +// printf(msg);
  7108. + } else
  7109. +#endif
  7110. + printf(msg);
  7111. + }
  7112. + return 0;
  7113. +}
  7114. +
  7115. +int default_ipkg_list_callback(char *name, char *desc, char *version)
  7116. +{
  7117. + if (desc)
  7118. + printf("%s - %s - %s\n", name, version, desc);
  7119. + else
  7120. + printf("%s - %s\n", name, version);
  7121. + return 0;
  7122. +}
  7123. +
  7124. +int default_ipkg_files_callback(char *desc)
  7125. +{
  7126. + if (desc)
  7127. + printf("%s\n", desc);
  7128. + return 0;
  7129. +}
  7130. +
  7131. +int default_ipkg_status_callback(char *desc)
  7132. +{
  7133. + printf("%s\n", desc);
  7134. + return 0;
  7135. +}
  7136. +
  7137. +char* default_ipkg_response_callback(char *question)
  7138. +{
  7139. + char *response = NULL;
  7140. + printf(question);
  7141. + fflush(stdout);
  7142. + do {
  7143. + response = (char *)file_read_line_alloc(stdin);
  7144. + } while (response == NULL);
  7145. + return response;
  7146. +}
  7147. +
  7148. +/* This is used for backward compatibility */
  7149. +int
  7150. +ipkg_op (int argc, char *argv[])
  7151. +{
  7152. + int err, optind_;
  7153. + args_t args;
  7154. + char *cmd_name;
  7155. + ipkg_cmd_t *cmd;
  7156. + ipkg_conf_t ipkg_conf;
  7157. + const char *message = "ipkg must have one sub-command argument";
  7158. +
  7159. + args_init (&args);
  7160. +
  7161. + optind_ = args_parse (&args, argc, argv);
  7162. + if (optind_ == argc || optind_ < 0)
  7163. + {
  7164. + args_usage(message);
  7165. + }
  7166. +
  7167. + cmd_name = argv[optind_++];
  7168. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  7169. + read anything from there.
  7170. +*/
  7171. + if ( !strcmp(cmd_name,"print-architecture") ||
  7172. + !strcmp(cmd_name,"print_architecture") ||
  7173. + !strcmp(cmd_name,"print-installation-architecture") ||
  7174. + !strcmp(cmd_name,"print_installation_architecture") )
  7175. + args.nocheckfordirorfile = 1;
  7176. +
  7177. +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
  7178. + read anything from there.
  7179. +*/
  7180. + if ( !strcmp(cmd_name,"flag") ||
  7181. + !strcmp(cmd_name,"configure") ||
  7182. + !strcmp(cmd_name,"remove") ||
  7183. + !strcmp(cmd_name,"files") ||
  7184. + !strcmp(cmd_name,"search") ||
  7185. + !strcmp(cmd_name,"compare_versions") ||
  7186. + !strcmp(cmd_name,"compare-versions") ||
  7187. + !strcmp(cmd_name,"list_installed") ||
  7188. + !strcmp(cmd_name,"list-installed") ||
  7189. + !strcmp(cmd_name,"status") )
  7190. + args.noreadfeedsfile = 1;
  7191. +
  7192. +
  7193. + err = ipkg_conf_init (&ipkg_conf, &args);
  7194. + if (err)
  7195. + {
  7196. + return err;
  7197. + }
  7198. +
  7199. + args_deinit (&args);
  7200. +
  7201. + ipkg_cb_message = default_ipkg_message_callback;
  7202. + ipkg_cb_response = default_ipkg_response_callback;
  7203. + ipkg_cb_status = (ipkg_status_callback)default_ipkg_status_callback;
  7204. + if ( strcmp(cmd_name, "files")==0)
  7205. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_files_callback;
  7206. + else
  7207. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_list_callback;
  7208. +
  7209. + cmd = ipkg_cmd_find (cmd_name);
  7210. + if (cmd == NULL)
  7211. + {
  7212. + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
  7213. + cmd_name);
  7214. + args_usage (NULL);
  7215. + }
  7216. +
  7217. + if (cmd->requires_args && optind_ == argc)
  7218. + {
  7219. + fprintf (stderr,
  7220. + "%s: the ``%s'' command requires at least one argument\n",
  7221. + __FUNCTION__, cmd_name);
  7222. + args_usage (NULL);
  7223. + }
  7224. +
  7225. + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind_, (const char **) (argv + optind_), NULL);
  7226. +
  7227. + ipkg_conf_deinit (&ipkg_conf);
  7228. +
  7229. + return err;
  7230. +}
  7231. +
  7232. +#endif /* IPKG_LIB */
  7233. diff -Nur busybox-1.13.4.orig/archival/libipkg/libipkg.h busybox-1.13.4/archival/libipkg/libipkg.h
  7234. --- busybox-1.13.4.orig/archival/libipkg/libipkg.h 1970-01-01 01:00:00.000000000 +0100
  7235. +++ busybox-1.13.4/archival/libipkg/libipkg.h 2009-05-31 15:40:37.069994700 +0200
  7236. @@ -0,0 +1,87 @@
  7237. +/* ipkglib.h - the itsy package management system
  7238. +
  7239. + Florian Boor <florian.boor@kernelconcepts.de>
  7240. +
  7241. + This program is free software; you can redistribute it and/or
  7242. + modify it under the terms of the GNU General Public License as
  7243. + published by the Free Software Foundation; either version 2, or (at
  7244. + your option) any later version.
  7245. +
  7246. + This program is distributed in the hope that it will be useful, but
  7247. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7248. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7249. + General Public License for more details.
  7250. +*/
  7251. +
  7252. +#ifndef IPKGLIB_H
  7253. +#define IPKGLIB_H
  7254. +
  7255. +#ifdef IPKG_LIB
  7256. +
  7257. +#include "ipkg_conf.h"
  7258. +#include "ipkg_message.h"
  7259. +
  7260. +#include "args.h"
  7261. +#include "pkg.h"
  7262. +
  7263. +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
  7264. + char *msg);
  7265. +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
  7266. + pkg_state_status_t status, void *userdata);
  7267. +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
  7268. + void *userdata);
  7269. +typedef char* (*ipkg_response_callback)(char *question);
  7270. +
  7271. +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
  7272. +extern int ipkg_init (ipkg_message_callback mcall,
  7273. + ipkg_response_callback rcall,
  7274. + args_t * args);
  7275. +
  7276. +extern int ipkg_deinit (args_t *args);
  7277. +extern int ipkg_packages_list(args_t *args,
  7278. + const char *packages,
  7279. + ipkg_list_callback cblist,
  7280. + void *userdata);
  7281. +extern int ipkg_packages_status(args_t *args,
  7282. + const char *packages,
  7283. + ipkg_status_callback cbstatus,
  7284. + void *userdata);
  7285. +extern int ipkg_packages_info(args_t *args,
  7286. + const char *packages,
  7287. + ipkg_status_callback cbstatus,
  7288. + void *userdata);
  7289. +extern int ipkg_packages_install(args_t *args, const char *name);
  7290. +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
  7291. +extern int ipkg_lists_update(args_t *args);
  7292. +extern int ipkg_packages_upgrade(args_t *args);
  7293. +extern int ipkg_packages_download(args_t *args, const char *name);
  7294. +extern int ipkg_package_files(args_t *args,
  7295. + const char *name,
  7296. + ipkg_list_callback cblist,
  7297. + void *userdata);
  7298. +extern int ipkg_file_search(args_t *args,
  7299. + const char *file,
  7300. + ipkg_list_callback cblist,
  7301. + void *userdata);
  7302. +extern int ipkg_package_whatdepends(args_t *args, const char *file);
  7303. +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
  7304. +extern int ipkg_package_whatprovides(args_t *args, const char *file);
  7305. +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
  7306. +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
  7307. +
  7308. +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
  7309. +extern ipkg_response_callback ipkg_cb_response;
  7310. +extern ipkg_status_callback ipkg_cb_status;
  7311. +extern ipkg_list_callback ipkg_cb_list;
  7312. +extern void push_error_list(struct errlist **errors,char * msg);
  7313. +extern void reverse_error_list(struct errlist **errors);
  7314. +extern void free_error_list(struct errlist **errors);
  7315. +
  7316. +#else
  7317. +
  7318. +extern int ipkg_op(int argc, char *argv[]);
  7319. +
  7320. +#endif
  7321. +
  7322. +
  7323. +#endif
  7324. diff -Nur busybox-1.13.4.orig/archival/libipkg/nv_pair.c busybox-1.13.4/archival/libipkg/nv_pair.c
  7325. --- busybox-1.13.4.orig/archival/libipkg/nv_pair.c 1970-01-01 01:00:00.000000000 +0100
  7326. +++ busybox-1.13.4/archival/libipkg/nv_pair.c 2009-05-31 15:40:37.073994372 +0200
  7327. @@ -0,0 +1,40 @@
  7328. +/* nv_pair.c - the itsy package management system
  7329. +
  7330. + Carl D. Worth
  7331. +
  7332. + Copyright (C) 2001 University of Southern California
  7333. +
  7334. + This program is free software; you can redistribute it and/or
  7335. + modify it under the terms of the GNU General Public License as
  7336. + published by the Free Software Foundation; either version 2, or (at
  7337. + your option) any later version.
  7338. +
  7339. + This program is distributed in the hope that it will be useful, but
  7340. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7341. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7342. + General Public License for more details.
  7343. +*/
  7344. +
  7345. +#include "ipkg.h"
  7346. +
  7347. +#include "nv_pair.h"
  7348. +#include "str_util.h"
  7349. +
  7350. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
  7351. +{
  7352. + nv_pair->name = str_dup_safe(name);
  7353. + nv_pair->value = str_dup_safe(value);
  7354. +
  7355. + return 0;
  7356. +}
  7357. +
  7358. +void nv_pair_deinit(nv_pair_t *nv_pair)
  7359. +{
  7360. + free(nv_pair->name);
  7361. + nv_pair->name = NULL;
  7362. +
  7363. + free(nv_pair->value);
  7364. + nv_pair->value = NULL;
  7365. +}
  7366. +
  7367. +
  7368. diff -Nur busybox-1.13.4.orig/archival/libipkg/nv_pair.h busybox-1.13.4/archival/libipkg/nv_pair.h
  7369. --- busybox-1.13.4.orig/archival/libipkg/nv_pair.h 1970-01-01 01:00:00.000000000 +0100
  7370. +++ busybox-1.13.4/archival/libipkg/nv_pair.h 2009-05-31 15:40:37.073994372 +0200
  7371. @@ -0,0 +1,32 @@
  7372. +/* nv_pair.h - the itsy package management system
  7373. +
  7374. + Carl D. Worth
  7375. +
  7376. + Copyright (C) 2001 University of Southern California
  7377. +
  7378. + This program is free software; you can redistribute it and/or
  7379. + modify it under the terms of the GNU General Public License as
  7380. + published by the Free Software Foundation; either version 2, or (at
  7381. + your option) any later version.
  7382. +
  7383. + This program is distributed in the hope that it will be useful, but
  7384. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7385. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7386. + General Public License for more details.
  7387. +*/
  7388. +
  7389. +#ifndef NV_PAIR_H
  7390. +#define NV_PAIR_H
  7391. +
  7392. +typedef struct nv_pair nv_pair_t;
  7393. +struct nv_pair
  7394. +{
  7395. + char *name;
  7396. + char *value;
  7397. +};
  7398. +
  7399. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
  7400. +void nv_pair_deinit(nv_pair_t *nv_pair);
  7401. +
  7402. +#endif
  7403. +
  7404. diff -Nur busybox-1.13.4.orig/archival/libipkg/nv_pair_list.c busybox-1.13.4/archival/libipkg/nv_pair_list.c
  7405. --- busybox-1.13.4.orig/archival/libipkg/nv_pair_list.c 1970-01-01 01:00:00.000000000 +0100
  7406. +++ busybox-1.13.4/archival/libipkg/nv_pair_list.c 2009-05-31 15:40:37.073994372 +0200
  7407. @@ -0,0 +1,98 @@
  7408. +/* nv_pair_list.c - the itsy package management system
  7409. +
  7410. + Carl D. Worth
  7411. +
  7412. + Copyright (C) 2001 University of Southern California
  7413. +
  7414. + This program is free software; you can redistribute it and/or
  7415. + modify it under the terms of the GNU General Public License as
  7416. + published by the Free Software Foundation; either version 2, or (at
  7417. + your option) any later version.
  7418. +
  7419. + This program is distributed in the hope that it will be useful, but
  7420. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7421. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7422. + General Public License for more details.
  7423. +*/
  7424. +
  7425. +#include "ipkg.h"
  7426. +
  7427. +#include "nv_pair.h"
  7428. +#include "void_list.h"
  7429. +#include "nv_pair_list.h"
  7430. +
  7431. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
  7432. +{
  7433. + return void_list_elt_init((void_list_elt_t *) elt, data);
  7434. +}
  7435. +
  7436. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
  7437. +{
  7438. + void_list_elt_deinit((void_list_elt_t *) elt);
  7439. +}
  7440. +
  7441. +int nv_pair_list_init(nv_pair_list_t *list)
  7442. +{
  7443. + return void_list_init((void_list_t *) list);
  7444. +}
  7445. +
  7446. +void nv_pair_list_deinit(nv_pair_list_t *list)
  7447. +{
  7448. + nv_pair_list_elt_t *iter;
  7449. + nv_pair_t *nv_pair;
  7450. +
  7451. + for (iter = list->head; iter; iter = iter->next) {
  7452. + nv_pair = iter->data;
  7453. + nv_pair_deinit(nv_pair);
  7454. +
  7455. + /* malloced in nv_pair_list_append */
  7456. + free(nv_pair);
  7457. + iter->data = NULL;
  7458. + }
  7459. + void_list_deinit((void_list_t *) list);
  7460. +}
  7461. +
  7462. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
  7463. +{
  7464. + int err;
  7465. +
  7466. + /* freed in nv_pair_list_deinit */
  7467. + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
  7468. +
  7469. + if (nv_pair == NULL) {
  7470. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7471. + return NULL;
  7472. + }
  7473. + nv_pair_init(nv_pair, name, value);
  7474. +
  7475. + err = void_list_append((void_list_t *) list, nv_pair);
  7476. + if (err) {
  7477. + return NULL;
  7478. + }
  7479. +
  7480. + return nv_pair;
  7481. +}
  7482. +
  7483. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
  7484. +{
  7485. + return void_list_push((void_list_t *) list, data);
  7486. +}
  7487. +
  7488. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
  7489. +{
  7490. + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
  7491. +}
  7492. +
  7493. +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
  7494. +{
  7495. + nv_pair_list_elt_t *iter;
  7496. + nv_pair_t *nv_pair;
  7497. +
  7498. + for (iter = list->head; iter; iter = iter->next) {
  7499. + nv_pair = iter->data;
  7500. + if (strcmp(nv_pair->name, name) == 0) {
  7501. + return nv_pair->value;
  7502. + }
  7503. + }
  7504. + return NULL;
  7505. +}
  7506. diff -Nur busybox-1.13.4.orig/archival/libipkg/nv_pair_list.h busybox-1.13.4/archival/libipkg/nv_pair_list.h
  7507. --- busybox-1.13.4.orig/archival/libipkg/nv_pair_list.h 1970-01-01 01:00:00.000000000 +0100
  7508. +++ busybox-1.13.4/archival/libipkg/nv_pair_list.h 2009-05-31 15:40:37.085996181 +0200
  7509. @@ -0,0 +1,60 @@
  7510. +/* nv_pair_list.h - the itsy package management system
  7511. +
  7512. + Carl D. Worth
  7513. +
  7514. + Copyright (C) 2001 University of Southern California
  7515. +
  7516. + This program is free software; you can redistribute it and/or
  7517. + modify it under the terms of the GNU General Public License as
  7518. + published by the Free Software Foundation; either version 2, or (at
  7519. + your option) any later version.
  7520. +
  7521. + This program is distributed in the hope that it will be useful, but
  7522. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7523. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7524. + General Public License for more details.
  7525. +*/
  7526. +
  7527. +#ifndef NV_PAIR_LIST_H
  7528. +#define NV_PAIR_LIST_H
  7529. +
  7530. +#include "nv_pair.h"
  7531. +#include "void_list.h"
  7532. +
  7533. +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
  7534. +struct nv_pair_list_elt
  7535. +{
  7536. + nv_pair_list_elt_t *next;
  7537. + nv_pair_t *data;
  7538. +};
  7539. +
  7540. +typedef struct nv_pair_list nv_pair_list_t;
  7541. +struct nv_pair_list
  7542. +{
  7543. + nv_pair_list_elt_t pre_head;
  7544. + nv_pair_list_elt_t *head;
  7545. + nv_pair_list_elt_t *tail;
  7546. +};
  7547. +
  7548. +static inline int nv_pair_list_empty(nv_pair_list_t *list)
  7549. +{
  7550. + if (list->head == NULL)
  7551. + return 1;
  7552. + else
  7553. + return 0;
  7554. +}
  7555. +
  7556. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
  7557. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
  7558. +
  7559. +int nv_pair_list_init(nv_pair_list_t *list);
  7560. +void nv_pair_list_deinit(nv_pair_list_t *list);
  7561. +
  7562. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
  7563. + const char *name, const char *value);
  7564. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
  7565. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
  7566. +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
  7567. +
  7568. +#endif
  7569. +
  7570. diff -Nur busybox-1.13.4.orig/archival/libipkg/pkg.c busybox-1.13.4/archival/libipkg/pkg.c
  7571. --- busybox-1.13.4.orig/archival/libipkg/pkg.c 1970-01-01 01:00:00.000000000 +0100
  7572. +++ busybox-1.13.4/archival/libipkg/pkg.c 2009-05-31 15:40:37.089995574 +0200
  7573. @@ -0,0 +1,1757 @@
  7574. +/* pkg.c - the itsy package management system
  7575. +
  7576. + Carl D. Worth
  7577. +
  7578. + Copyright (C) 2001 University of Southern California
  7579. +
  7580. + This program is free software; you can redistribute it and/or
  7581. + modify it under the terms of the GNU General Public License as
  7582. + published by the Free Software Foundation; either version 2, or (at
  7583. + your option) any later version.
  7584. +
  7585. + This program is distributed in the hope that it will be useful, but
  7586. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7587. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7588. + General Public License for more details.
  7589. +*/
  7590. +
  7591. +#include "ipkg.h"
  7592. +#include <ctype.h>
  7593. +#include <string.h>
  7594. +#include <errno.h>
  7595. +
  7596. +#include "pkg.h"
  7597. +
  7598. +#include "pkg_parse.h"
  7599. +#include "pkg_extract.h"
  7600. +#include "ipkg_message.h"
  7601. +#include "ipkg_utils.h"
  7602. +
  7603. +#include "sprintf_alloc.h"
  7604. +#include "file_util.h"
  7605. +#include "str_util.h"
  7606. +#include "xsystem.h"
  7607. +#include "ipkg_conf.h"
  7608. +
  7609. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname);
  7610. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_);
  7611. +
  7612. +typedef struct enum_map enum_map_t;
  7613. +struct enum_map
  7614. +{
  7615. + int value;
  7616. + const char *str;
  7617. +};
  7618. +
  7619. +static const enum_map_t pkg_state_want_map[] = {
  7620. + { SW_UNKNOWN, "unknown"},
  7621. + { SW_INSTALL, "install"},
  7622. + { SW_DEINSTALL, "deinstall"},
  7623. + { SW_PURGE, "purge"}
  7624. +};
  7625. +
  7626. +static const enum_map_t pkg_state_flag_map[] = {
  7627. + { SF_OK, "ok"},
  7628. + { SF_REINSTREQ, "reinstreq"},
  7629. + { SF_HOLD, "hold"},
  7630. + { SF_REPLACE, "replace"},
  7631. + { SF_NOPRUNE, "noprune"},
  7632. + { SF_PREFER, "prefer"},
  7633. + { SF_OBSOLETE, "obsolete"},
  7634. + { SF_USER, "user"},
  7635. +};
  7636. +
  7637. +static const enum_map_t pkg_state_status_map[] = {
  7638. + { SS_NOT_INSTALLED, "not-installed" },
  7639. + { SS_UNPACKED, "unpacked" },
  7640. + { SS_HALF_CONFIGURED, "half-configured" },
  7641. + { SS_INSTALLED, "installed" },
  7642. + { SS_HALF_INSTALLED, "half-installed" },
  7643. + { SS_CONFIG_FILES, "config-files" },
  7644. + { SS_POST_INST_FAILED, "post-inst-failed" },
  7645. + { SS_REMOVAL_FAILED, "removal-failed" }
  7646. +};
  7647. +
  7648. +static int verrevcmp(const char *val, const char *ref);
  7649. +
  7650. +
  7651. +pkg_t *pkg_new(void)
  7652. +{
  7653. + pkg_t *pkg;
  7654. +
  7655. + pkg = malloc(sizeof(pkg_t));
  7656. + if (pkg == NULL) {
  7657. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7658. + return NULL;
  7659. + }
  7660. +
  7661. + pkg_init(pkg);
  7662. +
  7663. + return pkg;
  7664. +}
  7665. +
  7666. +int pkg_init(pkg_t *pkg)
  7667. +{
  7668. + memset(pkg, 0, sizeof(pkg_t));
  7669. + pkg->name = NULL;
  7670. + pkg->epoch = 0;
  7671. + pkg->version = NULL;
  7672. + pkg->revision = NULL;
  7673. + pkg->familiar_revision = NULL;
  7674. + pkg->dest = NULL;
  7675. + pkg->src = NULL;
  7676. + pkg->architecture = NULL;
  7677. + pkg->maintainer = NULL;
  7678. + pkg->section = NULL;
  7679. + pkg->description = NULL;
  7680. + pkg->state_want = SW_UNKNOWN;
  7681. + pkg->state_flag = SF_OK;
  7682. + pkg->state_status = SS_NOT_INSTALLED;
  7683. + pkg->depends_str = NULL;
  7684. + pkg->provides_str = NULL;
  7685. + pkg->depends_count = 0;
  7686. + pkg->depends = NULL;
  7687. + pkg->suggests_str = NULL;
  7688. + pkg->recommends_str = NULL;
  7689. + pkg->suggests_count = 0;
  7690. + pkg->recommends_count = 0;
  7691. +
  7692. + /* Abhaya: added init for conflicts fields */
  7693. + pkg->conflicts = NULL;
  7694. + pkg->conflicts_count = 0;
  7695. +
  7696. + /* added for replaces. Jamey 7/23/2002 */
  7697. + pkg->replaces = NULL;
  7698. + pkg->replaces_count = 0;
  7699. +
  7700. + pkg->pre_depends_count = 0;
  7701. + pkg->pre_depends_str = NULL;
  7702. + pkg->provides_count = 0;
  7703. + pkg->provides = NULL;
  7704. + pkg->filename = NULL;
  7705. + pkg->local_filename = NULL;
  7706. + pkg->tmp_unpack_dir = NULL;
  7707. + pkg->md5sum = NULL;
  7708. + pkg->size = NULL;
  7709. + pkg->installed_size = NULL;
  7710. + pkg->priority = NULL;
  7711. + pkg->source = NULL;
  7712. + conffile_list_init(&pkg->conffiles);
  7713. + pkg->installed_files = NULL;
  7714. + pkg->installed_files_ref_cnt = 0;
  7715. + pkg->essential = 0;
  7716. + pkg->provided_by_hand = 0;
  7717. +
  7718. + return 0;
  7719. +}
  7720. +
  7721. +void pkg_deinit(pkg_t *pkg)
  7722. +{
  7723. + free(pkg->name);
  7724. + pkg->name = NULL;
  7725. + pkg->epoch = 0;
  7726. + free(pkg->version);
  7727. + pkg->version = NULL;
  7728. + /* revision and familiar_revision share storage with version, so
  7729. + don't free */
  7730. + pkg->revision = NULL;
  7731. + pkg->familiar_revision = NULL;
  7732. + /* owned by ipkg_conf_t */
  7733. + pkg->dest = NULL;
  7734. + /* owned by ipkg_conf_t */
  7735. + pkg->src = NULL;
  7736. + free(pkg->architecture);
  7737. + pkg->architecture = NULL;
  7738. + free(pkg->maintainer);
  7739. + pkg->maintainer = NULL;
  7740. + free(pkg->section);
  7741. + pkg->section = NULL;
  7742. + free(pkg->description);
  7743. + pkg->description = NULL;
  7744. + pkg->state_want = SW_UNKNOWN;
  7745. + pkg->state_flag = SF_OK;
  7746. + pkg->state_status = SS_NOT_INSTALLED;
  7747. + free(pkg->depends_str);
  7748. + pkg->depends_str = NULL;
  7749. + free(pkg->provides_str);
  7750. + pkg->provides_str = NULL;
  7751. + pkg->depends_count = 0;
  7752. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
  7753. + pkg->pre_depends_count = 0;
  7754. + free(pkg->pre_depends_str);
  7755. + pkg->pre_depends_str = NULL;
  7756. + pkg->provides_count = 0;
  7757. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
  7758. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
  7759. + free(pkg->filename);
  7760. + pkg->filename = NULL;
  7761. + free(pkg->local_filename);
  7762. + pkg->local_filename = NULL;
  7763. + /* CLEANUP: It'd be nice to pullin the cleanup function from
  7764. + ipkg_install.c here. See comment in
  7765. + ipkg_install.c:cleanup_temporary_files */
  7766. + free(pkg->tmp_unpack_dir);
  7767. + pkg->tmp_unpack_dir = NULL;
  7768. + free(pkg->md5sum);
  7769. + pkg->md5sum = NULL;
  7770. + free(pkg->size);
  7771. + pkg->size = NULL;
  7772. + free(pkg->installed_size);
  7773. + pkg->installed_size = NULL;
  7774. + free(pkg->priority);
  7775. + pkg->priority = NULL;
  7776. + free(pkg->source);
  7777. + pkg->source = NULL;
  7778. + conffile_list_deinit(&pkg->conffiles);
  7779. + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
  7780. + since if they are calling deinit, they should know. Maybe do an
  7781. + assertion here instead? */
  7782. + pkg->installed_files_ref_cnt = 1;
  7783. + pkg_free_installed_files(pkg);
  7784. + pkg->essential = 0;
  7785. +}
  7786. +
  7787. +int pkg_init_from_file(pkg_t *pkg, const char *filename)
  7788. +{
  7789. + int err;
  7790. + char **raw;
  7791. + FILE *control_file;
  7792. +
  7793. + err = pkg_init(pkg);
  7794. + if (err) { return err; }
  7795. +
  7796. + pkg->local_filename = strdup(filename);
  7797. +
  7798. + control_file = tmpfile();
  7799. + err = pkg_extract_control_file_to_stream(pkg, control_file);
  7800. + if (err) { return err; }
  7801. +
  7802. + rewind(control_file);
  7803. + raw = read_raw_pkgs_from_stream(control_file);
  7804. + pkg_parse_raw(pkg, &raw, NULL, NULL);
  7805. +
  7806. + fclose(control_file);
  7807. +
  7808. + return 0;
  7809. +}
  7810. +
  7811. +/* Merge any new information in newpkg into oldpkg */
  7812. +/* XXX: CLEANUP: This function shouldn't actually modify anything in
  7813. + newpkg, but should leave it usable. This rework is so that
  7814. + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
  7815. +/*
  7816. + * uh, i thought that i had originally written this so that it took
  7817. + * two pkgs and returned a new one? we can do that again... -sma
  7818. + */
  7819. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
  7820. +{
  7821. + if (oldpkg == newpkg) {
  7822. + return 0;
  7823. + }
  7824. +
  7825. + if (!oldpkg->src)
  7826. + oldpkg->src = newpkg->src;
  7827. + if (!oldpkg->dest)
  7828. + oldpkg->dest = newpkg->dest;
  7829. + if (!oldpkg->architecture)
  7830. + oldpkg->architecture = str_dup_safe(newpkg->architecture);
  7831. + if (!oldpkg->arch_priority)
  7832. + oldpkg->arch_priority = newpkg->arch_priority;
  7833. + if (!oldpkg->section)
  7834. + oldpkg->section = str_dup_safe(newpkg->section);
  7835. + if(!oldpkg->maintainer)
  7836. + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
  7837. + if(!oldpkg->description)
  7838. + oldpkg->description = str_dup_safe(newpkg->description);
  7839. + if (set_status) {
  7840. + /* merge the state_flags from the new package */
  7841. + oldpkg->state_want = newpkg->state_want;
  7842. + oldpkg->state_status = newpkg->state_status;
  7843. + oldpkg->state_flag = newpkg->state_flag;
  7844. + } else {
  7845. + if (oldpkg->state_want == SW_UNKNOWN)
  7846. + oldpkg->state_want = newpkg->state_want;
  7847. + if (oldpkg->state_status == SS_NOT_INSTALLED)
  7848. + oldpkg->state_status = newpkg->state_status;
  7849. + oldpkg->state_flag |= newpkg->state_flag;
  7850. + }
  7851. +
  7852. + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
  7853. + oldpkg->depends_str = newpkg->depends_str;
  7854. + newpkg->depends_str = NULL;
  7855. + oldpkg->depends_count = newpkg->depends_count;
  7856. + newpkg->depends_count = 0;
  7857. +
  7858. + oldpkg->depends = newpkg->depends;
  7859. + newpkg->depends = NULL;
  7860. +
  7861. + oldpkg->pre_depends_str = newpkg->pre_depends_str;
  7862. + newpkg->pre_depends_str = NULL;
  7863. + oldpkg->pre_depends_count = newpkg->pre_depends_count;
  7864. + newpkg->pre_depends_count = 0;
  7865. +
  7866. + oldpkg->recommends_str = newpkg->recommends_str;
  7867. + newpkg->recommends_str = NULL;
  7868. + oldpkg->recommends_count = newpkg->recommends_count;
  7869. + newpkg->recommends_count = 0;
  7870. +
  7871. + oldpkg->suggests_str = newpkg->suggests_str;
  7872. + newpkg->suggests_str = NULL;
  7873. + oldpkg->suggests_count = newpkg->suggests_count;
  7874. + newpkg->suggests_count = 0;
  7875. + }
  7876. +
  7877. + if (!oldpkg->provides_str) {
  7878. + oldpkg->provides_str = newpkg->provides_str;
  7879. + newpkg->provides_str = NULL;
  7880. + oldpkg->provides_count = newpkg->provides_count;
  7881. + newpkg->provides_count = 0;
  7882. +
  7883. + oldpkg->provides = newpkg->provides;
  7884. + newpkg->provides = NULL;
  7885. + }
  7886. +
  7887. + if (!oldpkg->conflicts_str) {
  7888. + oldpkg->conflicts_str = newpkg->conflicts_str;
  7889. + newpkg->conflicts_str = NULL;
  7890. + oldpkg->conflicts_count = newpkg->conflicts_count;
  7891. + newpkg->conflicts_count = 0;
  7892. +
  7893. + oldpkg->conflicts = newpkg->conflicts;
  7894. + newpkg->conflicts = NULL;
  7895. + }
  7896. +
  7897. + if (!oldpkg->replaces_str) {
  7898. + oldpkg->replaces_str = newpkg->replaces_str;
  7899. + newpkg->replaces_str = NULL;
  7900. + oldpkg->replaces_count = newpkg->replaces_count;
  7901. + newpkg->replaces_count = 0;
  7902. +
  7903. + oldpkg->replaces = newpkg->replaces;
  7904. + newpkg->replaces = NULL;
  7905. + }
  7906. +
  7907. + if (!oldpkg->filename)
  7908. + oldpkg->filename = str_dup_safe(newpkg->filename);
  7909. + if (0)
  7910. + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
  7911. + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
  7912. + if (!oldpkg->local_filename)
  7913. + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
  7914. + if (!oldpkg->tmp_unpack_dir)
  7915. + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
  7916. + if (!oldpkg->md5sum)
  7917. + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
  7918. + if (!oldpkg->size)
  7919. + oldpkg->size = str_dup_safe(newpkg->size);
  7920. + if (!oldpkg->installed_size)
  7921. + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
  7922. + if (!oldpkg->priority)
  7923. + oldpkg->priority = str_dup_safe(newpkg->priority);
  7924. + if (!oldpkg->source)
  7925. + oldpkg->source = str_dup_safe(newpkg->source);
  7926. + if (oldpkg->conffiles.head == NULL){
  7927. + oldpkg->conffiles = newpkg->conffiles;
  7928. + conffile_list_init(&newpkg->conffiles);
  7929. + }
  7930. + if (!oldpkg->installed_files){
  7931. + oldpkg->installed_files = newpkg->installed_files;
  7932. + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
  7933. + newpkg->installed_files = NULL;
  7934. + }
  7935. + if (!oldpkg->essential)
  7936. + oldpkg->essential = newpkg->essential;
  7937. +
  7938. + return 0;
  7939. +}
  7940. +
  7941. +abstract_pkg_t *abstract_pkg_new(void)
  7942. +{
  7943. + abstract_pkg_t * ab_pkg;
  7944. +
  7945. + ab_pkg = malloc(sizeof(abstract_pkg_t));
  7946. +
  7947. + if (ab_pkg == NULL) {
  7948. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7949. + return NULL;
  7950. + }
  7951. +
  7952. + if ( abstract_pkg_init(ab_pkg) < 0 )
  7953. + return NULL;
  7954. +
  7955. + return ab_pkg;
  7956. +}
  7957. +
  7958. +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
  7959. +{
  7960. + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
  7961. +
  7962. + ab_pkg->provided_by = abstract_pkg_vec_alloc();
  7963. + if (ab_pkg->provided_by==NULL){
  7964. + return -1;
  7965. + }
  7966. + ab_pkg->dependencies_checked = 0;
  7967. + ab_pkg->state_status = SS_NOT_INSTALLED;
  7968. +
  7969. + return 0;
  7970. +}
  7971. +
  7972. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
  7973. + char * temp_str;
  7974. + char **raw =NULL;
  7975. + char **raw_start=NULL;
  7976. +
  7977. + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
  7978. + if (temp_str == NULL ){
  7979. + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
  7980. + return;
  7981. + }
  7982. + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
  7983. +
  7984. + raw = raw_start = read_raw_pkgs_from_file(temp_str);
  7985. + if (raw == NULL ){
  7986. + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
  7987. + return;
  7988. + }
  7989. +
  7990. + while(*raw){
  7991. + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
  7992. + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
  7993. + }
  7994. + }
  7995. + raw = raw_start;
  7996. + while (*raw) {
  7997. + if (raw!=NULL)
  7998. + free(*raw++);
  7999. + }
  8000. +
  8001. + free(raw_start);
  8002. + free(temp_str);
  8003. +
  8004. + return ;
  8005. +
  8006. +}
  8007. +
  8008. +char * pkg_formatted_info(pkg_t *pkg )
  8009. +{
  8010. + char *line;
  8011. + char * buff;
  8012. +
  8013. + buff = malloc(8192);
  8014. + if (buff == NULL) {
  8015. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8016. + return NULL;
  8017. + }
  8018. +
  8019. + buff[0] = '\0';
  8020. +
  8021. + line = pkg_formatted_field(pkg, "Package");
  8022. + strncat(buff ,line, strlen(line));
  8023. + free(line);
  8024. +
  8025. + line = pkg_formatted_field(pkg, "Version");
  8026. + strncat(buff ,line, strlen(line));
  8027. + free(line);
  8028. +
  8029. + line = pkg_formatted_field(pkg, "Depends");
  8030. + strncat(buff ,line, strlen(line));
  8031. + free(line);
  8032. +
  8033. + line = pkg_formatted_field(pkg, "Recommends");
  8034. + strncat(buff ,line, strlen(line));
  8035. + free(line);
  8036. +
  8037. + line = pkg_formatted_field(pkg, "Suggests");
  8038. + strncat(buff ,line, strlen(line));
  8039. + free(line);
  8040. +
  8041. + line = pkg_formatted_field(pkg, "Provides");
  8042. + strncat(buff ,line, strlen(line));
  8043. + free(line);
  8044. +
  8045. + line = pkg_formatted_field(pkg, "Replaces");
  8046. + strncat(buff ,line, strlen(line));
  8047. + free(line);
  8048. +
  8049. + line = pkg_formatted_field(pkg, "Conflicts");
  8050. + strncat(buff ,line, strlen(line));
  8051. + free(line);
  8052. +
  8053. + line = pkg_formatted_field(pkg, "Status");
  8054. + strncat(buff ,line, strlen(line));
  8055. + free(line);
  8056. +
  8057. + line = pkg_formatted_field(pkg, "Section");
  8058. + strncat(buff ,line, strlen(line));
  8059. + free(line);
  8060. +
  8061. + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
  8062. + strncat(buff ,line, strlen(line));
  8063. + free(line);
  8064. +
  8065. + line = pkg_formatted_field(pkg, "Architecture");
  8066. + strncat(buff ,line, strlen(line));
  8067. + free(line);
  8068. +
  8069. + line = pkg_formatted_field(pkg, "Maintainer");
  8070. + strncat(buff ,line, strlen(line));
  8071. + free(line);
  8072. +
  8073. + line = pkg_formatted_field(pkg, "MD5sum");
  8074. + strncat(buff ,line, strlen(line));
  8075. + free(line);
  8076. +
  8077. + line = pkg_formatted_field(pkg, "Size");
  8078. + strncat(buff ,line, strlen(line));
  8079. + free(line);
  8080. +
  8081. + line = pkg_formatted_field(pkg, "Filename");
  8082. + strncat(buff ,line, strlen(line));
  8083. + free(line);
  8084. +
  8085. + line = pkg_formatted_field(pkg, "Conffiles");
  8086. + strncat(buff ,line, strlen(line));
  8087. + free(line);
  8088. +
  8089. + line = pkg_formatted_field(pkg, "Source");
  8090. + strncat(buff ,line, strlen(line));
  8091. + free(line);
  8092. +
  8093. + line = pkg_formatted_field(pkg, "Description");
  8094. + strncat(buff ,line, strlen(line));
  8095. + free(line);
  8096. +
  8097. + line = pkg_formatted_field(pkg, "Installed-Time");
  8098. + strncat(buff ,line, strlen(line));
  8099. + free(line);
  8100. +
  8101. + return buff;
  8102. +}
  8103. +
  8104. +char * pkg_formatted_field(pkg_t *pkg, const char *field )
  8105. +{
  8106. + static size_t LINE_LEN = 128;
  8107. + char * temp = (char *)malloc(1);
  8108. + int len = 0;
  8109. + int flag_provide_false = 0;
  8110. +
  8111. +/*
  8112. + Pigi: After some discussion with Florian we decided to modify the full procedure in
  8113. + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
  8114. +*/
  8115. +
  8116. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8117. + goto UNKNOWN_FMT_FIELD;
  8118. + }
  8119. +
  8120. + temp[0]='\0';
  8121. +
  8122. + switch (field[0])
  8123. + {
  8124. + case 'a':
  8125. + case 'A':
  8126. + if (strcasecmp(field, "Architecture") == 0) {
  8127. + /* Architecture */
  8128. + if (pkg->architecture) {
  8129. + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
  8130. + if ( temp == NULL ){
  8131. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8132. + return NULL;
  8133. + }
  8134. + temp[0]='\0';
  8135. + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
  8136. + }
  8137. + } else {
  8138. + goto UNKNOWN_FMT_FIELD;
  8139. + }
  8140. + break;
  8141. + case 'c':
  8142. + case 'C':
  8143. + if (strcasecmp(field, "Conffiles") == 0) {
  8144. + /* Conffiles */
  8145. + conffile_list_elt_t *iter;
  8146. + char confstr_[LINE_LEN];
  8147. +
  8148. + if (pkg->conffiles.head == NULL) {
  8149. + return temp;
  8150. + }
  8151. +
  8152. + len = 14 ;
  8153. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8154. + if (iter->data->name && iter->data->value) {
  8155. + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
  8156. + }
  8157. + }
  8158. + temp = (char *)realloc(temp,len);
  8159. + if ( temp == NULL ){
  8160. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8161. + return NULL;
  8162. + }
  8163. + temp[0]='\0';
  8164. + strncpy(temp, "Conffiles:\n", 12);
  8165. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8166. + if (iter->data->name && iter->data->value) {
  8167. + snprintf(confstr_, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
  8168. + strncat(temp, confstr_, strlen(confstr_));
  8169. + }
  8170. + }
  8171. + } else if (strcasecmp(field, "Conflicts") == 0) {
  8172. + int i;
  8173. +
  8174. + if (pkg->conflicts_count) {
  8175. + char conflictstr[LINE_LEN];
  8176. + len = 14 ;
  8177. + for(i = 0; i < pkg->conflicts_count; i++) {
  8178. + len = len + (strlen(pkg->conflicts_str[i])+5);
  8179. + }
  8180. + temp = (char *)realloc(temp,len);
  8181. + if ( temp == NULL ){
  8182. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8183. + return NULL;
  8184. + }
  8185. + temp[0]='\0';
  8186. + strncpy(temp, "Conflicts:", 11);
  8187. + for(i = 0; i < pkg->conflicts_count; i++) {
  8188. + snprintf(conflictstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
  8189. + strncat(temp, conflictstr, strlen(conflictstr));
  8190. + }
  8191. + strncat(temp, "\n", strlen("\n"));
  8192. + }
  8193. + } else {
  8194. + goto UNKNOWN_FMT_FIELD;
  8195. + }
  8196. + break;
  8197. + case 'd':
  8198. + case 'D':
  8199. + if (strcasecmp(field, "Depends") == 0) {
  8200. + /* Depends */
  8201. + int i;
  8202. +
  8203. + if (pkg->depends_count) {
  8204. + char depstr[LINE_LEN];
  8205. + len = 14 ;
  8206. + for(i = 0; i < pkg->depends_count; i++) {
  8207. + len = len + (strlen(pkg->depends_str[i])+4);
  8208. + }
  8209. + temp = (char *)realloc(temp,len);
  8210. + if ( temp == NULL ){
  8211. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8212. + return NULL;
  8213. + }
  8214. + temp[0]='\0';
  8215. + strncpy(temp, "Depends:", 10);
  8216. + for(i = 0; i < pkg->depends_count; i++) {
  8217. + snprintf(depstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
  8218. + strncat(temp, depstr, strlen(depstr));
  8219. + }
  8220. + strncat(temp, "\n", strlen("\n"));
  8221. + }
  8222. + } else if (strcasecmp(field, "Description") == 0) {
  8223. + /* Description */
  8224. + if (pkg->description) {
  8225. + temp = (char *)realloc(temp,strlen(pkg->description)+16);
  8226. + if ( temp == NULL ){
  8227. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8228. + return NULL;
  8229. + }
  8230. + temp[0]='\0';
  8231. + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
  8232. + }
  8233. + } else {
  8234. + goto UNKNOWN_FMT_FIELD;
  8235. + }
  8236. + break;
  8237. + case 'e':
  8238. + case 'E': {
  8239. + /* Essential */
  8240. + if (pkg->essential) {
  8241. + temp = (char *)realloc(temp,16);
  8242. + if ( temp == NULL ){
  8243. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8244. + return NULL;
  8245. + }
  8246. + temp[0]='\0';
  8247. + snprintf(temp, (16), "Essential: yes\n");
  8248. + }
  8249. + }
  8250. + break;
  8251. + case 'f':
  8252. + case 'F': {
  8253. + /* Filename */
  8254. + if (pkg->filename) {
  8255. + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
  8256. + if ( temp == NULL ){
  8257. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8258. + return NULL;
  8259. + }
  8260. + temp[0]='\0';
  8261. + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
  8262. + }
  8263. + }
  8264. + break;
  8265. + case 'i':
  8266. + case 'I': {
  8267. + if (strcasecmp(field, "Installed-Size") == 0) {
  8268. + /* Installed-Size */
  8269. + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
  8270. + if ( temp == NULL ){
  8271. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8272. + return NULL;
  8273. + }
  8274. + temp[0]='\0';
  8275. + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
  8276. + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
  8277. + temp = (char *)realloc(temp,29);
  8278. + if ( temp == NULL ){
  8279. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8280. + return NULL;
  8281. + }
  8282. + temp[0]='\0';
  8283. + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
  8284. + }
  8285. + }
  8286. + break;
  8287. + case 'm':
  8288. + case 'M': {
  8289. + /* Maintainer | MD5sum */
  8290. + if (strcasecmp(field, "Maintainer") == 0) {
  8291. + /* Maintainer */
  8292. + if (pkg->maintainer) {
  8293. + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
  8294. + if ( temp == NULL ){
  8295. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8296. + return NULL;
  8297. + }
  8298. + temp[0]='\0';
  8299. + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
  8300. + }
  8301. + } else if (strcasecmp(field, "MD5sum") == 0) {
  8302. + /* MD5sum */
  8303. + if (pkg->md5sum) {
  8304. + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
  8305. + if ( temp == NULL ){
  8306. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8307. + return NULL;
  8308. + }
  8309. + temp[0]='\0';
  8310. + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
  8311. + }
  8312. + } else {
  8313. + goto UNKNOWN_FMT_FIELD;
  8314. + }
  8315. + }
  8316. + break;
  8317. + case 'p':
  8318. + case 'P': {
  8319. + if (strcasecmp(field, "Package") == 0) {
  8320. + /* Package */
  8321. + temp = (char *)realloc(temp,strlen(pkg->name)+11);
  8322. + if ( temp == NULL ){
  8323. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8324. + return NULL;
  8325. + }
  8326. + temp[0]='\0';
  8327. + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
  8328. + } else if (strcasecmp(field, "Priority") == 0) {
  8329. + /* Priority */
  8330. + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
  8331. + if ( temp == NULL ){
  8332. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8333. + return NULL;
  8334. + }
  8335. + temp[0]='\0';
  8336. + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
  8337. + } else if (strcasecmp(field, "Provides") == 0) {
  8338. + /* Provides */
  8339. + int i;
  8340. +
  8341. + if (pkg->provides_count) {
  8342. + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
  8343. + for ( i=0; i < pkg->provides_count; i++ ){
  8344. + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
  8345. + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
  8346. + flag_provide_false = 1;
  8347. + }
  8348. + }
  8349. + if ( !flag_provide_false || /* Pigi there is not my trick flag */
  8350. + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
  8351. + char provstr[LINE_LEN];
  8352. + len = 15;
  8353. + for(i = 0; i < pkg->provides_count; i++) {
  8354. + len = len + (strlen(pkg->provides_str[i])+5);
  8355. + }
  8356. + temp = (char *)realloc(temp,len);
  8357. + if ( temp == NULL ){
  8358. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8359. + return NULL;
  8360. + }
  8361. + temp[0]='\0';
  8362. + strncpy(temp, "Provides:", 12);
  8363. + for(i = 0; i < pkg->provides_count; i++) {
  8364. + if (strlen(pkg->provides_str[i])>0){;
  8365. + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
  8366. + strncat(temp, provstr, strlen(provstr));
  8367. + }
  8368. + }
  8369. + strncat(temp, "\n", strlen("\n"));
  8370. + }
  8371. + }
  8372. + } else {
  8373. + goto UNKNOWN_FMT_FIELD;
  8374. + }
  8375. + }
  8376. + break;
  8377. + case 'r':
  8378. + case 'R': {
  8379. + int i;
  8380. + /* Replaces | Recommends*/
  8381. + if (strcasecmp (field, "Replaces") == 0) {
  8382. + if (pkg->replaces_count) {
  8383. + char replstr[LINE_LEN];
  8384. + len = 14;
  8385. + for (i = 0; i < pkg->replaces_count; i++) {
  8386. + len = len + (strlen(pkg->replaces_str[i])+5);
  8387. + }
  8388. + temp = (char *)realloc(temp,len);
  8389. + if ( temp == NULL ){
  8390. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8391. + return NULL;
  8392. + }
  8393. + temp[0]='\0';
  8394. + strncpy(temp, "Replaces:", 12);
  8395. + for (i = 0; i < pkg->replaces_count; i++) {
  8396. + snprintf(replstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
  8397. + strncat(temp, replstr, strlen(replstr));
  8398. + }
  8399. + strncat(temp, "\n", strlen("\n"));
  8400. + }
  8401. + } else if (strcasecmp (field, "Recommends") == 0) {
  8402. + if (pkg->recommends_count) {
  8403. + char recstr[LINE_LEN];
  8404. + len = 15;
  8405. + for(i = 0; i < pkg->recommends_count; i++) {
  8406. + len = len + (strlen( pkg->recommends_str[i])+5);
  8407. + }
  8408. + temp = (char *)realloc(temp,len);
  8409. + if ( temp == NULL ){
  8410. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8411. + return NULL;
  8412. + }
  8413. + temp[0]='\0';
  8414. + strncpy(temp, "Recommends:", 13);
  8415. + for(i = 0; i < pkg->recommends_count; i++) {
  8416. + snprintf(recstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
  8417. + strncat(temp, recstr, strlen(recstr));
  8418. + }
  8419. + strncat(temp, "\n", strlen("\n"));
  8420. + }
  8421. + } else {
  8422. + goto UNKNOWN_FMT_FIELD;
  8423. + }
  8424. + }
  8425. + break;
  8426. + case 's':
  8427. + case 'S': {
  8428. + /* Section | Size | Source | Status | Suggests */
  8429. + if (strcasecmp(field, "Section") == 0) {
  8430. + /* Section */
  8431. + if (pkg->section) {
  8432. + temp = (char *)realloc(temp,strlen(pkg->section)+11);
  8433. + if ( temp == NULL ){
  8434. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8435. + return NULL;
  8436. + }
  8437. + temp[0]='\0';
  8438. + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
  8439. + }
  8440. + } else if (strcasecmp(field, "Size") == 0) {
  8441. + /* Size */
  8442. + if (pkg->size) {
  8443. + temp = (char *)realloc(temp,strlen(pkg->size)+8);
  8444. + if ( temp == NULL ){
  8445. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8446. + return NULL;
  8447. + }
  8448. + temp[0]='\0';
  8449. + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
  8450. + }
  8451. + } else if (strcasecmp(field, "Source") == 0) {
  8452. + /* Source */
  8453. + if (pkg->source) {
  8454. + temp = (char *)realloc(temp,strlen(pkg->source)+10);
  8455. + if ( temp == NULL ){
  8456. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8457. + return NULL;
  8458. + }
  8459. + temp[0]='\0';
  8460. + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
  8461. + }
  8462. + } else if (strcasecmp(field, "Status") == 0) {
  8463. + /* Status */
  8464. + /* Benjamin Pineau note: we should avoid direct usage of
  8465. + * strlen(arg) without keeping "arg" for later free()
  8466. + */
  8467. + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
  8468. + char *pstat=pkg_state_status_to_str(pkg->state_status);
  8469. + char *pwant=pkg_state_want_to_str(pkg->state_want);
  8470. +
  8471. + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
  8472. + temp = (char *)realloc(temp,sum_of_sizes);
  8473. + if ( temp == NULL ){
  8474. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8475. + return NULL;
  8476. + }
  8477. + temp[0]='\0';
  8478. + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
  8479. + free(pflag);
  8480. + free(pwant);
  8481. + if(pstat) /* pfstat can be NULL if ENOMEM */
  8482. + free(pstat);
  8483. + } else if (strcasecmp(field, "Suggests") == 0) {
  8484. + if (pkg->suggests_count) {
  8485. + int i;
  8486. + char sugstr[LINE_LEN];
  8487. + len = 13;
  8488. + for(i = 0; i < pkg->suggests_count; i++) {
  8489. + len = len + (strlen(pkg->suggests_str[i])+5);
  8490. + }
  8491. + temp = (char *)realloc(temp,len);
  8492. + if ( temp == NULL ){
  8493. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8494. + return NULL;
  8495. + }
  8496. + temp[0]='\0';
  8497. + strncpy(temp, "Suggests:", 10);
  8498. + for(i = 0; i < pkg->suggests_count; i++) {
  8499. + snprintf(sugstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
  8500. + strncat(temp, sugstr, strlen(sugstr));
  8501. + }
  8502. + strncat(temp, "\n", strlen("\n"));
  8503. + }
  8504. + } else {
  8505. + goto UNKNOWN_FMT_FIELD;
  8506. + }
  8507. + }
  8508. + break;
  8509. + case 'v':
  8510. + case 'V': {
  8511. + /* Version */
  8512. + char *version = pkg_version_str_alloc(pkg);
  8513. + temp = (char *)realloc(temp,strlen(version)+14);
  8514. + if ( temp == NULL ){
  8515. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8516. + return NULL;
  8517. + }
  8518. + temp[0]='\0';
  8519. + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
  8520. + free(version);
  8521. + }
  8522. + break;
  8523. + default:
  8524. + goto UNKNOWN_FMT_FIELD;
  8525. + }
  8526. +
  8527. + if ( strlen(temp)<2 ) {
  8528. + temp[0]='\0';
  8529. + }
  8530. + return temp;
  8531. +
  8532. + UNKNOWN_FMT_FIELD:
  8533. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
  8534. + if ( strlen(temp)<2 ) {
  8535. + temp[0]='\0';
  8536. + }
  8537. +
  8538. + return temp;
  8539. +}
  8540. +
  8541. +void pkg_print_info(pkg_t *pkg, FILE *file)
  8542. +{
  8543. + char * buff;
  8544. + if (pkg == NULL) {
  8545. + return;
  8546. + }
  8547. +
  8548. + buff = pkg_formatted_info(pkg);
  8549. + if ( buff == NULL )
  8550. + return;
  8551. + if (strlen(buff)>2){
  8552. + fwrite(buff, 1, strlen(buff), file);
  8553. + }
  8554. + free(buff);
  8555. +}
  8556. +
  8557. +void pkg_print_status(pkg_t * pkg, FILE * file)
  8558. +{
  8559. + if (pkg == NULL) {
  8560. + return;
  8561. + }
  8562. +
  8563. + /* XXX: QUESTION: Do we actually want more fields here? The
  8564. + original idea was to save space by installing only what was
  8565. + needed for actual computation, (package, version, status,
  8566. + essential, conffiles). The assumption is that all other fields
  8567. + can be found in th available file.
  8568. +
  8569. + But, someone proposed the idea to make it possible to
  8570. + reconstruct a .ipk from an installed package, (ie. for beaming
  8571. + from one handheld to another). So, maybe we actually want a few
  8572. + more fields here, (depends, suggests, etc.), so that that would
  8573. + be guaranteed to work even in the absence of more information
  8574. + from the available file.
  8575. +
  8576. + 28-MAR-03: kergoth and I discussed this yesterday. We think
  8577. + the essential info needs to be here for all installed packages
  8578. + because they may not appear in the Packages files on various
  8579. + feeds. Furthermore, one should be able to install from URL or
  8580. + local storage without requiring a Packages file from any feed.
  8581. + -Jamey
  8582. + */
  8583. + pkg_print_field(pkg, file, "Package");
  8584. + pkg_print_field(pkg, file, "Version");
  8585. + pkg_print_field(pkg, file, "Depends");
  8586. + pkg_print_field(pkg, file, "Recommends");
  8587. + pkg_print_field(pkg, file, "Suggests");
  8588. + pkg_print_field(pkg, file, "Provides");
  8589. + pkg_print_field(pkg, file, "Replaces");
  8590. + pkg_print_field(pkg, file, "Conflicts");
  8591. + pkg_print_field(pkg, file, "Status");
  8592. + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
  8593. + pkg_print_field(pkg, file, "Architecture");
  8594. + pkg_print_field(pkg, file, "Conffiles");
  8595. + pkg_print_field(pkg, file, "Installed-Time");
  8596. + fputs("\n", file);
  8597. +}
  8598. +
  8599. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
  8600. +{
  8601. + char *buff;
  8602. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8603. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
  8604. + __FUNCTION__, field);
  8605. + }
  8606. + buff = pkg_formatted_field(pkg, field);
  8607. + if (strlen(buff)>2) {
  8608. + fprintf(file, "%s", buff);
  8609. + fflush(file);
  8610. + }
  8611. + free(buff);
  8612. + return;
  8613. +}
  8614. +
  8615. +/*
  8616. + * libdpkg - Debian packaging suite library routines
  8617. + * vercmp.c - comparison of version numbers
  8618. + *
  8619. + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
  8620. + */
  8621. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
  8622. +{
  8623. + int r;
  8624. +
  8625. + if (pkg->epoch > ref_pkg->epoch) {
  8626. + return 1;
  8627. + }
  8628. +
  8629. + if (pkg->epoch < ref_pkg->epoch) {
  8630. + return -1;
  8631. + }
  8632. +
  8633. + r = verrevcmp(pkg->version, ref_pkg->version);
  8634. + if (r) {
  8635. + return r;
  8636. + }
  8637. +
  8638. +#ifdef USE_DEBVERSION
  8639. + r = verrevcmp(pkg->revision, ref_pkg->revision);
  8640. + if (r) {
  8641. + return r;
  8642. + }
  8643. +
  8644. + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
  8645. +#endif
  8646. +
  8647. + return r;
  8648. +}
  8649. +
  8650. +int verrevcmp(const char *val, const char *ref)
  8651. +{
  8652. + int vc, rc;
  8653. + long vl, rl;
  8654. + const char *vp, *rp;
  8655. + const char *vsep, *rsep;
  8656. +
  8657. + if (!val) val= "";
  8658. + if (!ref) ref= "";
  8659. + for (;;) {
  8660. + vp= val; while (*vp && !isdigit(*vp)) vp++;
  8661. + rp= ref; while (*rp && !isdigit(*rp)) rp++;
  8662. + for (;;) {
  8663. + vc= (val == vp) ? 0 : *val++;
  8664. + rc= (ref == rp) ? 0 : *ref++;
  8665. + if (!rc && !vc) break;
  8666. + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
  8667. + if (rc && !isalpha(rc)) rc += 256;
  8668. + if (vc != rc) return vc - rc;
  8669. + }
  8670. + val= vp;
  8671. + ref= rp;
  8672. + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
  8673. + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
  8674. + if (vl != rl) return vl - rl;
  8675. +
  8676. + vc = *val;
  8677. + rc = *ref;
  8678. + vsep = strchr(".-", vc);
  8679. + rsep = strchr(".-", rc);
  8680. + if (vsep && !rsep) return -1;
  8681. + if (!vsep && rsep) return +1;
  8682. +
  8683. + if (!*val && !*ref) return 0;
  8684. + if (!*val) return -1;
  8685. + if (!*ref) return +1;
  8686. + }
  8687. +}
  8688. +
  8689. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
  8690. +{
  8691. + int r;
  8692. +
  8693. + r = pkg_compare_versions(it, ref);
  8694. +
  8695. + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
  8696. + return r <= 0;
  8697. + }
  8698. +
  8699. + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
  8700. + return r >= 0;
  8701. + }
  8702. +
  8703. + if (strcmp(op, "<<") == 0) {
  8704. + return r < 0;
  8705. + }
  8706. +
  8707. + if (strcmp(op, ">>") == 0) {
  8708. + return r > 0;
  8709. + }
  8710. +
  8711. + if (strcmp(op, "=") == 0) {
  8712. + return r == 0;
  8713. + }
  8714. +
  8715. + fprintf(stderr, "unknown operator: %s", op);
  8716. + return 0;
  8717. +}
  8718. +
  8719. +int pkg_name_version_and_architecture_compare(pkg_t *p1, pkg_t *p2)
  8720. +{
  8721. + const pkg_t *a = *(const pkg_t **)p1;
  8722. + const pkg_t *b = *(const pkg_t **)p2;
  8723. + int namecmp;
  8724. + int vercmp;
  8725. + if (!a->name || !b->name) {
  8726. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8727. + a, a->name, b, b->name);
  8728. + return 0;
  8729. + }
  8730. +
  8731. + namecmp = strcmp(a->name, b->name);
  8732. + if (namecmp)
  8733. + return namecmp;
  8734. + vercmp = pkg_compare_versions(a, b);
  8735. + if (vercmp)
  8736. + return vercmp;
  8737. + if (!a->arch_priority || !b->arch_priority) {
  8738. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
  8739. + a, a->arch_priority, b, b->arch_priority);
  8740. + return 0;
  8741. + }
  8742. + if (a->arch_priority > b->arch_priority)
  8743. + return 1;
  8744. + if (a->arch_priority < b->arch_priority)
  8745. + return -1;
  8746. + return 0;
  8747. +}
  8748. +
  8749. +int abstract_pkg_name_compare(abstract_pkg_t *p1, abstract_pkg_t *p2)
  8750. +{
  8751. + const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
  8752. + const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
  8753. + if (!a->name || !b->name) {
  8754. + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8755. + a, a->name, b, b->name);
  8756. + return 0;
  8757. + }
  8758. + return strcmp(a->name, b->name);
  8759. +}
  8760. +
  8761. +
  8762. +char *pkg_version_str_alloc(pkg_t *pkg)
  8763. +{
  8764. + char *complete_version;
  8765. + char *epoch_str;
  8766. +#ifdef USE_DEBVERSION
  8767. + char *revision_str;
  8768. + char *familiar_revision_str;
  8769. +#endif
  8770. +
  8771. + if (pkg->epoch) {
  8772. + sprintf_alloc(&epoch_str, "%lu:", (unsigned long)pkg->epoch);
  8773. + } else {
  8774. + epoch_str = strdup("");
  8775. + }
  8776. +
  8777. +#ifdef USE_DEBVERSION
  8778. + if (pkg->revision && strlen(pkg->revision)) {
  8779. + sprintf_alloc(&revision_str, "-%s", pkg->revision);
  8780. + } else {
  8781. + revision_str = strdup("");
  8782. + }
  8783. +
  8784. + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
  8785. + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
  8786. + } else {
  8787. + familiar_revision_str = strdup("");
  8788. + }
  8789. +#endif
  8790. +
  8791. +#ifdef USE_DEBVERSION
  8792. + sprintf_alloc(&complete_version, "%s%s%s%s",
  8793. + epoch_str, pkg->version, revision_str, familiar_revision_str);
  8794. +#else
  8795. + sprintf_alloc(&complete_version, "%s%s",
  8796. + epoch_str, pkg->version);
  8797. +#endif
  8798. +
  8799. + free(epoch_str);
  8800. +#ifdef USE_DEBVERSION
  8801. + free(revision_str);
  8802. + free(familiar_revision_str);
  8803. +#endif
  8804. +
  8805. + return complete_version;
  8806. +}
  8807. +
  8808. +str_list_t *pkg_get_installed_files(pkg_t *pkg)
  8809. +{
  8810. + int err;
  8811. + char *list_file_name = NULL;
  8812. + FILE *list_file = NULL;
  8813. + char *line;
  8814. + char *installed_file_name;
  8815. + int rootdirlen;
  8816. +
  8817. + pkg->installed_files_ref_cnt++;
  8818. +
  8819. + if (pkg->installed_files) {
  8820. + return pkg->installed_files;
  8821. + }
  8822. +
  8823. + pkg->installed_files = str_list_alloc();
  8824. + if (pkg->installed_files == NULL) {
  8825. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8826. + return NULL;
  8827. + }
  8828. +
  8829. + /* For uninstalled packages, get the file list firectly from the package.
  8830. + For installed packages, look at the package.list file in the database.
  8831. + */
  8832. + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
  8833. + if (pkg->local_filename == NULL) {
  8834. + return pkg->installed_files;
  8835. + }
  8836. + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
  8837. + file. In other words, change deb_extract so that it can
  8838. + simply return the file list as a char *[] rather than
  8839. + insisting on writing in to a FILE * as it does now. */
  8840. + list_file = tmpfile();
  8841. + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
  8842. + if (err) {
  8843. + fclose(list_file);
  8844. + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
  8845. + __FUNCTION__, pkg->local_filename, strerror(err));
  8846. + return pkg->installed_files;
  8847. + }
  8848. + rewind(list_file);
  8849. + } else {
  8850. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8851. + pkg->dest->info_dir, pkg->name);
  8852. + if (! file_exists(list_file_name)) {
  8853. + free(list_file_name);
  8854. + return pkg->installed_files;
  8855. + }
  8856. +
  8857. + list_file = fopen(list_file_name, "r");
  8858. + if (list_file == NULL) {
  8859. + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
  8860. + list_file_name, strerror(errno));
  8861. + free(list_file_name);
  8862. + return pkg->installed_files;
  8863. + }
  8864. + free(list_file_name);
  8865. + }
  8866. +
  8867. + rootdirlen = strlen( pkg->dest->root_dir );
  8868. + while (1) {
  8869. + char *file_name;
  8870. +
  8871. + line = file_read_line_alloc(list_file);
  8872. + if (line == NULL) {
  8873. + break;
  8874. + }
  8875. + str_chomp(line);
  8876. + file_name = line;
  8877. +
  8878. + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
  8879. + if( strncmp( pkg->dest->root_dir,
  8880. + file_name,
  8881. + rootdirlen ) ) {
  8882. + if (*file_name == '.') {
  8883. + file_name++;
  8884. + }
  8885. + if (*file_name == '/') {
  8886. + file_name++;
  8887. + }
  8888. +
  8889. + /* Freed in pkg_free_installed_files */
  8890. + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
  8891. + } else {
  8892. + // already contains root_dir as header -> ABSOLUTE
  8893. + sprintf_alloc(&installed_file_name, "%s", file_name);
  8894. + }
  8895. + str_list_append(pkg->installed_files, installed_file_name);
  8896. + free(line);
  8897. + }
  8898. +
  8899. + fclose(list_file);
  8900. +
  8901. + return pkg->installed_files;
  8902. +}
  8903. +
  8904. +/* XXX: CLEANUP: This function and it's counterpart,
  8905. + (pkg_get_installed_files), do not match our init/deinit naming
  8906. + convention. Nor the alloc/free convention. But, then again, neither
  8907. + of these conventions currrently fit the way these two functions
  8908. + work. */
  8909. +int pkg_free_installed_files(pkg_t *pkg)
  8910. +{
  8911. + str_list_elt_t *iter;
  8912. +
  8913. + pkg->installed_files_ref_cnt--;
  8914. + if (pkg->installed_files_ref_cnt > 0) {
  8915. + return 0;
  8916. + }
  8917. +
  8918. + if (pkg->installed_files) {
  8919. +
  8920. + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
  8921. + /* malloced in pkg_get_installed_files */
  8922. + free (iter->data);
  8923. + iter->data = NULL;
  8924. + }
  8925. +
  8926. + str_list_deinit(pkg->installed_files);
  8927. + }
  8928. +
  8929. + pkg->installed_files = NULL;
  8930. +
  8931. + return 0;
  8932. +}
  8933. +
  8934. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
  8935. +{
  8936. + int err;
  8937. + char *list_file_name;
  8938. +
  8939. + //I don't think pkg_free_installed_files should be called here. Jamey
  8940. + //pkg_free_installed_files(pkg);
  8941. +
  8942. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8943. + pkg->dest->info_dir, pkg->name);
  8944. + if (!conf->noaction) {
  8945. + err = unlink(list_file_name);
  8946. + free(list_file_name);
  8947. +
  8948. + if (err) {
  8949. + return errno;
  8950. + }
  8951. + }
  8952. + return 0;
  8953. +}
  8954. +
  8955. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
  8956. +{
  8957. + conffile_list_elt_t *iter;
  8958. + conffile_t *conffile;
  8959. +
  8960. + if (pkg == NULL) {
  8961. + return NULL;
  8962. + }
  8963. +
  8964. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8965. + conffile = iter->data;
  8966. +
  8967. + if (strcmp(conffile->name, file_name) == 0) {
  8968. + return conffile;
  8969. + }
  8970. + }
  8971. +
  8972. + return NULL;
  8973. +}
  8974. +
  8975. +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
  8976. + const char *script, const char *args)
  8977. +{
  8978. + int err;
  8979. + char *path;
  8980. + char *cmd;
  8981. +
  8982. + /* XXX: FEATURE: When conf->offline_root is set, we should run the
  8983. + maintainer script within a chroot environment. */
  8984. +
  8985. + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
  8986. + have scripts in pkg->tmp_unpack_dir. */
  8987. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  8988. + if (pkg->dest == NULL) {
  8989. + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
  8990. + __FUNCTION__, pkg->name);
  8991. + return EINVAL;
  8992. + }
  8993. + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
  8994. + } else {
  8995. + if (pkg->tmp_unpack_dir == NULL) {
  8996. + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
  8997. + __FUNCTION__, pkg->name);
  8998. + return EINVAL;
  8999. + }
  9000. + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
  9001. + }
  9002. +
  9003. + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
  9004. + if (conf->noaction) return 0;
  9005. +
  9006. + /* XXX: CLEANUP: There must be a better way to handle maintainer
  9007. + scripts when running with offline_root mode and/or a dest other
  9008. + than '/'. I've been playing around with some clever chroot
  9009. + tricks and I might come up with something workable. */
  9010. + if (conf->offline_root) {
  9011. + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
  9012. + }
  9013. +
  9014. + setenv("PKG_ROOT",
  9015. + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
  9016. +
  9017. + if (! file_exists(path)) {
  9018. + free(path);
  9019. + return 0;
  9020. + }
  9021. +
  9022. + if (conf->offline_root) {
  9023. + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
  9024. + free(path);
  9025. + return 0;
  9026. + }
  9027. +
  9028. + sprintf_alloc(&cmd, "%s %s", path, args);
  9029. + free(path);
  9030. +
  9031. + err = xsystem(cmd);
  9032. + free(cmd);
  9033. +
  9034. + if (err) {
  9035. + fprintf(stderr, "%s script returned status %d\n", script, err);
  9036. + return err;
  9037. + }
  9038. +
  9039. + return 0;
  9040. +}
  9041. +
  9042. +char *pkg_state_want_to_str(pkg_state_want_t sw)
  9043. +{
  9044. + int i;
  9045. +
  9046. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  9047. + if (pkg_state_want_map[i].value == sw) {
  9048. + return strdup(pkg_state_want_map[i].str);
  9049. + }
  9050. + }
  9051. +
  9052. + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
  9053. + __FUNCTION__, sw);
  9054. + return strdup("<STATE_WANT_UNKNOWN>");
  9055. +}
  9056. +
  9057. +pkg_state_want_t pkg_state_want_from_str(char *str)
  9058. +{
  9059. + int i;
  9060. +
  9061. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  9062. + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
  9063. + return pkg_state_want_map[i].value;
  9064. + }
  9065. + }
  9066. +
  9067. + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
  9068. + __FUNCTION__, str);
  9069. + return SW_UNKNOWN;
  9070. +}
  9071. +
  9072. +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
  9073. +{
  9074. + int i;
  9075. + int len = 3; /* ok\000 is minimum */
  9076. + char *str = NULL;
  9077. +
  9078. + /* clear the temporary flags before converting to string */
  9079. + sf &= SF_NONVOLATILE_FLAGS;
  9080. +
  9081. + if (sf == 0) {
  9082. + return strdup("ok");
  9083. + } else {
  9084. +
  9085. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9086. + if (sf & pkg_state_flag_map[i].value) {
  9087. + len += strlen(pkg_state_flag_map[i].str) + 1;
  9088. + }
  9089. + }
  9090. + str = malloc(len);
  9091. + if ( str == NULL ) {
  9092. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9093. + return NULL;
  9094. + }
  9095. + str[0] = 0;
  9096. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9097. + if (sf & pkg_state_flag_map[i].value) {
  9098. + strcat(str, pkg_state_flag_map[i].str);
  9099. + strcat(str, ",");
  9100. + }
  9101. + }
  9102. + len = strlen(str);
  9103. + str[len-1] = 0; /* squash last comma */
  9104. + return str;
  9105. + }
  9106. +}
  9107. +
  9108. +pkg_state_flag_t pkg_state_flag_from_str(char *str)
  9109. +{
  9110. + int i;
  9111. + int sf = SF_OK;
  9112. +
  9113. + if (strcmp(str, "ok") == 0) {
  9114. + return SF_OK;
  9115. + }
  9116. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9117. + const char *sfname = pkg_state_flag_map[i].str;
  9118. + int sfname_len = strlen(sfname);
  9119. + if (strncmp(str, sfname, sfname_len) == 0) {
  9120. + sf |= pkg_state_flag_map[i].value;
  9121. + str += sfname_len;
  9122. + if (str[0] == ',') {
  9123. + str++;
  9124. + } else {
  9125. + break;
  9126. + }
  9127. + }
  9128. + }
  9129. +
  9130. + return sf;
  9131. +}
  9132. +
  9133. +char *pkg_state_status_to_str(pkg_state_status_t ss)
  9134. +{
  9135. + int i;
  9136. +
  9137. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9138. + if (pkg_state_status_map[i].value == ss) {
  9139. + return strdup(pkg_state_status_map[i].str);
  9140. + }
  9141. + }
  9142. +
  9143. + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
  9144. + __FUNCTION__, ss);
  9145. + return strdup("<STATE_STATUS_UNKNOWN>");
  9146. +}
  9147. +
  9148. +pkg_state_status_t pkg_state_status_from_str(char *str)
  9149. +{
  9150. + int i;
  9151. +
  9152. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9153. + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
  9154. + return pkg_state_status_map[i].value;
  9155. + }
  9156. + }
  9157. +
  9158. + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
  9159. + __FUNCTION__, str);
  9160. + return SS_NOT_INSTALLED;
  9161. +}
  9162. +
  9163. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
  9164. +{
  9165. + nv_pair_list_elt_t *l;
  9166. +
  9167. + if (!pkg->architecture)
  9168. + return 1;
  9169. +
  9170. + l = conf->arch_list.head;
  9171. +
  9172. + while (l) {
  9173. + nv_pair_t *nv = l->data;
  9174. + if (strcmp(nv->name, pkg->architecture) == 0) {
  9175. + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
  9176. + return 1;
  9177. + }
  9178. + l = l->next;
  9179. + }
  9180. +
  9181. + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
  9182. + return 0;
  9183. +}
  9184. +
  9185. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
  9186. +{
  9187. + nv_pair_list_elt_t *l;
  9188. +
  9189. + l = conf->arch_list.head;
  9190. +
  9191. + while (l) {
  9192. + nv_pair_t *nv = l->data;
  9193. + if (strcmp(nv->name, archname) == 0) {
  9194. + int priority = strtol(nv->value, NULL, 0);
  9195. + return priority;
  9196. + }
  9197. + l = l->next;
  9198. + }
  9199. + return 0;
  9200. +}
  9201. +
  9202. +int pkg_info_preinstall_check(ipkg_conf_t *conf)
  9203. +{
  9204. + int i;
  9205. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9206. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  9207. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9208. +
  9209. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
  9210. + pkg_hash_fetch_available(pkg_hash, available_pkgs);
  9211. + /* update arch_priority for each package */
  9212. + for (i = 0; i < available_pkgs->len; i++) {
  9213. + pkg_t *pkg = available_pkgs->pkgs[i];
  9214. + int arch_priority = 1;
  9215. + if (!pkg)
  9216. + continue;
  9217. + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
  9218. + if (pkg->architecture)
  9219. + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
  9220. + else
  9221. + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
  9222. + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
  9223. + pkg->arch_priority = arch_priority;
  9224. + }
  9225. +
  9226. + for (i = 0; i < available_pkgs->len; i++) {
  9227. + pkg_t *pkg = available_pkgs->pkgs[i];
  9228. + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
  9229. + /* clear flags and want for any uninstallable package */
  9230. + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
  9231. + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
  9232. + pkg->state_want = SW_UNKNOWN;
  9233. + pkg->state_flag = 0;
  9234. + }
  9235. + }
  9236. + pkg_vec_free(available_pkgs);
  9237. +
  9238. + /* update the file owner data structure */
  9239. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
  9240. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9241. + for (i = 0; i < installed_pkgs->len; i++) {
  9242. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9243. + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
  9244. + str_list_elt_t *iter;
  9245. + if (installed_files == NULL) {
  9246. + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
  9247. + break;
  9248. + }
  9249. + for (iter = installed_files->head; iter; iter = iter->next) {
  9250. + char *installed_file = iter->data;
  9251. + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
  9252. + file_hash_set_file_owner(conf, installed_file, pkg);
  9253. + }
  9254. + }
  9255. + pkg_vec_free(installed_pkgs);
  9256. +
  9257. + return 0;
  9258. +}
  9259. +
  9260. +struct pkg_write_filelist_data {
  9261. + ipkg_conf_t *conf;
  9262. + pkg_t *pkg;
  9263. + FILE *stream;
  9264. +};
  9265. +
  9266. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
  9267. +{
  9268. + struct pkg_write_filelist_data *data = data_;
  9269. + pkg_t *entry = entry_;
  9270. + if (entry == data->pkg) {
  9271. + fprintf(data->stream, "%s\n", key);
  9272. + }
  9273. +}
  9274. +
  9275. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
  9276. +{
  9277. + struct pkg_write_filelist_data data;
  9278. + char *list_file_name = NULL;
  9279. + int err = 0;
  9280. +
  9281. + if (!pkg) {
  9282. + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
  9283. + return -EINVAL;
  9284. + }
  9285. + ipkg_message(conf, IPKG_INFO,
  9286. + " creating %s.list file\n", pkg->name);
  9287. + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
  9288. + if (!list_file_name) {
  9289. + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
  9290. + return -ENOMEM;
  9291. + }
  9292. + ipkg_message(conf, IPKG_INFO,
  9293. + " creating %s file for pkg %s\n", list_file_name, pkg->name);
  9294. + data.stream = fopen(list_file_name, "w");
  9295. + if (!data.stream) {
  9296. + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
  9297. + list_file_name, strerror(errno));
  9298. + return errno;
  9299. + }
  9300. + data.pkg = pkg;
  9301. + data.conf = conf;
  9302. + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
  9303. + fclose(data.stream);
  9304. + free(list_file_name);
  9305. +
  9306. + return err;
  9307. +}
  9308. +
  9309. +int pkg_write_changed_filelists(ipkg_conf_t *conf)
  9310. +{
  9311. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9312. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9313. + int i;
  9314. + int err;
  9315. + if (conf->noaction)
  9316. + return 0;
  9317. +
  9318. + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
  9319. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9320. + for (i = 0; i < installed_pkgs->len; i++) {
  9321. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9322. + if (pkg->state_flag & SF_FILELIST_CHANGED) {
  9323. + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
  9324. + err = pkg_write_filelist(conf, pkg);
  9325. + if (err)
  9326. + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
  9327. + }
  9328. + }
  9329. + return 0;
  9330. +}
  9331. diff -Nur busybox-1.13.4.orig/archival/libipkg/pkg.h busybox-1.13.4/archival/libipkg/pkg.h
  9332. --- busybox-1.13.4.orig/archival/libipkg/pkg.h 1970-01-01 01:00:00.000000000 +0100
  9333. +++ busybox-1.13.4/archival/libipkg/pkg.h 2009-05-31 15:40:37.109997565 +0200
  9334. @@ -0,0 +1,229 @@
  9335. +/* pkg.h - the itsy package management system
  9336. +
  9337. + Carl D. Worth
  9338. +
  9339. + Copyright (C) 2001 University of Southern California
  9340. +
  9341. + This program is free software; you can redistribute it and/or
  9342. + modify it under the terms of the GNU General Public License as
  9343. + published by the Free Software Foundation; either version 2, or (at
  9344. + your option) any later version.
  9345. +
  9346. + This program is distributed in the hope that it will be useful, but
  9347. + WITHOUT ANY WARRANTY; without even the implied warranty of
  9348. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9349. + General Public License for more details.
  9350. +*/
  9351. +
  9352. +#ifndef PKG_H
  9353. +#define PKG_H
  9354. +
  9355. +#include <sys/types.h>
  9356. +#include <sys/stat.h>
  9357. +#include <unistd.h>
  9358. +
  9359. +#include "pkg_vec.h"
  9360. +#include "str_list.h"
  9361. +#include "pkg_src.h"
  9362. +#include "pkg_dest.h"
  9363. +#include "ipkg_conf.h"
  9364. +#include "conffile_list.h"
  9365. +
  9366. +struct ipkg_conf;
  9367. +
  9368. +/* I think "Size" is currently the shortest field name */
  9369. +#define PKG_MINIMUM_FIELD_NAME_LEN 4
  9370. +
  9371. +enum pkg_state_want
  9372. +{
  9373. + SW_UNKNOWN = 1,
  9374. + SW_INSTALL,
  9375. + SW_DEINSTALL,
  9376. + SW_PURGE,
  9377. + SW_LAST_STATE_WANT
  9378. +};
  9379. +typedef enum pkg_state_want pkg_state_want_t;
  9380. +
  9381. +enum pkg_state_flag
  9382. +{
  9383. + SF_OK = 0,
  9384. + SF_REINSTREQ = 1,
  9385. + SF_HOLD = 2, /* do not upgrade version */
  9386. + SF_REPLACE = 4, /* replace this package */
  9387. + SF_NOPRUNE = 8, /* do not remove obsolete files */
  9388. + SF_PREFER = 16, /* prefer this version */
  9389. + SF_OBSOLETE = 32, /* old package in upgrade pair */
  9390. + SF_MARKED = 64, /* temporary mark */
  9391. + SF_FILELIST_CHANGED = 128, /* needs filelist written */
  9392. + SF_USER = 256,
  9393. + SF_LAST_STATE_FLAG
  9394. +};
  9395. +typedef enum pkg_state_flag pkg_state_flag_t;
  9396. +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
  9397. +
  9398. +enum pkg_state_status
  9399. +{
  9400. + SS_NOT_INSTALLED = 1,
  9401. + SS_UNPACKED,
  9402. + SS_HALF_CONFIGURED,
  9403. + SS_INSTALLED,
  9404. + SS_HALF_INSTALLED,
  9405. + SS_CONFIG_FILES,
  9406. + SS_POST_INST_FAILED,
  9407. + SS_REMOVAL_FAILED,
  9408. + SS_LAST_STATE_STATUS
  9409. +};
  9410. +typedef enum pkg_state_status pkg_state_status_t;
  9411. +
  9412. +struct abstract_pkg{
  9413. + char * name;
  9414. + int dependencies_checked;
  9415. + pkg_vec_t * pkgs;
  9416. + pkg_state_status_t state_status;
  9417. + pkg_state_flag_t state_flag;
  9418. + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
  9419. + abstract_pkg_vec_t * provided_by;
  9420. + abstract_pkg_vec_t * replaced_by;
  9421. +};
  9422. +
  9423. +#include "pkg_depends.h"
  9424. +
  9425. +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
  9426. +
  9427. + The 3 version fields should go into a single version struct. (This
  9428. + is especially important since, currently, pkg->version can easily
  9429. + be mistaken for pkg_verson_str_alloc(pkg) although they are very
  9430. + distinct. This has been the source of multiple bugs.
  9431. +
  9432. + The 3 state fields could possibly also go into their own struct.
  9433. +
  9434. + All fields which deal with lists of packages, (Depends,
  9435. + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
  9436. + be handled by a single struct in pkg_t
  9437. +
  9438. + All string fields for which there is a small set of possible
  9439. + values, (section, maintainer, architecture, maybe version?), that
  9440. + are reused among different packages -- for all such packages we
  9441. + should move from "char *"s to some atom datatype to share data
  9442. + storage and use less memory. We might even do reference counting,
  9443. + but probably not since most often we only create new pkg_t structs,
  9444. + we don't often free them. */
  9445. +struct pkg
  9446. +{
  9447. + char *name;
  9448. + unsigned long epoch;
  9449. + char *version;
  9450. + char *revision;
  9451. + char *familiar_revision;
  9452. + pkg_src_t *src;
  9453. + pkg_dest_t *dest;
  9454. + char *architecture;
  9455. + char *section;
  9456. + char *maintainer;
  9457. + char *description;
  9458. + pkg_state_want_t state_want;
  9459. + pkg_state_flag_t state_flag;
  9460. + pkg_state_status_t state_status;
  9461. + char **depends_str;
  9462. + int depends_count;
  9463. + char **pre_depends_str;
  9464. + int pre_depends_count;
  9465. + char **recommends_str;
  9466. + int recommends_count;
  9467. + char **suggests_str;
  9468. + int suggests_count;
  9469. + compound_depend_t * depends;
  9470. +
  9471. + /* Abhaya: new conflicts */
  9472. + char **conflicts_str;
  9473. + compound_depend_t * conflicts;
  9474. + int conflicts_count;
  9475. +
  9476. + char **replaces_str;
  9477. + int replaces_count;
  9478. + abstract_pkg_t ** replaces;
  9479. +
  9480. + char **provides_str;
  9481. + int provides_count;
  9482. + abstract_pkg_t ** provides;
  9483. +
  9484. + abstract_pkg_t *parent;
  9485. +
  9486. + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
  9487. +
  9488. + char *filename;
  9489. + char *local_filename;
  9490. + char *url;
  9491. + char *tmp_unpack_dir;
  9492. + char *md5sum;
  9493. + char *size;
  9494. + char *installed_size;
  9495. + char *priority;
  9496. + char *source;
  9497. + conffile_list_t conffiles;
  9498. + time_t installed_time;
  9499. + /* As pointer for lazy evaluation */
  9500. + str_list_t *installed_files;
  9501. + /* XXX: CLEANUP: I'd like to perhaps come up with a better
  9502. + mechanism to avoid the problem here, (which is that the
  9503. + installed_files list was being freed from an inner loop while
  9504. + still being used within an outer loop. */
  9505. + int installed_files_ref_cnt;
  9506. + int essential;
  9507. + int arch_priority;
  9508. +/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */
  9509. + int provided_by_hand;
  9510. +};
  9511. +
  9512. +pkg_t *pkg_new(void);
  9513. +int pkg_init(pkg_t *pkg);
  9514. +void pkg_deinit(pkg_t *pkg);
  9515. +int pkg_init_from_file(pkg_t *pkg, const char *filename);
  9516. +abstract_pkg_t *abstract_pkg_new(void);
  9517. +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
  9518. +
  9519. +/*
  9520. + * merges fields from newpkg into oldpkg.
  9521. + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
  9522. + */
  9523. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
  9524. +
  9525. +char *pkg_version_str_alloc(pkg_t *pkg);
  9526. +
  9527. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
  9528. +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b);
  9529. +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b);
  9530. +
  9531. +char * pkg_formatted_info(pkg_t *pkg );
  9532. +char * pkg_formatted_field(pkg_t *pkg, const char *field );
  9533. +
  9534. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
  9535. +
  9536. +void pkg_print_info(pkg_t *pkg, FILE *file);
  9537. +void pkg_print_status(pkg_t * pkg, FILE * file);
  9538. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
  9539. +str_list_t *pkg_get_installed_files(pkg_t *pkg);
  9540. +int pkg_free_installed_files(pkg_t *pkg);
  9541. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
  9542. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
  9543. +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
  9544. + const char *script, const char *args);
  9545. +
  9546. +/* enum mappings */
  9547. +char *pkg_state_want_to_str(pkg_state_want_t sw);
  9548. +pkg_state_want_t pkg_state_want_from_str(char *str);
  9549. +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
  9550. +pkg_state_flag_t pkg_state_flag_from_str(char *str);
  9551. +char *pkg_state_status_to_str(pkg_state_status_t ss);
  9552. +pkg_state_status_t pkg_state_status_from_str(char *str);
  9553. +
  9554. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
  9555. +
  9556. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
  9557. +int pkg_info_preinstall_check(ipkg_conf_t *conf);
  9558. +int pkg_free_installed_files(pkg_t *pkg);
  9559. +
  9560. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
  9561. +int pkg_write_changed_filelists(ipkg_conf_t *conf);
  9562. +
  9563. +#endif
  9564. diff -Nur busybox-1.13.4.orig/archival/libipkg/pkg_depends.c busybox-1.13.4/archival/libipkg/pkg_depends.c
  9565. --- busybox-1.13.4.orig/archival/libipkg/pkg_depends.c 1970-01-01 01:00:00.000000000 +0100
  9566. +++ busybox-1.13.4/archival/libipkg/pkg_depends.c 2009-05-31 15:40:37.093995246 +0200
  9567. @@ -0,0 +1,1032 @@
  9568. +/* pkg_depends.c - the itsy package management system
  9569. +
  9570. + Steven M. Ayer
  9571. +
  9572. + Copyright (C) 2002 Compaq Computer Corporation
  9573. +
  9574. + This program is free software; you can redistribute it and/or
  9575. + modify it under the terms of the GNU General Public License as
  9576. + published by the Free Software Foundation; either version 2, or (at
  9577. + your option) any later version.
  9578. +
  9579. + This program is distributed in the hope that it will be useful, but
  9580. + WITHOUT ANY WARRANTY; without even the implied warranty of
  9581. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9582. + General Public License for more details.
  9583. +*/
  9584. +
  9585. +#include "ipkg.h"
  9586. +#include <errno.h>
  9587. +#include <ctype.h>
  9588. +
  9589. +#include "pkg.h"
  9590. +#include "ipkg_utils.h"
  9591. +#include "pkg_hash.h"
  9592. +#include "ipkg_message.h"
  9593. +#include "pkg_parse.h"
  9594. +#include "hash_table.h"
  9595. +
  9596. +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
  9597. +static depend_t * depend_init(void);
  9598. +static void depend_deinit(depend_t *d);
  9599. +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
  9600. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
  9601. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
  9602. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg);
  9603. +
  9604. +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
  9605. +{
  9606. + depend_t *depend = (depend_t *)cdata;
  9607. + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
  9608. + return 1;
  9609. + else
  9610. + return 0;
  9611. +}
  9612. +
  9613. +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
  9614. +{
  9615. + depend_t *depend = (depend_t *)cdata;
  9616. +#if 0
  9617. + pkg_t * temp = pkg_new();
  9618. + int comparison;
  9619. + parseVersion(temp, depend->version);
  9620. + comparison = pkg_compare_versions(pkg, temp);
  9621. + free(temp);
  9622. +
  9623. + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
  9624. + __FUNCTION__, pkg->name, pkg->version,
  9625. + depend, depend->constraint, depend->version,
  9626. + comparison, version_constraints_satisfied(depend, pkg));
  9627. +#endif
  9628. + if (version_constraints_satisfied(depend, pkg))
  9629. + return 1;
  9630. + else
  9631. + return 0;
  9632. +}
  9633. +
  9634. +/* returns ndependences or negative error value */
  9635. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
  9636. + pkg_vec_t *unsatisfied, char *** unresolved)
  9637. +{
  9638. + pkg_t * satisfier_entry_pkg;
  9639. + register int i, j, k, l;
  9640. + int count, found;
  9641. + char ** the_lost;
  9642. + abstract_pkg_t * ab_pkg;
  9643. +
  9644. + /*
  9645. + * this is a setup to check for redundant/cyclic dependency checks,
  9646. + * which are marked at the abstract_pkg level
  9647. + */
  9648. + if (!(ab_pkg = pkg->parent)) {
  9649. + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
  9650. + *unresolved = NULL;
  9651. + return 0;
  9652. + }
  9653. + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
  9654. + *unresolved = NULL;
  9655. + return 0;
  9656. + } else {
  9657. + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
  9658. + }
  9659. + /**/
  9660. +
  9661. + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
  9662. + if (!count){
  9663. + *unresolved = NULL;
  9664. + return 0;
  9665. + }
  9666. +
  9667. + the_lost = NULL;
  9668. +
  9669. + /* foreach dependency */
  9670. + for (i = 0; i < count; i++) {
  9671. + compound_depend_t * compound_depend = &pkg->depends[i];
  9672. + depend_t ** possible_satisfiers = compound_depend->possibilities;;
  9673. + found = 0;
  9674. + satisfier_entry_pkg = NULL;
  9675. +
  9676. + if (compound_depend->type == GREEDY_DEPEND) {
  9677. + /* foreach possible satisfier */
  9678. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9679. + /* foreach provided_by, which includes the abstract_pkg itself */
  9680. + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
  9681. + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
  9682. + int nposs = ab_provider_vec->len;
  9683. + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
  9684. + for (l = 0; l < nposs; l++) {
  9685. + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
  9686. + /* if no depends on this one, try the first package that Provides this one */
  9687. + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
  9688. + continue;
  9689. + }
  9690. +
  9691. + /* cruise this possiblity's pkg_vec looking for an installed version */
  9692. + for (k = 0; k < test_vec->len; k++) {
  9693. + pkg_t *pkg_scout = test_vec->pkgs[k];
  9694. + /* not installed, and not already known about? */
  9695. + if ((pkg_scout->state_want != SW_INSTALL)
  9696. + && !pkg_scout->parent->dependencies_checked
  9697. + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
  9698. + char ** newstuff = NULL;
  9699. + int rc;
  9700. + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
  9701. + /* check for not-already-installed dependencies */
  9702. + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
  9703. + pkg_scout,
  9704. + tmp_vec,
  9705. + &newstuff);
  9706. + if (newstuff == NULL) {
  9707. + int ok = 1;
  9708. + for (i = 0; i < rc; i++) {
  9709. + pkg_t *p = tmp_vec->pkgs[i];
  9710. + if (p->state_want == SW_INSTALL)
  9711. + continue;
  9712. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
  9713. + ok = 0;
  9714. + break;
  9715. + }
  9716. + pkg_vec_free (tmp_vec);
  9717. + if (ok) {
  9718. + /* mark this one for installation */
  9719. + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
  9720. + pkg_vec_insert(unsatisfied, pkg_scout);
  9721. + }
  9722. + } else {
  9723. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
  9724. + free (newstuff);
  9725. + }
  9726. + }
  9727. + }
  9728. + }
  9729. + }
  9730. +
  9731. + continue;
  9732. + }
  9733. +
  9734. + /* foreach possible satisfier, look for installed package */
  9735. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9736. + /* foreach provided_by, which includes the abstract_pkg itself */
  9737. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9738. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9739. + pkg_t *satisfying_pkg =
  9740. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9741. + pkg_installed_and_constraint_satisfied,
  9742. + dependence_to_satisfy, 1);
  9743. + /* Being that I can't test constraing in pkg_hash, I will test it here */
  9744. + if (satisfying_pkg != NULL) {
  9745. + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9746. + satisfying_pkg = NULL;
  9747. + }
  9748. + }
  9749. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
  9750. + if (satisfying_pkg != NULL) {
  9751. + found = 1;
  9752. + break;
  9753. + }
  9754. +
  9755. + }
  9756. + /* if nothing installed matches, then look for uninstalled satisfier */
  9757. + if (!found) {
  9758. + /* foreach possible satisfier, look for installed package */
  9759. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9760. + /* foreach provided_by, which includes the abstract_pkg itself */
  9761. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9762. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9763. + pkg_t *satisfying_pkg =
  9764. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9765. + pkg_constraint_satisfied,
  9766. + dependence_to_satisfy, 1);
  9767. + /* Being that I can't test constraing in pkg_hash, I will test it here too */
  9768. + if (satisfying_pkg != NULL) {
  9769. + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9770. + satisfying_pkg = NULL;
  9771. + }
  9772. + }
  9773. +
  9774. + /* user request overrides package recommendation */
  9775. + if (satisfying_pkg != NULL
  9776. + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
  9777. + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
  9778. + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
  9779. + pkg->name, satisfying_pkg->name);
  9780. + continue;
  9781. + }
  9782. +
  9783. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
  9784. + if (satisfying_pkg != NULL) {
  9785. + satisfier_entry_pkg = satisfying_pkg;
  9786. + break;
  9787. + }
  9788. + }
  9789. + }
  9790. +
  9791. + /* we didn't find one, add something to the unsatisfied vector */
  9792. + if (!found) {
  9793. + if (!satisfier_entry_pkg) {
  9794. + /* failure to meet recommendations is not an error */
  9795. + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
  9796. + the_lost = add_unresolved_dep(pkg, the_lost, i);
  9797. + else
  9798. + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
  9799. + pkg->name, compound_depend->possibilities[0]->pkg->name);
  9800. + }
  9801. + else {
  9802. + if (compound_depend->type == SUGGEST) {
  9803. + /* just mention it politely */
  9804. + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
  9805. + pkg->name, satisfier_entry_pkg->name);
  9806. + } else {
  9807. + char ** newstuff = NULL;
  9808. +
  9809. + if (satisfier_entry_pkg != pkg &&
  9810. + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
  9811. + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
  9812. + pkg_hash_fetch_unsatisfied_dependencies(conf,
  9813. + satisfier_entry_pkg,
  9814. + unsatisfied,
  9815. + &newstuff);
  9816. + the_lost = merge_unresolved(the_lost, newstuff);
  9817. + }
  9818. + }
  9819. + }
  9820. + }
  9821. + }
  9822. + *unresolved = the_lost;
  9823. +
  9824. + return unsatisfied->len;
  9825. +}
  9826. +
  9827. +/*checking for conflicts !in replaces
  9828. + If a packages conflicts with another but is also replacing it, I should not consider it a
  9829. + really conflicts
  9830. + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
  9831. +*/
  9832. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
  9833. +{
  9834. + int i ;
  9835. + int replaces_count = pkg->replaces_count;
  9836. + abstract_pkg_t **replaces;
  9837. +
  9838. + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
  9839. + return 0;
  9840. +
  9841. + replaces = pkg->replaces;
  9842. +
  9843. + for (i = 0; i < replaces_count; i++) {
  9844. + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
  9845. + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
  9846. + return 1;
  9847. + }
  9848. + }
  9849. + return 0;
  9850. +
  9851. +}
  9852. +
  9853. +
  9854. +/* Abhaya: added support for conflicts */
  9855. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg)
  9856. +{
  9857. + pkg_vec_t * installed_conflicts, * test_vec;
  9858. + compound_depend_t * conflicts;
  9859. + depend_t ** possible_satisfiers;
  9860. + depend_t * possible_satisfier;
  9861. + register int i, j, k;
  9862. + int count;
  9863. + abstract_pkg_t * ab_pkg;
  9864. + pkg_t **pkg_scouts;
  9865. + pkg_t *pkg_scout;
  9866. +
  9867. + /*
  9868. + * this is a setup to check for redundant/cyclic dependency checks,
  9869. + * which are marked at the abstract_pkg level
  9870. + */
  9871. + if(!(ab_pkg = pkg->parent)){
  9872. + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
  9873. + return (pkg_vec_t *)NULL;
  9874. + }
  9875. +
  9876. + conflicts = pkg->conflicts;
  9877. + if(!conflicts){
  9878. + return (pkg_vec_t *)NULL;
  9879. + }
  9880. + installed_conflicts = pkg_vec_alloc();
  9881. +
  9882. + count = pkg->conflicts_count;
  9883. +
  9884. +
  9885. +
  9886. + /* foreach conflict */
  9887. + for(i = 0; i < pkg->conflicts_count; i++){
  9888. +
  9889. + possible_satisfiers = conflicts->possibilities;
  9890. +
  9891. + /* foreach possible satisfier */
  9892. + for(j = 0; j < conflicts->possibility_count; j++){
  9893. + possible_satisfier = possible_satisfiers[j];
  9894. + if (!possible_satisfier)
  9895. + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
  9896. + if (!possible_satisfier->pkg)
  9897. + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
  9898. + test_vec = possible_satisfier->pkg->pkgs;
  9899. + if (test_vec) {
  9900. + /* pkg_vec found, it is an actual package conflict
  9901. + * cruise this possiblity's pkg_vec looking for an installed version */
  9902. + pkg_scouts = test_vec->pkgs;
  9903. + for(k = 0; k < test_vec->len; k++){
  9904. + pkg_scout = pkg_scouts[k];
  9905. + if (!pkg_scout) {
  9906. + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
  9907. + continue;
  9908. + }
  9909. + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
  9910. + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
  9911. + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
  9912. + pkg_vec_insert(installed_conflicts, pkg_scout);
  9913. + }
  9914. + }
  9915. + }
  9916. + }
  9917. + }
  9918. + conflicts++;
  9919. + }
  9920. +
  9921. + if (installed_conflicts->len)
  9922. + return installed_conflicts;
  9923. + pkg_vec_free(installed_conflicts);
  9924. + return (pkg_vec_t *)NULL;
  9925. +}
  9926. +
  9927. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
  9928. +{
  9929. + pkg_t * temp;
  9930. + int comparison;
  9931. +
  9932. + if(depends->constraint == NONE)
  9933. + return 1;
  9934. +
  9935. + temp = pkg_new();
  9936. +
  9937. + parseVersion(temp, depends->version);
  9938. +
  9939. + comparison = pkg_compare_versions(pkg, temp);
  9940. +
  9941. + free(temp);
  9942. +
  9943. + if((depends->constraint == EARLIER) &&
  9944. + (comparison < 0))
  9945. + return 1;
  9946. + else if((depends->constraint == LATER) &&
  9947. + (comparison > 0))
  9948. + return 1;
  9949. + else if(comparison == 0)
  9950. + return 1;
  9951. + else if((depends->constraint == LATER_EQUAL) &&
  9952. + (comparison >= 0))
  9953. + return 1;
  9954. + else if((depends->constraint == EARLIER_EQUAL) &&
  9955. + (comparison <= 0))
  9956. + return 1;
  9957. +
  9958. + return 0;
  9959. +}
  9960. +
  9961. +int pkg_dependence_satisfiable(depend_t *depend)
  9962. +{
  9963. + abstract_pkg_t *apkg = depend->pkg;
  9964. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9965. + int n_providers = provider_apkgs->len;
  9966. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9967. + pkg_vec_t *pkg_vec;
  9968. + int n_pkgs ;
  9969. + int i;
  9970. + int j;
  9971. +
  9972. + for (i = 0; i < n_providers; i++) {
  9973. + abstract_pkg_t *papkg = apkgs[i];
  9974. + pkg_vec = papkg->pkgs;
  9975. + if (pkg_vec) {
  9976. + n_pkgs = pkg_vec->len;
  9977. + for (j = 0; j < n_pkgs; j++) {
  9978. + pkg_t *pkg = pkg_vec->pkgs[j];
  9979. + if (version_constraints_satisfied(depend, pkg)) {
  9980. + return 1;
  9981. + }
  9982. + }
  9983. + }
  9984. + }
  9985. + return 0;
  9986. +}
  9987. +
  9988. +int pkg_dependence_satisfied(depend_t *depend)
  9989. +{
  9990. + abstract_pkg_t *apkg = depend->pkg;
  9991. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9992. + int n_providers = provider_apkgs->len;
  9993. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9994. + int i;
  9995. + int n_pkgs;
  9996. + int j;
  9997. +
  9998. + for (i = 0; i < n_providers; i++) {
  9999. + abstract_pkg_t *papkg = apkgs[i];
  10000. + pkg_vec_t *pkg_vec = papkg->pkgs;
  10001. + if (pkg_vec) {
  10002. + n_pkgs = pkg_vec->len;
  10003. + for (j = 0; j < n_pkgs; j++) {
  10004. + pkg_t *pkg = pkg_vec->pkgs[j];
  10005. + if (version_constraints_satisfied(depend, pkg)) {
  10006. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
  10007. + return 1;
  10008. + }
  10009. + }
  10010. + }
  10011. + }
  10012. + return 0;
  10013. +}
  10014. +
  10015. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
  10016. +{
  10017. + register int i;
  10018. + pkg_t ** pkgs = vec->pkgs;
  10019. +
  10020. + for(i = 0; i < vec->len; i++)
  10021. + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
  10022. + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
  10023. + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
  10024. + return 1;
  10025. + return 0;
  10026. +}
  10027. +
  10028. +
  10029. +#ifdef DeadCode
  10030. +/**
  10031. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  10032. + * the same abstract package and 0 otherwise.
  10033. + */
  10034. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
  10035. +{
  10036. + abstract_pkg_t **provides = pkg->provides;
  10037. + int provides_count = pkg->provides_count;
  10038. + abstract_pkg_t **replacee_provides = replacee->provides;
  10039. + int replacee_provides_count = replacee->provides_count;
  10040. + int i, j;
  10041. + for (i = 0; i < provides_count; i++) {
  10042. + abstract_pkg_t *apkg = provides[i];
  10043. + for (j = 0; j < replacee_provides_count; j++) {
  10044. + abstract_pkg_t *replacee_apkg = replacee_provides[i];
  10045. + if (apkg == replacee_apkg)
  10046. + return 1;
  10047. + }
  10048. + }
  10049. + return 0;
  10050. +}
  10051. +#endif
  10052. +
  10053. +/**
  10054. + * pkg_provides_abstract returns 1 if pkg->provides contains providee
  10055. + * and 0 otherwise.
  10056. + */
  10057. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
  10058. +{
  10059. + abstract_pkg_t **provides = pkg->provides;
  10060. + int provides_count = pkg->provides_count;
  10061. + int i;
  10062. + for (i = 0; i < provides_count; i++) {
  10063. + if (provides[i] == providee)
  10064. + return 1;
  10065. + }
  10066. + return 0;
  10067. +}
  10068. +
  10069. +/**
  10070. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  10071. + * otherwise.
  10072. + */
  10073. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
  10074. +{
  10075. + abstract_pkg_t **replaces = pkg->replaces;
  10076. + int replaces_count = pkg->replaces_count;
  10077. + /* abstract_pkg_t **replacee_provides = pkg->provides;
  10078. + int replacee_provides_count = pkg->provides_count; */
  10079. + int i, j;
  10080. + for (i = 0; i < replaces_count; i++) {
  10081. + abstract_pkg_t *abstract_replacee = replaces[i];
  10082. + for (j = 0; j < replaces_count; j++) {
  10083. + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
  10084. + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
  10085. + if (replacee->provides[j] == abstract_replacee)
  10086. + return 1;
  10087. + }
  10088. + }
  10089. + return 0;
  10090. +}
  10091. +
  10092. +
  10093. +/**
  10094. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
  10095. + * otherwise.
  10096. + */
  10097. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
  10098. +{
  10099. + compound_depend_t *conflicts = pkg->conflicts;
  10100. + int conflicts_count = pkg->conflicts_count;
  10101. + int i, j;
  10102. + for (i = 0; i < conflicts_count; i++) {
  10103. + int possibility_count = conflicts[i].possibility_count;
  10104. + struct depend **possibilities = conflicts[i].possibilities;
  10105. + for (j = 0; j < possibility_count; j++) {
  10106. + if (possibilities[j]->pkg == conflictee) {
  10107. + return 1;
  10108. + }
  10109. + }
  10110. + }
  10111. + return 0;
  10112. +}
  10113. +
  10114. +/**
  10115. + * pkg_conflicts returns 1 if pkg->conflicts contains one of
  10116. + * conflictee's provides and 0 otherwise.
  10117. + */
  10118. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
  10119. +{
  10120. + compound_depend_t *conflicts = pkg->conflicts;
  10121. + int conflicts_count = pkg->conflicts_count;
  10122. + abstract_pkg_t **conflictee_provides = conflictee->provides;
  10123. + int conflictee_provides_count = conflictee->provides_count;
  10124. + int i, j, k;
  10125. + int possibility_count;
  10126. + struct depend **possibilities;
  10127. + abstract_pkg_t *possibility ;
  10128. +
  10129. + for (i = 0; i < conflicts_count; i++) {
  10130. + possibility_count = conflicts[i].possibility_count;
  10131. + possibilities = conflicts[i].possibilities;
  10132. + for (j = 0; j < possibility_count; j++) {
  10133. + possibility = possibilities[j]->pkg;
  10134. + for (k = 0; k < conflictee_provides_count; k++) {
  10135. + if (possibility == conflictee_provides[k]) {
  10136. + return 1;
  10137. + }
  10138. + }
  10139. + }
  10140. + }
  10141. + return 0;
  10142. +}
  10143. +
  10144. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
  10145. +{
  10146. + int oldlen = 0, newlen = 0;
  10147. + char ** result;
  10148. + register int i, j;
  10149. +
  10150. + if(!newstuff)
  10151. + return oldstuff;
  10152. +
  10153. + while(oldstuff && oldstuff[oldlen]) oldlen++;
  10154. + while(newstuff && newstuff[newlen]) newlen++;
  10155. +
  10156. + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
  10157. + if (result == NULL) {
  10158. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10159. + return NULL;
  10160. + }
  10161. +
  10162. + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
  10163. + *(result + i) = *(newstuff + j);
  10164. +
  10165. + *(result + i) = NULL;
  10166. +
  10167. + return result;
  10168. +}
  10169. +
  10170. +/*
  10171. + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
  10172. + * this is null terminated, no count is carried around
  10173. + */
  10174. +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
  10175. +{
  10176. + int count;
  10177. + char ** resized;
  10178. + char *depend_str = pkg_depend_str(pkg, ref_ndx);
  10179. +
  10180. + count = 0;
  10181. + while(the_lost && the_lost[count]) count++;
  10182. +
  10183. + count++; /* need one to hold the null */
  10184. + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
  10185. + if (resized == NULL) {
  10186. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10187. + return NULL;
  10188. + }
  10189. + resized[count - 1] = strdup(depend_str);
  10190. + resized[count] = NULL;
  10191. +
  10192. + return resized;
  10193. +}
  10194. +
  10195. +void printDepends(pkg_t * pkg)
  10196. +{
  10197. + register int i, j;
  10198. + compound_depend_t * depend;
  10199. + int count;
  10200. +
  10201. + count = pkg->pre_depends_count + pkg->depends_count;
  10202. +
  10203. + depend = pkg->depends;
  10204. + if(!depend){
  10205. + fprintf(stderr, "Depends pointer is NULL\n");
  10206. + return;
  10207. + }
  10208. + for(i = 0; i < count; i++){
  10209. + fprintf(stderr, "%s has %d possibilities:\n",
  10210. + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
  10211. + depend->possibility_count);
  10212. + for(j = 0; j < depend->possibility_count; j++)
  10213. + fprintf(stderr, "\t%s version %s (%d)\n",
  10214. + depend->possibilities[j]->pkg->name,
  10215. + depend->possibilities[j]->version,
  10216. + depend->possibilities[j]->constraint);
  10217. + depend++;
  10218. + }
  10219. +}
  10220. +
  10221. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  10222. +{
  10223. + register int i, j;
  10224. +
  10225. + /* every pkg provides itself */
  10226. + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
  10227. +
  10228. + if (!pkg->provides_count)
  10229. + return 0;
  10230. +
  10231. + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
  10232. + if (pkg->provides == NULL) {
  10233. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10234. + return -1 ;
  10235. + }
  10236. + pkg->provides[0] = ab_pkg;
  10237. +
  10238. + // if (strcmp(ab_pkg->name, pkg->name))
  10239. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  10240. +
  10241. + for(i = 0; i < pkg->provides_count; i++){
  10242. + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
  10243. +
  10244. + pkg->provides[i+1] = provided_abpkg;
  10245. +
  10246. + j = 0;
  10247. + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
  10248. + }
  10249. + return 0;
  10250. +}
  10251. +
  10252. +/* Abhaya: added conflicts support */
  10253. +int buildConflicts(hash_table_t * hash, pkg_t * pkg)
  10254. +{
  10255. + register int i;
  10256. + compound_depend_t * conflicts;
  10257. +
  10258. + if (!pkg->conflicts_count)
  10259. + return 0;
  10260. +
  10261. + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
  10262. + pkg->conflicts_count);
  10263. + if (conflicts == NULL) {
  10264. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10265. + return -1;
  10266. + }
  10267. + for (i = 0; i < pkg->conflicts_count; i++) {
  10268. + conflicts->type = CONFLICTS;
  10269. + parseDepends(conflicts, hash,
  10270. + pkg->conflicts_str[i]);
  10271. +#if 0
  10272. + for (j = 0; j < conflicts->possibility_count; j++) {
  10273. + depend_t *possibility = conflicts->possibilities[j];
  10274. + abstract_pkg_t *conflicting_apkg = possibility->pkg;
  10275. + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
  10276. + }
  10277. +#endif
  10278. + conflicts++;
  10279. + }
  10280. + return 0;
  10281. +}
  10282. +
  10283. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  10284. +{
  10285. + register int i, j;
  10286. +
  10287. + if (!pkg->replaces_count)
  10288. + return 0;
  10289. +
  10290. + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
  10291. + if (pkg->replaces == NULL) {
  10292. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10293. + return -1;
  10294. + }
  10295. +
  10296. + // if (strcmp(ab_pkg->name, pkg->name))
  10297. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  10298. +
  10299. + for(i = 0; i < pkg->replaces_count; i++){
  10300. + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
  10301. +
  10302. + pkg->replaces[i] = old_abpkg;
  10303. +
  10304. + j = 0;
  10305. + if (!old_abpkg->replaced_by)
  10306. + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
  10307. + if ( old_abpkg->replaced_by == NULL ){
  10308. + return -1;
  10309. + }
  10310. + /* if a package pkg both replaces and conflicts old_abpkg,
  10311. + * then add it to the replaced_by vector so that old_abpkg
  10312. + * will be upgraded to ab_pkg automatically */
  10313. + if (pkg_conflicts_abstract(pkg, old_abpkg))
  10314. + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
  10315. + }
  10316. + return 0;
  10317. +}
  10318. +
  10319. +int buildDepends(hash_table_t * hash, pkg_t * pkg)
  10320. +{
  10321. + int count;
  10322. + register int i;
  10323. + compound_depend_t * depends;
  10324. +
  10325. + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
  10326. + return 0;
  10327. +
  10328. + if (0 && pkg->pre_depends_count)
  10329. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10330. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10331. + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
  10332. + if (depends == NULL) {
  10333. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10334. + return -1;
  10335. + }
  10336. +
  10337. +
  10338. + for(i = 0; i < pkg->pre_depends_count; i++){
  10339. + parseDepends(depends, hash, pkg->pre_depends_str[i]);
  10340. + if (0 && pkg->pre_depends_count)
  10341. + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
  10342. + pkg->pre_depends_str[i], depends, depends->possibility_count);
  10343. + depends->type = PREDEPEND;
  10344. + depends++;
  10345. + }
  10346. +
  10347. + for(i = 0; i < pkg->recommends_count; i++){
  10348. + parseDepends(depends, hash, pkg->recommends_str[i]);
  10349. + if (0 && pkg->recommends_count)
  10350. + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
  10351. + pkg->recommends_str[i], depends, depends->possibility_count);
  10352. + depends->type = RECOMMEND;
  10353. + depends++;
  10354. + }
  10355. +
  10356. + for(i = 0; i < pkg->suggests_count; i++){
  10357. + parseDepends(depends, hash, pkg->suggests_str[i]);
  10358. + if (0 && pkg->suggests_count)
  10359. + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
  10360. + pkg->suggests_str[i], depends, depends->possibility_count);
  10361. + depends->type = SUGGEST;
  10362. + depends++;
  10363. + }
  10364. +
  10365. + for(i = 0; i < pkg->depends_count; i++){
  10366. + parseDepends(depends, hash, pkg->depends_str[i]);
  10367. + if (0 && pkg->depends_count)
  10368. + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
  10369. + pkg->depends_str[i], depends, depends->possibility_count);
  10370. + depends++;
  10371. + }
  10372. + return 0;
  10373. +}
  10374. +
  10375. +/*
  10376. + * pkg_depend_string: returns the depends string specified by index_.
  10377. + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
  10378. + * [0,npredepends) -> returns pre_depends_str[index_]
  10379. + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index_]
  10380. + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index_]
  10381. + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index_]
  10382. + */
  10383. +char *pkg_depend_str(pkg_t *pkg, int index_)
  10384. +{
  10385. + if (index_ < pkg->pre_depends_count) {
  10386. + return pkg->pre_depends_str[index_];
  10387. + }
  10388. + index_ -= pkg->pre_depends_count;
  10389. +
  10390. + if (index_ < pkg->recommends_count) {
  10391. + return pkg->recommends_str[index_];
  10392. + }
  10393. + index_ -= pkg->recommends_count;
  10394. +
  10395. + if (index_ < pkg->suggests_count) {
  10396. + return pkg->suggests_str[index_];
  10397. + }
  10398. + index_ -= pkg->suggests_count;
  10399. +
  10400. + if (index_ < pkg->depends_count) {
  10401. + return pkg->depends_str[index_];
  10402. + }
  10403. + fprintf(stderr, "pkg_depend_str: index_ %d out of range for pkg=%s\n", index_, pkg->name);
  10404. + return NULL;
  10405. +}
  10406. +
  10407. +void freeDepends(pkg_t *pkg)
  10408. +{
  10409. + int i;
  10410. +
  10411. + if (pkg == NULL || pkg->depends == NULL) {
  10412. + return;
  10413. + }
  10414. +
  10415. + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
  10416. + for (i=0; i < pkg->depends->possibility_count; i++) {
  10417. + depend_deinit(pkg->depends->possibilities[i]);
  10418. + }
  10419. + free(pkg->depends->possibilities);
  10420. + free(pkg->depends);
  10421. + pkg->depends = NULL;
  10422. +}
  10423. +
  10424. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
  10425. +{
  10426. + compound_depend_t * depends;
  10427. + int count, othercount;
  10428. + register int i, j;
  10429. + abstract_pkg_t * ab_depend;
  10430. + abstract_pkg_t ** temp;
  10431. +
  10432. + count = pkg->pre_depends_count + pkg->depends_count;
  10433. + depends = pkg->depends;
  10434. +
  10435. + if (0 && pkg->pre_depends_count)
  10436. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10437. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10438. + for (i = 0; i < count; i++) {
  10439. + if (0 && pkg->pre_depends_count)
  10440. + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
  10441. + for (j = 0; j < depends->possibility_count; j++){
  10442. + ab_depend = depends->possibilities[j]->pkg;
  10443. + if(!ab_depend->depended_upon_by)
  10444. + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
  10445. +
  10446. + temp = ab_depend->depended_upon_by;
  10447. + othercount = 1;
  10448. + while(*temp){
  10449. + temp++;
  10450. + othercount++;
  10451. + }
  10452. + *temp = ab_pkg;
  10453. +
  10454. + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
  10455. + (othercount + 1) * sizeof(abstract_pkg_t *));
  10456. + /* the array may have moved */
  10457. + temp = ab_depend->depended_upon_by + othercount;
  10458. + *temp = NULL;
  10459. + }
  10460. + depends++;
  10461. + }
  10462. +}
  10463. +
  10464. +static depend_t * depend_init(void)
  10465. +{
  10466. + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
  10467. + if ( d==NULL ){
  10468. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10469. + return NULL;
  10470. + }
  10471. + d->constraint = NONE;
  10472. + d->version = NULL;
  10473. + d->pkg = NULL;
  10474. +
  10475. + return d;
  10476. +}
  10477. +
  10478. +static void depend_deinit(depend_t *d)
  10479. +{
  10480. + free(d);
  10481. +}
  10482. +
  10483. +static int parseDepends(compound_depend_t *compound_depend,
  10484. + hash_table_t * hash, char * depend_str)
  10485. +{
  10486. + char * pkg_name, buffer[2048];
  10487. + int num_of_ors = 0;
  10488. + register int i;
  10489. + register char * src, * dest;
  10490. + depend_t ** possibilities;
  10491. +
  10492. + /* first count the number of ored possibilities for satisfying dependency */
  10493. + src = depend_str;
  10494. + while(*src)
  10495. + if(*src++ == '|')
  10496. + num_of_ors++;
  10497. +
  10498. + compound_depend->type = DEPEND;
  10499. +
  10500. + compound_depend->possibility_count = num_of_ors + 1;
  10501. + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
  10502. + if (!possibilities)
  10503. + return -ENOMEM;
  10504. + compound_depend->possibilities = possibilities;
  10505. +
  10506. + src = depend_str;
  10507. + for(i = 0; i < num_of_ors + 1; i++){
  10508. + possibilities[i] = depend_init();
  10509. + if (!possibilities[i])
  10510. + return -ENOMEM;
  10511. + /* gobble up just the name first */
  10512. + dest = buffer;
  10513. + while(*src &&
  10514. + !isspace(*src) &&
  10515. + (*src != '(') &&
  10516. + (*src != '*') &&
  10517. + (*src != '|'))
  10518. + *dest++ = *src++;
  10519. + *dest = '\0';
  10520. + pkg_name = trim_alloc(buffer);
  10521. + if (pkg_name == NULL )
  10522. + return -ENOMEM;
  10523. +
  10524. + /* now look at possible version info */
  10525. +
  10526. + /* skip to next chars */
  10527. + if(isspace(*src))
  10528. + while(*src && isspace(*src)) src++;
  10529. +
  10530. + /* extract constraint and version */
  10531. + if(*src == '('){
  10532. + src++;
  10533. + if(!strncmp(src, "<<", 2)){
  10534. + possibilities[i]->constraint = EARLIER;
  10535. + src += 2;
  10536. + }
  10537. + else if(!strncmp(src, "<=", 2)){
  10538. + possibilities[i]->constraint = EARLIER_EQUAL;
  10539. + src += 2;
  10540. + }
  10541. + else if(!strncmp(src, ">=", 2)){
  10542. + possibilities[i]->constraint = LATER_EQUAL;
  10543. + src += 2;
  10544. + }
  10545. + else if(!strncmp(src, ">>", 2)){
  10546. + possibilities[i]->constraint = LATER;
  10547. + src += 2;
  10548. + }
  10549. + else if(!strncmp(src, "=", 1)){
  10550. + possibilities[i]->constraint = EQUAL;
  10551. + src++;
  10552. + }
  10553. + /* should these be here to support deprecated designations; dpkg does */
  10554. + else if(!strncmp(src, "<", 1)){
  10555. + possibilities[i]->constraint = EARLIER_EQUAL;
  10556. + src++;
  10557. + }
  10558. + else if(!strncmp(src, ">", 1)){
  10559. + possibilities[i]->constraint = LATER_EQUAL;
  10560. + src++;
  10561. + }
  10562. +
  10563. + /* now we have any constraint, pass space to version string */
  10564. + while(isspace(*src)) src++;
  10565. +
  10566. + /* this would be the version string */
  10567. + dest = buffer;
  10568. + while(*src && *src != ')')
  10569. + *dest++ = *src++;
  10570. + *dest = '\0';
  10571. +
  10572. + possibilities[i]->version = trim_alloc(buffer);
  10573. + /* fprintf(stderr, "let's print the depends version string:");
  10574. + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
  10575. + if (possibilities[i]->version == NULL )
  10576. + return -ENOMEM;
  10577. +
  10578. +
  10579. + }
  10580. + /* hook up the dependency to its abstract pkg */
  10581. + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
  10582. +
  10583. + free(pkg_name);
  10584. +
  10585. + /* now get past the ) and any possible | chars */
  10586. + while(*src &&
  10587. + (isspace(*src) ||
  10588. + (*src == ')') ||
  10589. + (*src == '|')))
  10590. + src++;
  10591. + if (*src == '*')
  10592. + {
  10593. + compound_depend->type = GREEDY_DEPEND;
  10594. + src++;
  10595. + }
  10596. + }
  10597. +
  10598. + return 0;
  10599. +}
  10600. diff -Nur busybox-1.13.4.orig/archival/libipkg/pkg_depends.h busybox-1.13.4/archival/libipkg/pkg_depends.h
  10601. --- busybox-1.13.4.orig/archival/libipkg/pkg_depends.h 1970-01-01 01:00:00.000000000 +0100
  10602. +++ busybox-1.13.4/archival/libipkg/pkg_depends.h 2009-05-31 15:40:37.093995246 +0200
  10603. @@ -0,0 +1,105 @@
  10604. +/* pkg_depends.h - the itsy package management system
  10605. +
  10606. + Steven M. Ayer
  10607. +
  10608. + Copyright (C) 2002 Compaq Computer Corporation
  10609. +
  10610. + This program is free software; you can redistribute it and/or
  10611. + modify it under the terms of the GNU General Public License as
  10612. + published by the Free Software Foundation; either version 2, or (at
  10613. + your option) any later version.
  10614. +
  10615. + This program is distributed in the hope that it will be useful, but
  10616. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10617. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10618. + General Public License for more details.
  10619. +*/
  10620. +
  10621. +#ifndef PKG_DEPENDS_H
  10622. +#define PKG_DEPENDS_H
  10623. +
  10624. +#include "pkg.h"
  10625. +#include "pkg_hash.h"
  10626. +
  10627. +enum depend_type {
  10628. + PREDEPEND,
  10629. + DEPEND,
  10630. + CONFLICTS,
  10631. + GREEDY_DEPEND,
  10632. + RECOMMEND,
  10633. + SUGGEST
  10634. +};
  10635. +typedef enum depend_type depend_type_t;
  10636. +
  10637. +enum version_constraint {
  10638. + NONE,
  10639. + EARLIER,
  10640. + EARLIER_EQUAL,
  10641. + EQUAL,
  10642. + LATER_EQUAL,
  10643. + LATER
  10644. +};
  10645. +typedef enum version_constraint version_constraint_t;
  10646. +
  10647. +struct depend{
  10648. + version_constraint_t constraint;
  10649. + char * version;
  10650. + abstract_pkg_t * pkg;
  10651. +};
  10652. +typedef struct depend depend_t;
  10653. +
  10654. +struct compound_depend{
  10655. + depend_type_t type;
  10656. + int possibility_count;
  10657. + struct depend ** possibilities;
  10658. +};
  10659. +typedef struct compound_depend compound_depend_t;
  10660. +
  10661. +#include "hash_table.h"
  10662. +
  10663. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10664. +int buildConflicts(hash_table_t * hash, pkg_t * pkg);
  10665. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10666. +int buildDepends(hash_table_t * hash, pkg_t * pkg);
  10667. +
  10668. +/**
  10669. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  10670. + * the same abstract package and 0 otherwise.
  10671. + */
  10672. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
  10673. +
  10674. +/**
  10675. + * pkg_provides returns 1 if pkg->provides contains providee and 0
  10676. + * otherwise.
  10677. + */
  10678. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
  10679. +
  10680. +/**
  10681. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  10682. + * otherwise.
  10683. + */
  10684. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
  10685. +
  10686. +/**
  10687. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
  10688. + * otherwise.
  10689. + */
  10690. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
  10691. +
  10692. +/**
  10693. + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
  10694. + * otherwise.
  10695. + */
  10696. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
  10697. +
  10698. +char *pkg_depend_str(pkg_t *pkg, int index_);
  10699. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
  10700. +void freeDepends(pkg_t *pkg);
  10701. +void printDepends(pkg_t * pkg);
  10702. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
  10703. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
  10704. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg);
  10705. +int pkg_dependence_satisfiable(depend_t *depend);
  10706. +int pkg_dependence_satisfied(depend_t *depend);
  10707. +
  10708. +#endif
  10709. diff -Nur busybox-1.13.4.orig/archival/libipkg/pkg_dest.c busybox-1.13.4/archival/libipkg/pkg_dest.c
  10710. --- busybox-1.13.4.orig/archival/libipkg/pkg_dest.c 1970-01-01 01:00:00.000000000 +0100
  10711. +++ busybox-1.13.4/archival/libipkg/pkg_dest.c 2009-05-31 15:40:37.093995246 +0200
  10712. @@ -0,0 +1,92 @@
  10713. +/* pkg_dest.c - the itsy package management system
  10714. +
  10715. + Carl D. Worth
  10716. +
  10717. + Copyright (C) 2001 University of Southern California
  10718. +
  10719. + This program is free software; you can redistribute it and/or
  10720. + modify it under the terms of the GNU General Public License as
  10721. + published by the Free Software Foundation; either version 2, or (at
  10722. + your option) any later version.
  10723. +
  10724. + This program is distributed in the hope that it will be useful, but
  10725. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10726. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10727. + General Public License for more details.
  10728. +*/
  10729. +
  10730. +#include "ipkg.h"
  10731. +
  10732. +#include "pkg_dest.h"
  10733. +#include "file_util.h"
  10734. +#include "str_util.h"
  10735. +#include "sprintf_alloc.h"
  10736. +
  10737. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
  10738. +{
  10739. + dest->name = strdup(name);
  10740. +
  10741. + /* Guarantee that dest->root_dir ends with a '/' */
  10742. + if (str_ends_with(root_dir, "/")) {
  10743. + dest->root_dir = strdup(root_dir);
  10744. + } else {
  10745. + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
  10746. + }
  10747. + file_mkdir_hier(dest->root_dir, 0755);
  10748. +
  10749. + sprintf_alloc(&dest->ipkg_dir, "%s%s",
  10750. + dest->root_dir, IPKG_STATE_DIR_PREFIX);
  10751. + file_mkdir_hier(dest->ipkg_dir, 0755);
  10752. +
  10753. + if (str_starts_with (lists_dir, "/"))
  10754. + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
  10755. + else
  10756. + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
  10757. +
  10758. + file_mkdir_hier(dest->lists_dir, 0755);
  10759. +
  10760. + sprintf_alloc(&dest->info_dir, "%s/%s",
  10761. + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
  10762. + file_mkdir_hier(dest->info_dir, 0755);
  10763. +
  10764. + sprintf_alloc(&dest->status_file_name, "%s/%s",
  10765. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10766. +
  10767. + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
  10768. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10769. +
  10770. + dest->status_file = NULL;
  10771. +
  10772. + return 0;
  10773. +}
  10774. +
  10775. +void pkg_dest_deinit(pkg_dest_t *dest)
  10776. +{
  10777. + free(dest->name);
  10778. + dest->name = NULL;
  10779. +
  10780. + free(dest->root_dir);
  10781. + dest->root_dir = NULL;
  10782. +
  10783. + free(dest->ipkg_dir);
  10784. + dest->ipkg_dir = NULL;
  10785. +
  10786. + free(dest->lists_dir);
  10787. + dest->lists_dir = NULL;
  10788. +
  10789. + free(dest->info_dir);
  10790. + dest->info_dir = NULL;
  10791. +
  10792. + free(dest->status_file_name);
  10793. + dest->status_file_name = NULL;
  10794. +
  10795. + free(dest->status_file_tmp_name);
  10796. + dest->status_file_tmp_name = NULL;
  10797. +
  10798. + if (dest->status_file) {
  10799. + fclose(dest->status_file);
  10800. + }
  10801. + dest->status_file = NULL;
  10802. +
  10803. + dest->root_dir = NULL;
  10804. +}
  10805. diff -Nur busybox-1.13.4.orig/archival/libipkg/pkg_dest.h busybox-1.13.4/archival/libipkg/pkg_dest.h
  10806. --- busybox-1.13.4.orig/archival/libipkg/pkg_dest.h 1970-01-01 01:00:00.000000000 +0100
  10807. +++ busybox-1.13.4/archival/libipkg/pkg_dest.h 2009-05-31 15:40:37.097996035 +0200
  10808. @@ -0,0 +1,38 @@
  10809. +/* pkg_dest.h - the itsy package management system
  10810. +
  10811. + Carl D. Worth
  10812. +
  10813. + Copyright (C) 2001 University of Southern California
  10814. +
  10815. + This program is free software; you can redistribute it and/or
  10816. + modify it under the terms of the GNU General Public License as
  10817. + published by the Free Software Foundation; either version 2, or (at
  10818. + your option) any later version.
  10819. +
  10820. + This program is distributed in the hope that it will be useful, but
  10821. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10822. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10823. + General Public License for more details.
  10824. +*/
  10825. +
  10826. +#ifndef PKG_DEST_H
  10827. +#define PKG_DEST_H
  10828. +
  10829. +typedef struct pkg_dest pkg_dest_t;
  10830. +struct pkg_dest
  10831. +{
  10832. + char *name;
  10833. + char *root_dir;
  10834. + char *ipkg_dir;
  10835. + char *lists_dir;
  10836. + char *info_dir;
  10837. + char *status_file_name;
  10838. + char *status_file_tmp_name;
  10839. + FILE *status_file;
  10840. +};
  10841. +
  10842. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
  10843. +void pkg_dest_deinit(pkg_dest_t *dest);
  10844. +
  10845. +#endif
  10846. +
  10847. diff -Nur busybox-1.13.4.orig/archival/libipkg/pkg_dest_list.c busybox-1.13.4/archival/libipkg/pkg_dest_list.c
  10848. --- busybox-1.13.4.orig/archival/libipkg/pkg_dest_list.c 1970-01-01 01:00:00.000000000 +0100
  10849. +++ busybox-1.13.4/archival/libipkg/pkg_dest_list.c 2009-05-31 15:40:37.097996035 +0200
  10850. @@ -0,0 +1,85 @@
  10851. +/* pkg_dest_list.c - the itsy package management system
  10852. +
  10853. + Carl D. Worth
  10854. +
  10855. + Copyright (C) 2001 University of Southern California
  10856. +
  10857. + This program is free software; you can redistribute it and/or
  10858. + modify it under the terms of the GNU General Public License as
  10859. + published by the Free Software Foundation; either version 2, or (at
  10860. + your option) any later version.
  10861. +
  10862. + This program is distributed in the hope that it will be useful, but
  10863. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10864. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10865. + General Public License for more details.
  10866. +*/
  10867. +
  10868. +#include "ipkg.h"
  10869. +
  10870. +#include "pkg_dest.h"
  10871. +#include "void_list.h"
  10872. +#include "pkg_dest_list.h"
  10873. +
  10874. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
  10875. +{
  10876. + return void_list_elt_init((void_list_elt_t *) elt, data);
  10877. +}
  10878. +
  10879. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
  10880. +{
  10881. + void_list_elt_deinit((void_list_elt_t *) elt);
  10882. +}
  10883. +
  10884. +int pkg_dest_list_init(pkg_dest_list_t *list)
  10885. +{
  10886. + return void_list_init((void_list_t *) list);
  10887. +}
  10888. +
  10889. +void pkg_dest_list_deinit(pkg_dest_list_t *list)
  10890. +{
  10891. + pkg_dest_list_elt_t *iter;
  10892. + pkg_dest_t *pkg_dest;
  10893. +
  10894. + for (iter = list->head; iter; iter = iter->next) {
  10895. + pkg_dest = iter->data;
  10896. + pkg_dest_deinit(pkg_dest);
  10897. +
  10898. + /* malloced in pkg_dest_list_append */
  10899. + free(pkg_dest);
  10900. + iter->data = NULL;
  10901. + }
  10902. + void_list_deinit((void_list_t *) list);
  10903. +}
  10904. +
  10905. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10906. + const char *root_dir,const char *lists_dir)
  10907. +{
  10908. + int err;
  10909. + pkg_dest_t *pkg_dest;
  10910. +
  10911. + /* freed in plg_dest_list_deinit */
  10912. + pkg_dest = malloc(sizeof(pkg_dest_t));
  10913. + if (pkg_dest == NULL) {
  10914. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10915. + return NULL;
  10916. + }
  10917. +
  10918. + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
  10919. + err = void_list_append((void_list_t *) list, pkg_dest);
  10920. + if (err) {
  10921. + return NULL;
  10922. + }
  10923. +
  10924. + return pkg_dest;
  10925. +}
  10926. +
  10927. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
  10928. +{
  10929. + return void_list_push((void_list_t *) list, data);
  10930. +}
  10931. +
  10932. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
  10933. +{
  10934. + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
  10935. +}
  10936. diff -Nur busybox-1.13.4.orig/archival/libipkg/pkg_dest_list.h busybox-1.13.4/archival/libipkg/pkg_dest_list.h
  10937. --- busybox-1.13.4.orig/archival/libipkg/pkg_dest_list.h 1970-01-01 01:00:00.000000000 +0100
  10938. +++ busybox-1.13.4/archival/libipkg/pkg_dest_list.h 2009-05-31 15:40:37.097996035 +0200
  10939. @@ -0,0 +1,50 @@
  10940. +/* pkg_dest_list.h - the itsy package management system
  10941. +
  10942. + Carl D. Worth
  10943. +
  10944. + Copyright (C) 2001 University of Southern California
  10945. +
  10946. + This program is free software; you can redistribute it and/or
  10947. + modify it under the terms of the GNU General Public License as
  10948. + published by the Free Software Foundation; either version 2, or (at
  10949. + your option) any later version.
  10950. +
  10951. + This program is distributed in the hope that it will be useful, but
  10952. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10953. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10954. + General Public License for more details.
  10955. +*/
  10956. +
  10957. +#ifndef PKG_DEST_LIST_H
  10958. +#define PKG_DEST_LIST_H
  10959. +
  10960. +#include "pkg_dest.h"
  10961. +
  10962. +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
  10963. +struct pkg_dest_list_elt
  10964. +{
  10965. + pkg_dest_list_elt_t *next;
  10966. + pkg_dest_t *data;
  10967. +};
  10968. +
  10969. +typedef struct pkg_dest_list pkg_dest_list_t;
  10970. +struct pkg_dest_list
  10971. +{
  10972. + pkg_dest_list_elt_t pre_head;
  10973. + pkg_dest_list_elt_t *head;
  10974. + pkg_dest_list_elt_t *tail;
  10975. +};
  10976. +
  10977. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
  10978. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
  10979. +
  10980. +int pkg_dest_list_init(pkg_dest_list_t *list);
  10981. +void pkg_dest_list_deinit(pkg_dest_list_t *list);
  10982. +
  10983. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10984. + const char *root_dir,const char* lists_dir);
  10985. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
  10986. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
  10987. +
  10988. +#endif
  10989. +
  10990. diff -Nur busybox-1.13.4.orig/archival/libipkg/pkg_extract.c busybox-1.13.4/archival/libipkg/pkg_extract.c
  10991. --- busybox-1.13.4.orig/archival/libipkg/pkg_extract.c 1970-01-01 01:00:00.000000000 +0100
  10992. +++ busybox-1.13.4/archival/libipkg/pkg_extract.c 2009-05-31 15:40:37.097996035 +0200
  10993. @@ -0,0 +1,225 @@
  10994. +/* pkg_extract.c - the itsy package management system
  10995. +
  10996. + Carl D. Worth
  10997. +
  10998. + Copyright (C) 2001 University of Southern California
  10999. +
  11000. + This program is free software; you can redistribute it and/or
  11001. + modify it under the terms of the GNU General Public License as
  11002. + published by the Free Software Foundation; either version 2, or (at
  11003. + your option) any later version.
  11004. +
  11005. + This program is distributed in the hope that it will be useful, but
  11006. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11007. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11008. + General Public License for more details.
  11009. +*/
  11010. +
  11011. +#include "ipkg.h"
  11012. +#include <errno.h>
  11013. +#include <fcntl.h>
  11014. +#include <stdio.h>
  11015. +
  11016. +#include "pkg_extract.h"
  11017. +
  11018. +#include "libbb.h"
  11019. +#include "file_util.h"
  11020. +#include "sprintf_alloc.h"
  11021. +#include "unarchive.h"
  11022. +
  11023. +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
  11024. +#define IPKG_DATA_ARCHIVE "data.tar.gz"
  11025. +#define IPKG_CONTROL_FILE "control"
  11026. +
  11027. +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
  11028. +{
  11029. + archive_handle_t *archive;
  11030. + char *path;
  11031. +
  11032. + sprintf_alloc(&path, "%s/", dir);
  11033. + archive = init_handle();
  11034. + archive->src_fd = xopen(pkg->local_filename, O_RDONLY);
  11035. + archive->filter = filter_accept_list;
  11036. + llist_add_to(&(archive->accept), (char *)filename);
  11037. + archive->buffer = path;
  11038. + archive->action_data = data_extract_all_prefix;
  11039. + archive->ah_flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
  11040. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11041. + close(archive->src_fd);
  11042. + free(archive->accept);
  11043. + free(archive);
  11044. + free(path);
  11045. +}
  11046. +
  11047. +static void FAST_FUNC data_extract_file_name_to_buffer(archive_handle_t *archive)
  11048. +{
  11049. + unsigned int size = strlen(archive->file_header->name) + 2;
  11050. +
  11051. + if (archive->buffer == NULL) {
  11052. + archive->buffer = xmalloc(size);
  11053. + strcpy(archive->buffer, archive->file_header->name);
  11054. + } else {
  11055. + size += strlen(archive->buffer);
  11056. + archive->buffer = xrealloc(archive->buffer, size);
  11057. + strcat(archive->buffer, archive->file_header->name);
  11058. + }
  11059. + strcat(archive->buffer, "\n");
  11060. + data_skip(archive);
  11061. +}
  11062. +
  11063. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
  11064. +{
  11065. + archive_handle_t *archive;
  11066. + char *name;
  11067. + const char *filename = "./" IPKG_CONTROL_FILE;
  11068. +
  11069. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  11070. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  11071. + archive = init_handle();
  11072. + archive->src_fd = xopen(name, O_RDONLY);
  11073. + archive->filter = filter_accept_list;
  11074. + llist_add_to(&(archive->accept), (char *)filename);
  11075. + archive->action_data = data_extract_to_buffer;
  11076. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11077. + close(archive->src_fd);
  11078. + fputs(archive->buffer, stream);
  11079. + free(archive->buffer);
  11080. + free(archive->accept);
  11081. + free(archive);
  11082. + free(name);
  11083. +
  11084. + return 0;
  11085. +}
  11086. +
  11087. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
  11088. +{
  11089. + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
  11090. +}
  11091. +
  11092. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
  11093. +{
  11094. + archive_handle_t *archive;
  11095. + char *name;
  11096. + char *path;
  11097. +
  11098. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  11099. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  11100. + sprintf_alloc(&path, "%s/%s", dir, prefix);
  11101. + archive = init_handle();
  11102. + archive->src_fd = xopen(name, O_RDONLY);
  11103. + archive->filter = filter_accept_all;
  11104. + archive->buffer = path;
  11105. + archive->action_data = data_extract_all_prefix;
  11106. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
  11107. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11108. + close(archive->src_fd);
  11109. + free(archive);
  11110. + free(path);
  11111. + free(name);
  11112. +
  11113. + return 0;
  11114. +}
  11115. +
  11116. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
  11117. +{
  11118. + archive_handle_t *archive;
  11119. + char *name;
  11120. + char *path;
  11121. +
  11122. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  11123. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  11124. + sprintf_alloc(&path, "%s/", dir);
  11125. + archive = init_handle();
  11126. + archive->src_fd = xopen(name, O_RDONLY);
  11127. + archive->filter = filter_accept_all;
  11128. + archive->buffer = path;
  11129. + archive->action_data = data_extract_all_prefix;
  11130. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
  11131. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11132. + close(archive->src_fd);
  11133. + free(archive);
  11134. + free(path);
  11135. + free(name);
  11136. +
  11137. + return 0;
  11138. +}
  11139. +
  11140. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
  11141. +{
  11142. + int err=0;
  11143. + char *line, *data_file;
  11144. + FILE *file;
  11145. + FILE *tmp;
  11146. +
  11147. + file = fopen(file_name, "w");
  11148. + if (file == NULL) {
  11149. + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
  11150. + __FUNCTION__, file_name);
  11151. + return EINVAL;
  11152. + }
  11153. +
  11154. + tmp = tmpfile();
  11155. + if (pkg->installed_files) {
  11156. + str_list_elt_t *elt;
  11157. + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
  11158. + fprintf(file, "%s\n", elt->data);
  11159. + }
  11160. + } else {
  11161. + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
  11162. + if (err) {
  11163. + fclose(file);
  11164. + fclose(tmp);
  11165. + return err;
  11166. + }
  11167. +
  11168. + /* Fixup data file names by removing the initial '.' */
  11169. + rewind(tmp);
  11170. + while (1) {
  11171. + line = file_read_line_alloc(tmp);
  11172. + if (line == NULL) {
  11173. + break;
  11174. + }
  11175. +
  11176. + data_file = line;
  11177. + if (*data_file == '.') {
  11178. + data_file++;
  11179. + }
  11180. +
  11181. + if (*data_file != '/') {
  11182. + fputs("/", file);
  11183. + }
  11184. +
  11185. + /* I have no idea why, but this is what dpkg does */
  11186. + if (strcmp(data_file, "/\n") == 0) {
  11187. + fputs("/.\n", file);
  11188. + } else {
  11189. + fputs(data_file, file);
  11190. + }
  11191. + }
  11192. + }
  11193. + fclose(tmp);
  11194. + fclose(file);
  11195. +
  11196. + return err;
  11197. +}
  11198. +
  11199. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
  11200. +{
  11201. + archive_handle_t *archive;
  11202. + char *name;
  11203. +
  11204. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  11205. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  11206. + archive = init_handle();
  11207. + archive->src_fd = xopen(name, O_RDONLY);
  11208. + archive->filter = filter_accept_all;
  11209. + archive->action_data = data_extract_file_name_to_buffer;
  11210. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11211. + close(archive->src_fd);
  11212. + fputs(archive->buffer, file);
  11213. + free(archive->buffer);
  11214. + free(archive);
  11215. + free(name);
  11216. +
  11217. + return 0;
  11218. +}
  11219. diff -Nur busybox-1.13.4.orig/archival/libipkg/pkg_extract.h busybox-1.13.4/archival/libipkg/pkg_extract.h
  11220. --- busybox-1.13.4.orig/archival/libipkg/pkg_extract.h 1970-01-01 01:00:00.000000000 +0100
  11221. +++ busybox-1.13.4/archival/libipkg/pkg_extract.h 2009-05-31 15:40:37.105997055 +0200
  11222. @@ -0,0 +1,32 @@
  11223. +/* pkg_extract.c - the itsy package management system
  11224. +
  11225. + Carl D. Worth
  11226. +
  11227. + Copyright (C) 2001 University of Southern California
  11228. +
  11229. + This program is free software; you can redistribute it and/or
  11230. + modify it under the terms of the GNU General Public License as
  11231. + published by the Free Software Foundation; either version 2, or (at
  11232. + your option) any later version.
  11233. +
  11234. + This program is distributed in the hope that it will be useful, but
  11235. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11236. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11237. + General Public License for more details.
  11238. +*/
  11239. +
  11240. +#ifndef PKG_EXTRACT_H
  11241. +#define PKG_EXTRACT_H
  11242. +
  11243. +#include "pkg.h"
  11244. +
  11245. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
  11246. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
  11247. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
  11248. + const char *dir,
  11249. + const char *prefix);
  11250. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
  11251. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
  11252. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
  11253. +
  11254. +#endif
  11255. diff -Nur busybox-1.13.4.orig/archival/libipkg/pkg_hash.c busybox-1.13.4/archival/libipkg/pkg_hash.c
  11256. --- busybox-1.13.4.orig/archival/libipkg/pkg_hash.c 1970-01-01 01:00:00.000000000 +0100
  11257. +++ busybox-1.13.4/archival/libipkg/pkg_hash.c 2009-05-31 15:40:37.109997565 +0200
  11258. @@ -0,0 +1,623 @@
  11259. +/* ipkg_hash.c - the itsy package management system
  11260. +
  11261. + Steven M. Ayer
  11262. +
  11263. + Copyright (C) 2002 Compaq Computer Corporation
  11264. +
  11265. + This program is free software; you can redistribute it and/or
  11266. + modify it under the terms of the GNU General Public License as
  11267. + published by the Free Software Foundation; either version 2, or (at
  11268. + your option) any later version.
  11269. +
  11270. + This program is distributed in the hope that it will be useful, but
  11271. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11272. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11273. + General Public License for more details.
  11274. +*/
  11275. +
  11276. +#include "ipkg.h"
  11277. +#include <errno.h>
  11278. +#include <ctype.h>
  11279. +#include <stdlib.h>
  11280. +#include <string.h>
  11281. +
  11282. +#include "hash_table.h"
  11283. +#include "pkg.h"
  11284. +#include "ipkg_message.h"
  11285. +#include "pkg_vec.h"
  11286. +#include "pkg_hash.h"
  11287. +#include "pkg_parse.h"
  11288. +#include "ipkg_utils.h"
  11289. +
  11290. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11291. +
  11292. +/*
  11293. + * this will talk to both feeds-lists files and installed status files
  11294. + * example api:
  11295. + *
  11296. + * hash_table_t hash;
  11297. + * pkg_hash_init(name, &hash, 1000);
  11298. + * pkg_hash_add_from_file(<feed filename>);
  11299. + *
  11300. + * the query function is just there as a shell to prove to me that this
  11301. + * sort of works, but isn't far from doing something useful
  11302. + *
  11303. + * -sma, 12/21/01
  11304. + * modified: CDW 3 Jan. 2002
  11305. + */
  11306. +
  11307. +
  11308. +
  11309. +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
  11310. +{
  11311. + return hash_table_init(name, hash, len);
  11312. +}
  11313. +
  11314. +void pkg_hash_deinit(hash_table_t *hash)
  11315. +{
  11316. + hash_table_deinit(hash);
  11317. +}
  11318. +
  11319. +
  11320. +/* Find the default arch for a given package status file if none is given. */
  11321. +static char *pkg_get_default_arch(ipkg_conf_t *conf)
  11322. +{
  11323. + nv_pair_list_elt_t *l;
  11324. + const char *def_arch = HOST_CPU_STR; /* Default arch */
  11325. + int def_prio = 0; /* Other archs override this */
  11326. +
  11327. + l = conf->arch_list.head;
  11328. +
  11329. + while (l) {
  11330. + nv_pair_t *nv = l->data;
  11331. + int priority = strtol(nv->value, NULL, 0);
  11332. +
  11333. + /* Check if this arch has higher priority, and is valid */
  11334. + if ((priority > def_prio) &&
  11335. + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
  11336. + /* Our new default */
  11337. + def_prio = priority;
  11338. + def_arch = nv->name;
  11339. + }
  11340. + l = l->next;
  11341. + }
  11342. +
  11343. + return strdup(def_arch);
  11344. +}
  11345. +
  11346. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11347. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
  11348. +{
  11349. + hash_table_t *hash = &conf->pkg_hash;
  11350. + char **raw;
  11351. + char **raw_start;
  11352. + pkg_t *pkg;
  11353. +
  11354. + raw = raw_start = read_raw_pkgs_from_file(file_name);
  11355. + if (!raw)
  11356. + return -ENOMEM;
  11357. +
  11358. + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
  11359. + pkg = pkg_new();
  11360. + if (!pkg)
  11361. + return -ENOMEM;
  11362. +
  11363. + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
  11364. + if (!pkg->architecture) {
  11365. + char *version_str = pkg_version_str_alloc(pkg);
  11366. + pkg->architecture = pkg_get_default_arch(conf);
  11367. + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
  11368. + pkg->name, version_str, pkg->architecture);
  11369. + free(version_str);
  11370. + }
  11371. + hash_insert_pkg(hash, pkg, is_status_file,conf);
  11372. + } else {
  11373. + free(pkg);
  11374. + }
  11375. + }
  11376. +
  11377. + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
  11378. + memory after read_raw_pkgs_from_file */
  11379. + raw = raw_start;
  11380. + while (*raw) {
  11381. + free(*raw++);
  11382. + }
  11383. + free(raw_start);
  11384. + return 0;
  11385. +}
  11386. +
  11387. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
  11388. +{
  11389. + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
  11390. +}
  11391. +
  11392. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
  11393. +{
  11394. + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
  11395. + if (apkg)
  11396. + return NULL;
  11397. + return apkg->provided_by;
  11398. +}
  11399. +
  11400. +
  11401. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11402. + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
  11403. +{
  11404. + int i;
  11405. + int nprovides = 0;
  11406. + int nmatching = 0;
  11407. + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
  11408. + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
  11409. + abstract_pkg_vec_t *provided_apkg_vec;
  11410. + abstract_pkg_t **provided_apkgs;
  11411. + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
  11412. + pkg_t *latest_installed_parent = NULL;
  11413. + pkg_t *latest_matching = NULL;
  11414. + pkg_t *held_pkg = NULL;
  11415. + pkg_t *good_pkg_by_name = NULL;
  11416. +
  11417. + if (matching_apkgs == NULL || providers == NULL ||
  11418. + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
  11419. + return NULL;
  11420. +
  11421. + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
  11422. +
  11423. + provided_apkg_vec = apkg->provided_by;
  11424. + nprovides = provided_apkg_vec->len;
  11425. + provided_apkgs = provided_apkg_vec->pkgs;
  11426. + if (nprovides > 1)
  11427. + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
  11428. +
  11429. + /* accumulate all the providers */
  11430. + for (i = 0; i < nprovides; i++) {
  11431. + abstract_pkg_t *provider_apkg = provided_apkgs[i];
  11432. + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
  11433. + abstract_pkg_vec_insert(providers, provider_apkg);
  11434. + }
  11435. + nprovides = providers->len;
  11436. +
  11437. + for (i = 0; i < nprovides; i++) {
  11438. + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
  11439. + abstract_pkg_t *replacement_apkg = NULL;
  11440. + pkg_vec_t *vec;
  11441. +
  11442. + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
  11443. + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
  11444. + if (provider_apkg->replaced_by->len > 1) {
  11445. + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
  11446. + provider_apkg->name, replacement_apkg->name);
  11447. + }
  11448. + }
  11449. +
  11450. + if (replacement_apkg)
  11451. + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
  11452. + replacement_apkg->name, provider_apkg->name);
  11453. +
  11454. + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
  11455. + if (abstract_pkg_vec_contains(providers, replacement_apkg))
  11456. + continue;
  11457. + else
  11458. + provider_apkg = replacement_apkg;
  11459. + }
  11460. +
  11461. + if (!(vec = provider_apkg->pkgs)) {
  11462. + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
  11463. + continue;
  11464. + }
  11465. +
  11466. +
  11467. + /* now check for supported architecture */
  11468. + {
  11469. + int max_count = 0;
  11470. + int j;
  11471. +
  11472. + /* count packages matching max arch priority and keep track of last one */
  11473. + for (j = 0; j < vec->len; j++) {
  11474. + pkg_t *maybe = vec->pkgs[j];
  11475. + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
  11476. + maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
  11477. + if (maybe->arch_priority > 0) {
  11478. + max_count++;
  11479. + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
  11480. + pkg_vec_insert(matching_pkgs, maybe);
  11481. + }
  11482. + }
  11483. + }
  11484. + }
  11485. +
  11486. + if (matching_pkgs->len > 1)
  11487. + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
  11488. + if (matching_apkgs->len > 1)
  11489. + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
  11490. +
  11491. +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
  11492. + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
  11493. +/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
  11494. + Until now I always got the latest, but that breaks the downgrade option.
  11495. + If I stop at the first one, I would probably miss the new ones
  11496. + Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
  11497. + or from a Packages feed.
  11498. + 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*/
  11499. +/*Pigi*/
  11500. +
  11501. + for (i = 0; i < matching_pkgs->len; i++) {
  11502. + pkg_t *matching = matching_pkgs->pkgs[i];
  11503. + if (constraint_fcn(matching, cdata)) { /* We found it */
  11504. + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
  11505. + good_pkg_by_name = matching;
  11506. + if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
  11507. + break;
  11508. + }
  11509. + }
  11510. +
  11511. +
  11512. + for (i = 0; i < matching_pkgs->len; i++) {
  11513. + pkg_t *matching = matching_pkgs->pkgs[i];
  11514. + latest_matching = matching;
  11515. + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
  11516. + latest_installed_parent = matching;
  11517. + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
  11518. + if (held_pkg)
  11519. + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
  11520. + held_pkg->name, matching->name);
  11521. + held_pkg = matching;
  11522. + }
  11523. + }
  11524. +
  11525. + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
  11526. + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
  11527. + apkg->name, matching_apkgs->len);
  11528. + for (i = 0; i < matching_apkgs->len; i++) {
  11529. + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
  11530. + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
  11531. + }
  11532. + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
  11533. + }
  11534. +
  11535. + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
  11536. + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
  11537. + __FUNCTION__, apkg->name, matching_pkgs->len);
  11538. + for (i = 0; i < matching_pkgs->len; i++) {
  11539. + pkg_t *matching = matching_pkgs->pkgs[i];
  11540. + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
  11541. + matching->name, matching->version, matching->architecture);
  11542. + }
  11543. + }
  11544. +
  11545. + nmatching = matching_apkgs->len;
  11546. +
  11547. + pkg_vec_free(matching_pkgs);
  11548. + abstract_pkg_vec_free(matching_apkgs);
  11549. + abstract_pkg_vec_free(providers);
  11550. +
  11551. + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
  11552. + return good_pkg_by_name;
  11553. + }
  11554. + if (held_pkg) {
  11555. + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
  11556. + return held_pkg;
  11557. + }
  11558. + if (latest_installed_parent) {
  11559. + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
  11560. + return latest_installed_parent;
  11561. + }
  11562. + if (nmatching > 1) {
  11563. + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
  11564. + return NULL;
  11565. + }
  11566. + if (latest_matching) {
  11567. + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
  11568. + latest_matching->name, latest_matching->version, latest_matching->architecture);
  11569. + return latest_matching;
  11570. + }
  11571. + return NULL;
  11572. +}
  11573. +
  11574. +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
  11575. +{
  11576. + const char *name = (const char *)cdata;
  11577. + if (strcmp(pkg->name, name) == 0)
  11578. + return 1;
  11579. + else
  11580. + return 0;
  11581. +}
  11582. +
  11583. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
  11584. +{
  11585. + hash_table_t *hash = &conf->pkg_hash;
  11586. + abstract_pkg_t *apkg = NULL;
  11587. +
  11588. + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
  11589. + return NULL;
  11590. +
  11591. + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
  11592. +}
  11593. +
  11594. +
  11595. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11596. + const char *pkg_name,
  11597. + const char * version)
  11598. +{
  11599. + pkg_vec_t * vec;
  11600. + register int i;
  11601. + char *version_str = NULL;
  11602. +
  11603. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
  11604. + return NULL;
  11605. +
  11606. + for(i = 0; i < vec->len; i++) {
  11607. + version_str = pkg_version_str_alloc(vec->pkgs[i]);
  11608. + if(!strcmp(version_str, version)) {
  11609. + free(version_str);
  11610. + break;
  11611. + }
  11612. + free(version_str);
  11613. + }
  11614. +
  11615. + if(i == vec->len)
  11616. + return NULL;
  11617. +
  11618. + return vec->pkgs[i];
  11619. +}
  11620. +
  11621. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11622. + const char *pkg_name,
  11623. + pkg_dest_t *dest)
  11624. +{
  11625. + pkg_vec_t * vec;
  11626. + register int i;
  11627. +
  11628. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
  11629. + return NULL;
  11630. + }
  11631. +
  11632. + for(i = 0; i < vec->len; i++)
  11633. + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
  11634. + return vec->pkgs[i];
  11635. + }
  11636. + return NULL;
  11637. +}
  11638. +
  11639. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11640. + const char *pkg_name)
  11641. +{
  11642. + pkg_vec_t * vec;
  11643. + register int i;
  11644. +
  11645. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
  11646. + return NULL;
  11647. + }
  11648. +
  11649. + for(i = 0; i < vec->len; i++)
  11650. + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
  11651. + return vec->pkgs[i];
  11652. + }
  11653. +
  11654. + return NULL;
  11655. +}
  11656. +
  11657. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
  11658. +{
  11659. + abstract_pkg_t * ab_pkg;
  11660. +
  11661. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
  11662. + return NULL;
  11663. + }
  11664. +
  11665. + if (ab_pkg->pkgs) {
  11666. + return ab_pkg->pkgs;
  11667. + } else if (ab_pkg->provided_by) {
  11668. + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
  11669. + if (abpkg != NULL){
  11670. + return abpkg->pkgs;
  11671. + } else {
  11672. + return ab_pkg->pkgs;
  11673. + }
  11674. + } else {
  11675. + return NULL;
  11676. + }
  11677. +}
  11678. +
  11679. +static int pkg_compare_names(const void *p1, const void *p2)
  11680. +{
  11681. + const pkg_t *pkg1 = *(const pkg_t **)p1;
  11682. + const pkg_t *pkg2 = *(const pkg_t **)p2;
  11683. + if (pkg1->name == NULL)
  11684. + return 1;
  11685. + if (pkg2->name == NULL)
  11686. + return -1;
  11687. + return(strcmp(pkg1->name, pkg2->name));
  11688. +}
  11689. +
  11690. +
  11691. +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
  11692. +{
  11693. + int j;
  11694. + const char *name;
  11695. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11696. + pkg_vec_t *all = (pkg_vec_t *)data;
  11697. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11698. + name = pkg_name;
  11699. + if (pkg_vec) {
  11700. + for (j = 0; j < pkg_vec->len; j++) {
  11701. + pkg_t *pkg = pkg_vec->pkgs[j];
  11702. + pkg_vec_insert(all, pkg);
  11703. + }
  11704. + }
  11705. +}
  11706. +
  11707. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
  11708. +{
  11709. + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
  11710. + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
  11711. +}
  11712. +
  11713. +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
  11714. +{
  11715. + const char *name;
  11716. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11717. + pkg_vec_t *all = (pkg_vec_t *)data;
  11718. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11719. + int j;
  11720. + name = pkg_name;
  11721. + if (pkg_vec) {
  11722. + for (j = 0; j < pkg_vec->len; j++) {
  11723. + pkg_t *pkg = pkg_vec->pkgs[j];
  11724. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  11725. + pkg_vec_insert(all, pkg);
  11726. + }
  11727. + }
  11728. + }
  11729. +}
  11730. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
  11731. +{
  11732. + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
  11733. + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
  11734. +}
  11735. +
  11736. +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
  11737. +{
  11738. + int i;
  11739. + pkg_t *pkg;
  11740. + const char *name;
  11741. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11742. + ipkg_conf_t *conf = (ipkg_conf_t *)data;
  11743. + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
  11744. + name = pkg_name;
  11745. + fprintf(stdout, "%s\n", ab_pkg->name);
  11746. + i = 0;
  11747. + if (dependents != NULL)
  11748. + while (dependents [i] != NULL)
  11749. + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
  11750. + dependents = ab_pkg->provided_by->pkgs;
  11751. + i = 0;
  11752. + if (dependents != NULL)
  11753. + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
  11754. + printf ("\tprovided by - %s\n", dependents [i ++]->name);
  11755. + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
  11756. + if (pkg) {
  11757. + i = 0;
  11758. + while (i < pkg->depends_count)
  11759. + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
  11760. + }
  11761. +}
  11762. +void pkg_hash_dump(hash_table_t *hash, void *data)
  11763. +{
  11764. +
  11765. + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
  11766. + hash_table_foreach(hash, pkg_hash_dump_helper, data);
  11767. + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
  11768. +}
  11769. +
  11770. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11771. +{
  11772. + abstract_pkg_t * ab_pkg;
  11773. +
  11774. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
  11775. + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
  11776. +
  11777. + return ab_pkg;
  11778. +}
  11779. +
  11780. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  11781. +{
  11782. + abstract_pkg_t * ab_pkg;
  11783. + int arch_priority;
  11784. +
  11785. + if(!pkg)
  11786. + return pkg;
  11787. +
  11788. + arch_priority = pkg->arch_priority;
  11789. +
  11790. + if (buildDepends(hash, pkg)<0){
  11791. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11792. + return NULL;
  11793. + }
  11794. + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
  11795. +
  11796. + if (set_status) {
  11797. + if (pkg->state_status == SS_INSTALLED) {
  11798. + ab_pkg->state_status = SS_INSTALLED;
  11799. + } else if (pkg->state_status == SS_UNPACKED) {
  11800. + ab_pkg->state_status = SS_UNPACKED;
  11801. + }
  11802. + }
  11803. +
  11804. + if(!ab_pkg->pkgs)
  11805. + ab_pkg->pkgs = pkg_vec_alloc();
  11806. +
  11807. + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
  11808. + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
  11809. + pkg->parent = ab_pkg;
  11810. +
  11811. + if (buildProvides(hash, ab_pkg, pkg)<0){
  11812. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11813. + return NULL;
  11814. + }
  11815. + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
  11816. + if (buildConflicts(hash, pkg)<0){
  11817. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11818. + return NULL;
  11819. + }
  11820. + if (buildReplaces(hash, ab_pkg, pkg)<0) {
  11821. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11822. + return NULL;
  11823. + }
  11824. +
  11825. + buildDependedUponBy(pkg, ab_pkg);
  11826. + return pkg;
  11827. +}
  11828. +
  11829. +/*
  11830. + * this will assume that we've already determined that
  11831. + * the abstract pkg doesn't exist, 'cause we should know these things...
  11832. + */
  11833. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11834. +{
  11835. + abstract_pkg_t * ab_pkg;
  11836. +
  11837. + ab_pkg = abstract_pkg_new();
  11838. + if (ab_pkg == NULL) { return NULL; }
  11839. +
  11840. + ab_pkg->name = strdup(pkg_name);
  11841. + hash_table_insert(hash, pkg_name, ab_pkg);
  11842. +
  11843. + return ab_pkg;
  11844. +}
  11845. +
  11846. +
  11847. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
  11848. +{
  11849. + hash_table_t *file_hash = &conf->file_hash;
  11850. +
  11851. + return hash_table_get(file_hash, file_name);
  11852. +}
  11853. +
  11854. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
  11855. +{
  11856. + hash_table_t *file_hash = &conf->file_hash;
  11857. + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
  11858. + int file_name_len = strlen(file_name);
  11859. +
  11860. + if (file_name[file_name_len -1] == '/')
  11861. + return 0;
  11862. +
  11863. + if (conf->offline_root) {
  11864. + int len = strlen(conf->offline_root);
  11865. + if (strncmp(file_name, conf->offline_root, len) == 0) {
  11866. + file_name += len;
  11867. + }
  11868. + }
  11869. +
  11870. + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
  11871. + hash_table_insert(file_hash, file_name, owning_pkg);
  11872. + if (old_owning_pkg) {
  11873. + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
  11874. + /* mark this package to have its filelist written */
  11875. + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11876. + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11877. + }
  11878. + return 0;
  11879. +}
  11880. +
  11881. +
  11882. diff -Nur busybox-1.13.4.orig/archival/libipkg/pkg_hash.h busybox-1.13.4/archival/libipkg/pkg_hash.h
  11883. --- busybox-1.13.4.orig/archival/libipkg/pkg_hash.h 1970-01-01 01:00:00.000000000 +0100
  11884. +++ busybox-1.13.4/archival/libipkg/pkg_hash.h 2009-05-31 15:40:37.113996958 +0200
  11885. @@ -0,0 +1,61 @@
  11886. +/* pkg_hash.h - the itsy package management system
  11887. +
  11888. + Steven M. Ayer
  11889. +
  11890. + Copyright (C) 2002 Compaq Computer Corporation
  11891. +
  11892. + This program is free software; you can redistribute it and/or
  11893. + modify it under the terms of the GNU General Public License as
  11894. + published by the Free Software Foundation; either version 2, or (at
  11895. + your option) any later version.
  11896. +
  11897. + This program is distributed in the hope that it will be useful, but
  11898. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11899. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11900. + General Public License for more details.
  11901. +*/
  11902. +
  11903. +#ifndef PKG_HASH_H
  11904. +#define PKG_HASH_H
  11905. +
  11906. +#include "pkg.h"
  11907. +#include "pkg_vec.h"
  11908. +#include "hash_table.h"
  11909. +
  11910. +
  11911. +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
  11912. +void pkg_hash_deinit(hash_table_t *hash);
  11913. +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
  11914. +
  11915. +void pkg_hash_dump(hash_table_t *hash, void *data);
  11916. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
  11917. +
  11918. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11919. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
  11920. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
  11921. +
  11922. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11923. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
  11924. +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11925. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
  11926. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11927. + const char *pkg_name,
  11928. + const char * version);
  11929. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
  11930. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11931. + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
  11932. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
  11933. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11934. + const char *pkg_name);
  11935. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11936. + const char *pkg_name,
  11937. + pkg_dest_t *dest);
  11938. +
  11939. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
  11940. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
  11941. +
  11942. +/* XXX: shouldn't this go in pkg_vec.[ch]? */
  11943. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11944. +
  11945. +#endif
  11946. +
  11947. diff -Nur busybox-1.13.4.orig/archival/libipkg/pkg_parse.c busybox-1.13.4/archival/libipkg/pkg_parse.c
  11948. --- busybox-1.13.4.orig/archival/libipkg/pkg_parse.c 1970-01-01 01:00:00.000000000 +0100
  11949. +++ busybox-1.13.4/archival/libipkg/pkg_parse.c 2009-05-31 15:40:37.113996958 +0200
  11950. @@ -0,0 +1,368 @@
  11951. +/* pkg_parse.c - the itsy package management system
  11952. +
  11953. + Steven M. Ayer
  11954. +
  11955. + Copyright (C) 2002 Compaq Computer Corporation
  11956. +
  11957. + This program is free software; you can redistribute it and/or
  11958. + modify it under the terms of the GNU General Public License as
  11959. + published by the Free Software Foundation; either version 2, or (at
  11960. + your option) any later version.
  11961. +
  11962. + This program is distributed in the hope that it will be useful, but
  11963. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11964. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11965. + General Public License for more details.
  11966. +*/
  11967. +
  11968. +#include "ipkg.h"
  11969. +#include <errno.h>
  11970. +#include <ctype.h>
  11971. +
  11972. +#include "pkg.h"
  11973. +#include "ipkg_utils.h"
  11974. +#include "pkg_parse.h"
  11975. +
  11976. +int alterProvidesLine(char *raw, char *temp);
  11977. +
  11978. +int isGenericFieldType(char * type, char * line)
  11979. +{
  11980. + if(!strncmp(line, type, strlen(type)))
  11981. + return 1;
  11982. + return 0;
  11983. +}
  11984. +
  11985. +char * parseGenericFieldType(char * type, char * raw)
  11986. +{
  11987. + char * field_value = raw + (strlen(type) + 1);
  11988. + return trim_alloc(field_value);
  11989. +}
  11990. +
  11991. +void parseStatus(pkg_t *pkg, char * raw)
  11992. +{
  11993. + char sw_str[64], sf_str[64], ss_str[64];
  11994. +
  11995. + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
  11996. + pkg->state_want = pkg_state_want_from_str(sw_str);
  11997. + pkg->state_flag = pkg_state_flag_from_str(sf_str);
  11998. + pkg->state_status = pkg_state_status_from_str(ss_str);
  11999. +}
  12000. +
  12001. +char ** parseDependsString(char * raw, int * depends_count)
  12002. +{
  12003. + char ** depends = NULL;
  12004. + int line_count = 0;
  12005. + char buff[2048], * dest;
  12006. +
  12007. + while(raw && *raw && !isspace(*raw)) {
  12008. + raw++;
  12009. + }
  12010. +
  12011. + if(line_is_blank(raw)){
  12012. + *depends_count = line_count;
  12013. + return NULL;
  12014. + }
  12015. + while(raw && *raw){
  12016. + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
  12017. +
  12018. + while(isspace(*raw)) raw++;
  12019. +
  12020. + dest = buff;
  12021. + while((*raw != ',') && *raw)
  12022. + *dest++ = *raw++;
  12023. +
  12024. + *dest = '\0';
  12025. + depends[line_count] = trim_alloc(buff);
  12026. + if(depends[line_count] ==NULL)
  12027. + return NULL;
  12028. + line_count++;
  12029. + if(*raw == ',')
  12030. + raw++;
  12031. + }
  12032. + *depends_count = line_count;
  12033. + return depends;
  12034. +}
  12035. +
  12036. +void parseConffiles(pkg_t * pkg, char * raw)
  12037. +{
  12038. + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
  12039. +
  12040. + if(!strncmp(raw, "Conffiles:", 10))
  12041. + raw += strlen("Conffiles:");
  12042. +
  12043. + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
  12044. + conffile_list_append(&pkg->conffiles, file_name, md5sum);
  12045. + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
  12046. + while (*raw && isspace(*raw)) {
  12047. + raw++;
  12048. + }
  12049. + raw += strlen(file_name);
  12050. + while (*raw && isspace(*raw)) {
  12051. + raw++;
  12052. + }
  12053. + raw += strlen(md5sum);
  12054. + }
  12055. +}
  12056. +
  12057. +int parseVersion(pkg_t *pkg, char *raw)
  12058. +{
  12059. + char *colon, *eepochcolon;
  12060. +#ifdef USE_DEBVERSION
  12061. + char *hyphen;
  12062. +#endif
  12063. + unsigned long epoch;
  12064. +
  12065. + if (!*raw) {
  12066. + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
  12067. + return EINVAL;
  12068. + }
  12069. +
  12070. + if (strncmp(raw, "Version:", 8) == 0) {
  12071. + raw += 8;
  12072. + }
  12073. + while (*raw && isspace(*raw)) {
  12074. + raw++;
  12075. + }
  12076. +
  12077. + colon= strchr(raw,':');
  12078. + if (colon) {
  12079. + epoch= strtoul(raw,&eepochcolon,10);
  12080. + if (colon != eepochcolon) {
  12081. + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
  12082. + return EINVAL;
  12083. + }
  12084. + if (!*++colon) {
  12085. + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
  12086. + return EINVAL;
  12087. + }
  12088. + raw= colon;
  12089. + pkg->epoch= epoch;
  12090. + } else {
  12091. + pkg->epoch= 0;
  12092. + }
  12093. +
  12094. + pkg->revision = (char *)"";
  12095. + pkg->familiar_revision = (char *)"";
  12096. +
  12097. + pkg->version= malloc(strlen(raw)+1);
  12098. + if ( pkg->version == NULL ) {
  12099. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12100. + return ENOMEM;
  12101. + }
  12102. + strcpy(pkg->version, raw);
  12103. +
  12104. +#ifdef USE_DEBVERSION
  12105. + hyphen= strrchr(pkg->version,'-');
  12106. +
  12107. + if (hyphen) {
  12108. + *hyphen++= 0;
  12109. + if (strncmp("fam", hyphen, 3) == 0) {
  12110. + pkg->familiar_revision=hyphen+3;
  12111. + hyphen= strrchr(pkg->version,'-');
  12112. + if (hyphen) {
  12113. + *hyphen++= 0;
  12114. + pkg->revision = hyphen;
  12115. + }
  12116. + } else {
  12117. + pkg->revision = hyphen;
  12118. + }
  12119. + }
  12120. +#endif
  12121. +
  12122. +/*
  12123. + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
  12124. + pkg->epoch,
  12125. + pkg->version,
  12126. + pkg->revision,
  12127. + pkg->familiar_revision);
  12128. +*/
  12129. +
  12130. + return 0;
  12131. +}
  12132. +
  12133. +
  12134. +/* This code is needed to insert in first position the keyword for the aligning bug */
  12135. +
  12136. +int alterProvidesLine(char *raw, char *temp)
  12137. +{
  12138. +
  12139. +
  12140. + if (!*raw) {
  12141. + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
  12142. + return -EINVAL;
  12143. + }
  12144. +
  12145. + if ( temp == NULL ) {
  12146. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12147. + return -ENOMEM;
  12148. + }
  12149. +
  12150. + if (strncmp(raw, "Provides:", 9) == 0) {
  12151. + raw += 9;
  12152. + }
  12153. + while (*raw && isspace(*raw)) {
  12154. + raw++;
  12155. + }
  12156. +
  12157. + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
  12158. + while (*raw) {
  12159. + strncat( temp, raw++, 1);
  12160. + }
  12161. + return 0;
  12162. +
  12163. +}
  12164. +
  12165. +/* Some random thoughts from Carl:
  12166. +
  12167. + This function could be considerably simplified if we just kept
  12168. + an array of all the generic string-valued field names, and looped
  12169. + through those looking for a match. Also, these fields could perhaps
  12170. + be stored in the package as an array as well, (or, probably better,
  12171. + as an nv_pair_list_t).
  12172. +
  12173. + Fields which require special parsing or storage, (such as Depends:
  12174. + and Status:) could be handled as they are now.
  12175. +*/
  12176. +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
  12177. + to a dependency list. And, since we already have
  12178. + Depends/Pre-Depends and need to add Conflicts, Recommends, and
  12179. + Enhances, perhaps we could generalize all of these and save some
  12180. + code duplication.
  12181. +*/
  12182. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
  12183. +{
  12184. + int reading_conffiles, reading_description;
  12185. + int pkg_false_provides=1;
  12186. + char ** lines;
  12187. + char * provide=NULL;
  12188. +
  12189. + pkg->src = src;
  12190. + pkg->dest = dest;
  12191. +
  12192. + reading_conffiles = reading_description = 0;
  12193. +
  12194. + for (lines = *raw; *lines; lines++) {
  12195. + /* fprintf(stderr, "PARSING %s\n", *lines);*/
  12196. + if(isGenericFieldType((char *)"Package:", *lines))
  12197. + pkg->name = parseGenericFieldType((char *)"Package", *lines);
  12198. + else if(isGenericFieldType((char *)"Architecture:", *lines))
  12199. + pkg->architecture = parseGenericFieldType((char *)"Architecture", *lines);
  12200. + else if(isGenericFieldType((char *)"Filename:", *lines))
  12201. + pkg->filename = parseGenericFieldType((char *)"Filename", *lines);
  12202. + else if(isGenericFieldType((char *)"Section:", *lines))
  12203. + pkg->section = parseGenericFieldType((char *)"Section", *lines);
  12204. + else if(isGenericFieldType((char *)"MD5sum:", *lines))
  12205. + pkg->md5sum = parseGenericFieldType((char *)"MD5sum", *lines);
  12206. + /* The old ipkg wrote out status files with the wrong case for MD5sum,
  12207. + let's parse it either way */
  12208. + else if(isGenericFieldType((char *)"MD5Sum:", *lines))
  12209. + pkg->md5sum = parseGenericFieldType((char *)"MD5Sum", *lines);
  12210. + else if(isGenericFieldType((char *)"Size:", *lines))
  12211. + pkg->size = parseGenericFieldType((char *)"Size", *lines);
  12212. + else if(isGenericFieldType((char *)"Source:", *lines))
  12213. + pkg->source = parseGenericFieldType((char *)"Source", *lines);
  12214. + else if(isGenericFieldType((char *)"Installed-Size:", *lines))
  12215. + pkg->installed_size = parseGenericFieldType((char *)"Installed-Size", *lines);
  12216. + else if(isGenericFieldType((char *)"Installed-Time:", *lines)) {
  12217. + char *time_str = parseGenericFieldType((char *)"Installed-Time", *lines);
  12218. + pkg->installed_time = strtoul(time_str, NULL, 0);
  12219. + } else if(isGenericFieldType((char *)"Priority:", *lines))
  12220. + pkg->priority = parseGenericFieldType((char *)"Priority", *lines);
  12221. + else if(isGenericFieldType((char *)"Essential:", *lines)) {
  12222. + char *essential_value;
  12223. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12224. + if (strcmp(essential_value, "yes") == 0) {
  12225. + pkg->essential = 1;
  12226. + }
  12227. + free(essential_value);
  12228. + }
  12229. + else if(isGenericFieldType((char *)"Status", *lines))
  12230. + parseStatus(pkg, *lines);
  12231. + else if(isGenericFieldType((char *)"Version", *lines))
  12232. + parseVersion(pkg, *lines);
  12233. + else if(isGenericFieldType((char *)"Maintainer", *lines))
  12234. + pkg->maintainer = parseGenericFieldType((char *)"Maintainer", *lines);
  12235. + else if(isGenericFieldType((char *)"Conffiles", *lines)){
  12236. + parseConffiles(pkg, *lines);
  12237. + reading_conffiles = 1;
  12238. + }
  12239. + else if(isGenericFieldType((char *)"Description", *lines)) {
  12240. + pkg->description = parseGenericFieldType((char *)"Description", *lines);
  12241. + reading_conffiles = 0;
  12242. + reading_description = 1;
  12243. + }
  12244. +
  12245. + else if(isGenericFieldType((char *)"Provides", *lines)){
  12246. +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
  12247. + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
  12248. + if ( alterProvidesLine(*lines,provide) ){
  12249. + return EINVAL;
  12250. + }
  12251. + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
  12252. +/* Let's try to hack a bit here.
  12253. + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
  12254. + in alot of other places. We will remove it before writing down the status database */
  12255. + pkg_false_provides=0;
  12256. + free(provide);
  12257. + }
  12258. +
  12259. + else if(isGenericFieldType((char *)"Depends", *lines))
  12260. + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
  12261. + else if(isGenericFieldType((char *)"Pre-Depends", *lines))
  12262. + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
  12263. + else if(isGenericFieldType((char *)"Recommends", *lines))
  12264. + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
  12265. + else if(isGenericFieldType((char *)"Suggests", *lines))
  12266. + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
  12267. + /* Abhaya: support for conflicts */
  12268. + else if(isGenericFieldType((char *)"Conflicts", *lines))
  12269. + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
  12270. + else if(isGenericFieldType((char *)"Replaces", *lines))
  12271. + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
  12272. + else if(line_is_blank(*lines)) {
  12273. + lines++;
  12274. + break;
  12275. + }
  12276. + else if(**lines == ' '){
  12277. + if(reading_description) {
  12278. + /* we already know it's not blank, so the rest of description */
  12279. + pkg->description = realloc(pkg->description,
  12280. + strlen(pkg->description)
  12281. + + 1 + strlen(*lines) + 1);
  12282. + strcat(pkg->description, "\n");
  12283. + strcat(pkg->description, (*lines));
  12284. + }
  12285. + else if(reading_conffiles)
  12286. + parseConffiles(pkg, *lines);
  12287. + }
  12288. + }
  12289. + *raw = lines;
  12290. +/* If the ipk has not a Provides line, we insert our false line */
  12291. + if ( pkg_false_provides==1)
  12292. + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
  12293. +
  12294. + if (pkg->name) {
  12295. + return 0;
  12296. + } else {
  12297. + return EINVAL;
  12298. + }
  12299. +}
  12300. +
  12301. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
  12302. +{
  12303. + char ** lines;
  12304. +
  12305. + for (lines = *raw; *lines; lines++) {
  12306. + if(isGenericFieldType((char *)"Essential:", *lines)) {
  12307. + char *essential_value;
  12308. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12309. + if (strcmp(essential_value, "yes") == 0) {
  12310. + pkg->essential = 1;
  12311. + }
  12312. + free(essential_value);
  12313. + }
  12314. + }
  12315. + *raw = lines;
  12316. +
  12317. + return 0;
  12318. +}
  12319. diff -Nur busybox-1.13.4.orig/archival/libipkg/pkg_parse.h busybox-1.13.4/archival/libipkg/pkg_parse.h
  12320. --- busybox-1.13.4.orig/archival/libipkg/pkg_parse.h 1970-01-01 01:00:00.000000000 +0100
  12321. +++ busybox-1.13.4/archival/libipkg/pkg_parse.h 2009-05-31 15:40:37.113996958 +0200
  12322. @@ -0,0 +1,31 @@
  12323. +/* pkg_parse.h - the itsy package management system
  12324. +
  12325. + Steven M. Ayer
  12326. +
  12327. + Copyright (C) 2002 Compaq Computer Corporation
  12328. +
  12329. + This program is free software; you can redistribute it and/or
  12330. + modify it under the terms of the GNU General Public License as
  12331. + published by the Free Software Foundation; either version 2, or (at
  12332. + your option) any later version.
  12333. +
  12334. + This program is distributed in the hope that it will be useful, but
  12335. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12336. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12337. + General Public License for more details.
  12338. +*/
  12339. +
  12340. +#ifndef PKG_PARSE_H
  12341. +#define PKG_PARSE_H
  12342. +
  12343. +int isGenericFieldType(char * type, char * line);
  12344. +char * parseGenericFieldType(char * type, char * raw);
  12345. +void parseStatus(pkg_t *pkg, char * raw);
  12346. +int parseVersion(pkg_t *pkg, char *raw);
  12347. +char ** parseDependsString(char * raw, int * depends_count);
  12348. +int parseVersion(pkg_t *pkg, char *raw);
  12349. +void parseConffiles(pkg_t * pkg, char * raw);
  12350. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
  12351. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
  12352. +
  12353. +#endif
  12354. diff -Nur busybox-1.13.4.orig/archival/libipkg/pkg_src.c busybox-1.13.4/archival/libipkg/pkg_src.c
  12355. --- busybox-1.13.4.orig/archival/libipkg/pkg_src.c 1970-01-01 01:00:00.000000000 +0100
  12356. +++ busybox-1.13.4/archival/libipkg/pkg_src.c 2009-05-31 15:40:37.113996958 +0200
  12357. @@ -0,0 +1,43 @@
  12358. +/* pkg_src.c - the itsy package management system
  12359. +
  12360. + Carl D. Worth
  12361. +
  12362. + Copyright (C) 2001 University of Southern California
  12363. +
  12364. + This program is free software; you can redistribute it and/or
  12365. + modify it under the terms of the GNU General Public License as
  12366. + published by the Free Software Foundation; either version 2, or (at
  12367. + your option) any later version.
  12368. +
  12369. + This program is distributed in the hope that it will be useful, but
  12370. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12371. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12372. + General Public License for more details.
  12373. +*/
  12374. +
  12375. +#include "ipkg.h"
  12376. +
  12377. +#include "pkg_src.h"
  12378. +#include "str_util.h"
  12379. +
  12380. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
  12381. +{
  12382. + src->gzip = gzip;
  12383. + src->name = str_dup_safe (name);
  12384. + src->value = str_dup_safe (base_url);
  12385. + if (extra_data)
  12386. + src->extra_data = str_dup_safe (extra_data);
  12387. + else
  12388. + src->extra_data = NULL;
  12389. + return 0;
  12390. +}
  12391. +
  12392. +void pkg_src_deinit(pkg_src_t *src)
  12393. +{
  12394. + free (src->name);
  12395. + free (src->value);
  12396. + if (src->extra_data)
  12397. + free (src->extra_data);
  12398. +}
  12399. +
  12400. +
  12401. diff -Nur busybox-1.13.4.orig/archival/libipkg/pkg_src.h busybox-1.13.4/archival/libipkg/pkg_src.h
  12402. --- busybox-1.13.4.orig/archival/libipkg/pkg_src.h 1970-01-01 01:00:00.000000000 +0100
  12403. +++ busybox-1.13.4/archival/libipkg/pkg_src.h 2009-05-31 15:40:37.117996909 +0200
  12404. @@ -0,0 +1,34 @@
  12405. +/* pkg_src.h - the itsy package management system
  12406. +
  12407. + Carl D. Worth
  12408. +
  12409. + Copyright (C) 2001 University of Southern California
  12410. +
  12411. + This program is free software; you can redistribute it and/or
  12412. + modify it under the terms of the GNU General Public License as
  12413. + published by the Free Software Foundation; either version 2, or (at
  12414. + your option) any later version.
  12415. +
  12416. + This program is distributed in the hope that it will be useful, but
  12417. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12418. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12419. + General Public License for more details.
  12420. +*/
  12421. +
  12422. +#ifndef PKG_SRC_H
  12423. +#define PKG_SRC_H
  12424. +
  12425. +#include "nv_pair.h"
  12426. +
  12427. +typedef struct
  12428. +{
  12429. + char *name;
  12430. + char *value;
  12431. + char *extra_data;
  12432. + int gzip;
  12433. +} pkg_src_t;
  12434. +
  12435. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
  12436. +void pkg_src_deinit(pkg_src_t *src);
  12437. +
  12438. +#endif
  12439. diff -Nur busybox-1.13.4.orig/archival/libipkg/pkg_src_list.c busybox-1.13.4/archival/libipkg/pkg_src_list.c
  12440. --- busybox-1.13.4.orig/archival/libipkg/pkg_src_list.c 1970-01-01 01:00:00.000000000 +0100
  12441. +++ busybox-1.13.4/archival/libipkg/pkg_src_list.c 2009-05-31 15:40:37.117996909 +0200
  12442. @@ -0,0 +1,75 @@
  12443. +/* pkg_src_list.c - the itsy package management system
  12444. +
  12445. + Carl D. Worth
  12446. +
  12447. + Copyright (C) 2001 University of Southern California
  12448. +
  12449. + This program is free software; you can redistribute it and/or
  12450. + modify it under the terms of the GNU General Public License as
  12451. + published by the Free Software Foundation; either version 2, or (at
  12452. + your option) any later version.
  12453. +
  12454. + This program is distributed in the hope that it will be useful, but
  12455. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12456. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12457. + General Public License for more details.
  12458. +*/
  12459. +
  12460. +#include "ipkg.h"
  12461. +
  12462. +#include "pkg_src_list.h"
  12463. +#include "void_list.h"
  12464. +
  12465. +int pkg_src_list_init(pkg_src_list_t *list)
  12466. +{
  12467. + return void_list_init((void_list_t *) list);
  12468. +}
  12469. +
  12470. +void pkg_src_list_deinit(pkg_src_list_t *list)
  12471. +{
  12472. + pkg_src_list_elt_t *iter;
  12473. + pkg_src_t *pkg_src;
  12474. +
  12475. + for (iter = list->head; iter; iter = iter->next) {
  12476. + pkg_src = iter->data;
  12477. + pkg_src_deinit(pkg_src);
  12478. +
  12479. + /* malloced in pkg_src_list_append */
  12480. + free(pkg_src);
  12481. + iter->data = NULL;
  12482. + }
  12483. + void_list_deinit((void_list_t *) list);
  12484. +}
  12485. +
  12486. +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
  12487. + const char *name, const char *base_url, const char *extra_data,
  12488. + int gzip)
  12489. +{
  12490. + int err;
  12491. +
  12492. + /* freed in pkg_src_list_deinit */
  12493. + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
  12494. +
  12495. + if (pkg_src == NULL) {
  12496. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12497. + return NULL;
  12498. + }
  12499. + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
  12500. +
  12501. + err = void_list_append((void_list_t *) list, pkg_src);
  12502. + if (err) {
  12503. + return NULL;
  12504. + }
  12505. +
  12506. + return pkg_src;
  12507. +}
  12508. +
  12509. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
  12510. +{
  12511. + return void_list_push((void_list_t *) list, data);
  12512. +}
  12513. +
  12514. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
  12515. +{
  12516. + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
  12517. +}
  12518. diff -Nur busybox-1.13.4.orig/archival/libipkg/pkg_src_list.h busybox-1.13.4/archival/libipkg/pkg_src_list.h
  12519. --- busybox-1.13.4.orig/archival/libipkg/pkg_src_list.h 1970-01-01 01:00:00.000000000 +0100
  12520. +++ busybox-1.13.4/archival/libipkg/pkg_src_list.h 2009-05-31 15:40:37.117996909 +0200
  12521. @@ -0,0 +1,57 @@
  12522. +/* pkg_src_list.h - the itsy package management system
  12523. +
  12524. + Carl D. Worth
  12525. +
  12526. + Copyright (C) 2001 University of Southern California
  12527. +
  12528. + This program is free software; you can redistribute it and/or
  12529. + modify it under the terms of the GNU General Public License as
  12530. + published by the Free Software Foundation; either version 2, or (at
  12531. + your option) any later version.
  12532. +
  12533. + This program is distributed in the hope that it will be useful, but
  12534. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12535. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12536. + General Public License for more details.
  12537. +*/
  12538. +
  12539. +#ifndef PKG_SRC_LIST_H
  12540. +#define PKG_SRC_LIST_H
  12541. +
  12542. +#include "pkg_src.h"
  12543. +
  12544. +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
  12545. +struct pkg_src_list_elt
  12546. +{
  12547. + pkg_src_list_elt_t *next;
  12548. + pkg_src_t *data;
  12549. +};
  12550. +
  12551. +typedef struct pkg_src_list pkg_src_list_t;
  12552. +struct pkg_src_list
  12553. +{
  12554. + pkg_src_list_elt_t pre_head;
  12555. + pkg_src_list_elt_t *head;
  12556. + pkg_src_list_elt_t *tail;
  12557. +};
  12558. +
  12559. +static inline int pkg_src_list_empty(pkg_src_list_t *list)
  12560. +{
  12561. + if (list->head == NULL)
  12562. + return 1;
  12563. + else
  12564. + return 0;
  12565. +}
  12566. +
  12567. +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
  12568. +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
  12569. +
  12570. +int pkg_src_list_init(pkg_src_list_t *list);
  12571. +void pkg_src_list_deinit(pkg_src_list_t *list);
  12572. +
  12573. +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);
  12574. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
  12575. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
  12576. +
  12577. +#endif
  12578. +
  12579. diff -Nur busybox-1.13.4.orig/archival/libipkg/pkg_vec.c busybox-1.13.4/archival/libipkg/pkg_vec.c
  12580. --- busybox-1.13.4.orig/archival/libipkg/pkg_vec.c 1970-01-01 01:00:00.000000000 +0100
  12581. +++ busybox-1.13.4/archival/libipkg/pkg_vec.c 2009-05-31 15:40:37.117996909 +0200
  12582. @@ -0,0 +1,231 @@
  12583. +/* pkg_vec.c - the itsy package management system
  12584. +
  12585. + Steven M. Ayer
  12586. +
  12587. + Copyright (C) 2002 Compaq Computer Corporation
  12588. +
  12589. + This program is free software; you can redistribute it and/or
  12590. + modify it under the terms of the GNU General Public License as
  12591. + published by the Free Software Foundation; either version 2, or (at
  12592. + your option) any later version.
  12593. +
  12594. + This program is distributed in the hope that it will be useful, but
  12595. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12596. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12597. + General Public License for more details.
  12598. +*/
  12599. +
  12600. +#include <stdlib.h>
  12601. +#include <fnmatch.h>
  12602. +#include "libbb.h"
  12603. +#include "xregex.h"
  12604. +#include "ipkg.h"
  12605. +#include "pkg.h"
  12606. +
  12607. +pkg_vec_t * pkg_vec_alloc(void)
  12608. +{
  12609. + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
  12610. + if (!vec) {
  12611. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12612. + return NULL;
  12613. + }
  12614. + vec->pkgs = NULL;
  12615. + vec->len = 0;
  12616. +
  12617. + return vec;
  12618. +}
  12619. +
  12620. +void pkg_vec_free(pkg_vec_t *vec)
  12621. +{
  12622. + free(vec->pkgs);
  12623. + free(vec);
  12624. +}
  12625. +
  12626. +/*
  12627. + * assumption: all names in a vector are identical
  12628. + * assumption: all version strings are trimmed,
  12629. + * so identical versions have identical version strings,
  12630. + * implying identical packages; let's marry these
  12631. + */
  12632. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  12633. +{
  12634. + int i;
  12635. + int found = 0;
  12636. +
  12637. + /* look for a duplicate pkg by name, version, and architecture */
  12638. + for (i = 0; i < vec->len; i++){
  12639. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
  12640. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
  12641. + vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
  12642. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12643. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12644. + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
  12645. + found = 1;
  12646. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
  12647. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12648. + break;
  12649. + }
  12650. + }
  12651. +
  12652. + /* we didn't find one, add it */
  12653. + if (!found){
  12654. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
  12655. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12656. +
  12657. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12658. + vec->pkgs[vec->len] = pkg;
  12659. + vec->len++;
  12660. + return pkg;
  12661. + }
  12662. + /* update the one that we have */
  12663. + else {
  12664. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
  12665. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12666. + if (set_status) {
  12667. + /* this is from the status file, so need to merge with existing database */
  12668. + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
  12669. + pkg_merge(vec->pkgs[i], pkg, set_status);
  12670. + /* XXX: CLEANUP: It's not so polite to free something here
  12671. + that was passed in from above. */
  12672. + pkg_deinit(pkg);
  12673. + free(pkg);
  12674. + } else {
  12675. + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
  12676. + /* just overwrite the old one */
  12677. + pkg_deinit(vec->pkgs[i]);
  12678. + free(vec->pkgs[i]);
  12679. + vec->pkgs[i] = pkg;
  12680. + }
  12681. + return vec->pkgs[i];
  12682. + }
  12683. +}
  12684. +
  12685. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
  12686. +{
  12687. + int i;
  12688. + int found = 0;
  12689. +
  12690. + /* look for a duplicate pkg by name, version, and architecture */
  12691. + for (i = 0; i < vec->len; i++)
  12692. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12693. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12694. + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
  12695. + found = 1;
  12696. + break;
  12697. + }
  12698. +
  12699. + /* we didn't find one, add it */
  12700. + if(!found){
  12701. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12702. + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
  12703. + vec->len++;
  12704. + }
  12705. +}
  12706. +
  12707. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
  12708. +{
  12709. + int i;
  12710. + for (i = 0; i < vec->len; i++)
  12711. + if (vec->pkgs[i] == apkg)
  12712. + return 1;
  12713. + return 0;
  12714. +}
  12715. +
  12716. +typedef int (*compare_fcn_t)(const void *, const void *);
  12717. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
  12718. +{
  12719. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12720. +}
  12721. +
  12722. +int pkg_vec_clear_marks(pkg_vec_t *vec)
  12723. +{
  12724. + int npkgs = vec->len;
  12725. + int i;
  12726. + for (i = 0; i < npkgs; i++) {
  12727. + pkg_t *pkg = vec->pkgs[i];
  12728. + pkg->state_flag &= ~SF_MARKED;
  12729. + }
  12730. + return 0;
  12731. +}
  12732. +
  12733. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
  12734. +{
  12735. + int matching_count = 0;
  12736. + pkg_t **pkgs = vec->pkgs;
  12737. + int npkgs = vec->len;
  12738. + int i;
  12739. + for (i = 0; i < npkgs; i++) {
  12740. + pkg_t *pkg = pkgs[i];
  12741. + if (fnmatch(pattern, pkg->name, 0)==0) {
  12742. + pkg->state_flag |= SF_MARKED;
  12743. + matching_count++;
  12744. + }
  12745. + }
  12746. + return matching_count;
  12747. +}
  12748. +
  12749. +
  12750. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
  12751. +{
  12752. + abstract_pkg_vec_t * vec ;
  12753. + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
  12754. + if (!vec) {
  12755. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12756. + return NULL;
  12757. + }
  12758. + vec->pkgs = NULL;
  12759. + vec->len = 0;
  12760. +
  12761. + return vec;
  12762. +}
  12763. +
  12764. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
  12765. +{
  12766. + free(vec->pkgs);
  12767. + free(vec);
  12768. +}
  12769. +
  12770. +/*
  12771. + * assumption: all names in a vector are unique
  12772. + */
  12773. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
  12774. +{
  12775. + int i;
  12776. +
  12777. + /* look for a duplicate pkg by name */
  12778. + for(i = 0; i < vec->len; i++)
  12779. + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12780. + break;
  12781. +
  12782. + /* we didn't find one, add it */
  12783. + if(i == vec->len){
  12784. + vec->pkgs =
  12785. + (abstract_pkg_t **)
  12786. + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
  12787. + vec->pkgs[vec->len] = pkg;
  12788. + vec->len++;
  12789. + }
  12790. +}
  12791. +
  12792. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
  12793. +{
  12794. + if (vec->len > i)
  12795. + return vec->pkgs[i];
  12796. + else
  12797. + return NULL;
  12798. +}
  12799. +
  12800. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
  12801. +{
  12802. + int i;
  12803. + for (i = 0; i < vec->len; i++)
  12804. + if (vec->pkgs[i] == apkg)
  12805. + return 1;
  12806. + return 0;
  12807. +}
  12808. +
  12809. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
  12810. +{
  12811. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12812. +}
  12813. +
  12814. diff -Nur busybox-1.13.4.orig/archival/libipkg/pkg_vec.h busybox-1.13.4/archival/libipkg/pkg_vec.h
  12815. --- busybox-1.13.4.orig/archival/libipkg/pkg_vec.h 1970-01-01 01:00:00.000000000 +0100
  12816. +++ busybox-1.13.4/archival/libipkg/pkg_vec.h 2009-05-31 15:40:37.121997140 +0200
  12817. @@ -0,0 +1,62 @@
  12818. +/* pkg_vec.h - the itsy package management system
  12819. +
  12820. + Steven M. Ayer
  12821. +
  12822. + Copyright (C) 2002 Compaq Computer Corporation
  12823. +
  12824. + This program is free software; you can redistribute it and/or
  12825. + modify it under the terms of the GNU General Public License as
  12826. + published by the Free Software Foundation; either version 2, or (at
  12827. + your option) any later version.
  12828. +
  12829. + This program is distributed in the hope that it will be useful, but
  12830. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12831. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12832. + General Public License for more details.
  12833. +*/
  12834. +
  12835. +#ifndef PKG_VEC_H
  12836. +#define PKG_VEC_H
  12837. +
  12838. +typedef struct pkg pkg_t;
  12839. +typedef struct abstract_pkg abstract_pkg_t;
  12840. +
  12841. +struct pkg_vec
  12842. +{
  12843. + pkg_t **pkgs;
  12844. + int len;
  12845. +};
  12846. +typedef struct pkg_vec pkg_vec_t;
  12847. +
  12848. +struct abstract_pkg_vec
  12849. +{
  12850. + abstract_pkg_t **pkgs;
  12851. + int len;
  12852. +};
  12853. +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
  12854. +
  12855. +
  12856. +pkg_vec_t * pkg_vec_alloc(void);
  12857. +void pkg_vec_free(pkg_vec_t *vec);
  12858. +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
  12859. +
  12860. +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
  12861. +/* pkg_vec_insert_merge: might munge pkg.
  12862. +* returns the pkg that is in the pkg graph */
  12863. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
  12864. +/* this one never munges pkg */
  12865. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
  12866. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
  12867. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
  12868. +
  12869. +int pkg_vec_clear_marks(pkg_vec_t *vec);
  12870. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
  12871. +
  12872. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
  12873. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
  12874. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
  12875. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
  12876. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
  12877. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
  12878. +#endif
  12879. +
  12880. diff -Nur busybox-1.13.4.orig/archival/libipkg/sprintf_alloc.h busybox-1.13.4/archival/libipkg/sprintf_alloc.h
  12881. --- busybox-1.13.4.orig/archival/libipkg/sprintf_alloc.h 1970-01-01 01:00:00.000000000 +0100
  12882. +++ busybox-1.13.4/archival/libipkg/sprintf_alloc.h 2009-05-31 15:40:37.121997140 +0200
  12883. @@ -0,0 +1,25 @@
  12884. +/* sprintf_alloca.c -- like sprintf with memory allocation
  12885. +
  12886. + Carl D. Worth
  12887. +
  12888. + Copyright (C) 2001 University of Southern California
  12889. +
  12890. + This program is free software; you can redistribute it and/or modify
  12891. + it under the terms of the GNU General Public License as published by
  12892. + the Free Software Foundation; either version 2, or (at your option)
  12893. + any later version.
  12894. +
  12895. + This program is distributed in the hope that it will be useful,
  12896. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  12897. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12898. + GNU General Public License for more details.
  12899. +*/
  12900. +
  12901. +#ifndef SPRINTF_ALLOC_H
  12902. +#define SPRINTF_ALLOC_H
  12903. +
  12904. +#include "libbb.h"
  12905. +
  12906. +#define sprintf_alloc(str, fmt, args...) *str = xasprintf(fmt, ## args)
  12907. +
  12908. +#endif
  12909. diff -Nur busybox-1.13.4.orig/archival/libipkg/str_list.c busybox-1.13.4/archival/libipkg/str_list.c
  12910. --- busybox-1.13.4.orig/archival/libipkg/str_list.c 1970-01-01 01:00:00.000000000 +0100
  12911. +++ busybox-1.13.4/archival/libipkg/str_list.c 2009-05-31 15:40:37.121997140 +0200
  12912. @@ -0,0 +1,76 @@
  12913. +/* str_list.c - the itsy package management system
  12914. +
  12915. + Carl D. Worth
  12916. +
  12917. + Copyright (C) 2001 University of Southern California
  12918. +
  12919. + This program is free software; you can redistribute it and/or
  12920. + modify it under the terms of the GNU General Public License as
  12921. + published by the Free Software Foundation; either version 2, or (at
  12922. + your option) any later version.
  12923. +
  12924. + This program is distributed in the hope that it will be useful, but
  12925. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12926. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12927. + General Public License for more details.
  12928. +*/
  12929. +
  12930. +#include "ipkg.h"
  12931. +
  12932. +#include "str_list.h"
  12933. +
  12934. +int str_list_elt_init(str_list_elt_t *elt, char *data)
  12935. +{
  12936. + return void_list_elt_init((void_list_elt_t *) elt, data);
  12937. +}
  12938. +
  12939. +void str_list_elt_deinit(str_list_elt_t *elt)
  12940. +{
  12941. + void_list_elt_deinit((void_list_elt_t *) elt);
  12942. +}
  12943. +
  12944. +str_list_t *str_list_alloc(void)
  12945. +{
  12946. + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
  12947. + if (list)
  12948. + str_list_init(list);
  12949. + return list;
  12950. +}
  12951. +
  12952. +int str_list_init(str_list_t *list)
  12953. +{
  12954. + return void_list_init((void_list_t *) list);
  12955. +}
  12956. +
  12957. +void str_list_deinit(str_list_t *list)
  12958. +{
  12959. + void_list_deinit((void_list_t *) list);
  12960. +}
  12961. +
  12962. +int str_list_append(str_list_t *list, char *data)
  12963. +{
  12964. + return void_list_append((void_list_t *) list, data);
  12965. +}
  12966. +
  12967. +int str_list_push(str_list_t *list, char *data)
  12968. +{
  12969. + return void_list_push((void_list_t *) list, data);
  12970. +}
  12971. +
  12972. +str_list_elt_t *str_list_pop(str_list_t *list)
  12973. +{
  12974. + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
  12975. +}
  12976. +
  12977. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
  12978. +{
  12979. + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
  12980. + (void_list_elt_t **) iter);
  12981. +}
  12982. +
  12983. +char *str_list_remove_elt(str_list_t *list, const char *target_str)
  12984. +{
  12985. + return (char *)void_list_remove_elt((void_list_t *) list,
  12986. + (void *)target_str,
  12987. + (void_list_cmp_t)strcmp);
  12988. +}
  12989. diff -Nur busybox-1.13.4.orig/archival/libipkg/str_list.h busybox-1.13.4/archival/libipkg/str_list.h
  12990. --- busybox-1.13.4.orig/archival/libipkg/str_list.h 1970-01-01 01:00:00.000000000 +0100
  12991. +++ busybox-1.13.4/archival/libipkg/str_list.h 2009-05-31 15:40:37.121997140 +0200
  12992. @@ -0,0 +1,51 @@
  12993. +/* str_list.h - the itsy package management system
  12994. +
  12995. + Carl D. Worth
  12996. +
  12997. + Copyright (C) 2001 University of Southern California
  12998. +
  12999. + This program is free software; you can redistribute it and/or
  13000. + modify it under the terms of the GNU General Public License as
  13001. + published by the Free Software Foundation; either version 2, or (at
  13002. + your option) any later version.
  13003. +
  13004. + This program is distributed in the hope that it will be useful, but
  13005. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13006. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13007. + General Public License for more details.
  13008. +*/
  13009. +
  13010. +#ifndef STR_LIST_H
  13011. +#define STR_LIST_H
  13012. +
  13013. +#include "void_list.h"
  13014. +
  13015. +typedef struct str_list_elt str_list_elt_t;
  13016. +struct str_list_elt
  13017. +{
  13018. + str_list_elt_t *next;
  13019. + char *data;
  13020. +};
  13021. +
  13022. +typedef struct xstr_list str_list_t;
  13023. +struct xstr_list
  13024. +{
  13025. + str_list_elt_t pre_head;
  13026. + str_list_elt_t *head;
  13027. + str_list_elt_t *tail;
  13028. +};
  13029. +
  13030. +int str_list_elt_init(str_list_elt_t *elt, char *data);
  13031. +void str_list_elt_deinit(str_list_elt_t *elt);
  13032. +
  13033. +str_list_t *str_list_alloc(void);
  13034. +int str_list_init(str_list_t *list);
  13035. +void str_list_deinit(str_list_t *list);
  13036. +
  13037. +int str_list_append(str_list_t *list, char *data);
  13038. +int str_list_push(str_list_t *list, char *data);
  13039. +str_list_elt_t *str_list_pop(str_list_t *list);
  13040. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
  13041. +char *str_list_remove_elt(str_list_t *list, const char *target_str);
  13042. +
  13043. +#endif
  13044. diff -Nur busybox-1.13.4.orig/archival/libipkg/str_util.c busybox-1.13.4/archival/libipkg/str_util.c
  13045. --- busybox-1.13.4.orig/archival/libipkg/str_util.c 1970-01-01 01:00:00.000000000 +0100
  13046. +++ busybox-1.13.4/archival/libipkg/str_util.c 2009-05-31 15:40:37.125998767 +0200
  13047. @@ -0,0 +1,69 @@
  13048. +/* str_utils.c - the itsy package management system
  13049. +
  13050. + Carl D. Worth
  13051. +
  13052. + Copyright (C) 2001 University of Southern California
  13053. +
  13054. + This program is free software; you can redistribute it and/or
  13055. + modify it under the terms of the GNU General Public License as
  13056. + published by the Free Software Foundation; either version 2, or (at
  13057. + your option) any later version.
  13058. +
  13059. + This program is distributed in the hope that it will be useful, but
  13060. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13061. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13062. + General Public License for more details.
  13063. +*/
  13064. +
  13065. +#include "ipkg.h"
  13066. +
  13067. +int str_starts_with(const char *str, const char *prefix);
  13068. +int str_ends_with(const char *str, const char *suffix);
  13069. +int str_chomp(char *str);
  13070. +int str_toupper(char *str);
  13071. +char *str_dup_safe(const char *str);
  13072. +
  13073. +int str_starts_with(const char *str, const char *prefix)
  13074. +{
  13075. + return (strncmp(str, prefix, strlen(prefix)) == 0);
  13076. +}
  13077. +
  13078. +int str_ends_with(const char *str, const char *suffix)
  13079. +{
  13080. + int suffix_len;
  13081. + int str_len;
  13082. +
  13083. + str_len = strlen(str);
  13084. + suffix_len = strlen(suffix);
  13085. +
  13086. + if (str_len < suffix_len) {
  13087. + return 0;
  13088. + }
  13089. +
  13090. + return (strcmp(str + str_len - suffix_len, suffix) == 0);
  13091. +}
  13092. +
  13093. +int str_chomp(char *str)
  13094. +{
  13095. + if (str[strlen(str) - 1] == '\n') {
  13096. + str[strlen(str) - 1] = '\0';
  13097. + return 1;
  13098. + }
  13099. + return 0;
  13100. +}
  13101. +
  13102. +int str_toupper(char *str)
  13103. +{
  13104. + while (*str) {
  13105. + *str = toupper(*str);
  13106. + str++;
  13107. + }
  13108. +
  13109. + return 0;
  13110. +}
  13111. +
  13112. +char *str_dup_safe(const char *str)
  13113. +{
  13114. + return str ? strdup(str) : NULL;
  13115. +}
  13116. +
  13117. diff -Nur busybox-1.13.4.orig/archival/libipkg/str_util.h busybox-1.13.4/archival/libipkg/str_util.h
  13118. --- busybox-1.13.4.orig/archival/libipkg/str_util.h 1970-01-01 01:00:00.000000000 +0100
  13119. +++ busybox-1.13.4/archival/libipkg/str_util.h 2009-05-31 15:40:37.125998767 +0200
  13120. @@ -0,0 +1,27 @@
  13121. +/* str_utils.h - the itsy package management system
  13122. +
  13123. + Carl D. Worth
  13124. +
  13125. + Copyright (C) 2001 University of Southern California
  13126. +
  13127. + This program is free software; you can redistribute it and/or
  13128. + modify it under the terms of the GNU General Public License as
  13129. + published by the Free Software Foundation; either version 2, or (at
  13130. + your option) any later version.
  13131. +
  13132. + This program is distributed in the hope that it will be useful, but
  13133. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13134. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13135. + General Public License for more details.
  13136. +*/
  13137. +
  13138. +#ifndef STR_UTILS_H
  13139. +#define STR_UTILS_H
  13140. +
  13141. +int str_starts_with(const char *str, const char *prefix);
  13142. +int str_ends_with(const char *str, const char *suffix);
  13143. +int str_chomp(char *str);
  13144. +int str_toupper(char *str);
  13145. +char *str_dup_safe(const char *str);
  13146. +
  13147. +#endif
  13148. diff -Nur busybox-1.13.4.orig/archival/libipkg/user.c busybox-1.13.4/archival/libipkg/user.c
  13149. --- busybox-1.13.4.orig/archival/libipkg/user.c 1970-01-01 01:00:00.000000000 +0100
  13150. +++ busybox-1.13.4/archival/libipkg/user.c 2009-05-31 15:40:37.129998160 +0200
  13151. @@ -0,0 +1,61 @@
  13152. +/* user.c - the itsy package management system
  13153. +
  13154. + Jamey Hicks
  13155. +
  13156. + Copyright (C) 2002 Hewlett Packard Company
  13157. + Copyright (C) 2001 University of Southern California
  13158. +
  13159. + This program is free software; you can redistribute it and/or
  13160. + modify it under the terms of the GNU General Public License as
  13161. + published by the Free Software Foundation; either version 2, or (at
  13162. + your option) any later version.
  13163. +
  13164. + This program is distributed in the hope that it will be useful, but
  13165. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13166. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13167. + General Public License for more details.
  13168. +*/
  13169. +
  13170. +#include <stdio.h>
  13171. +#include <stdarg.h>
  13172. +#include "libbb.h"
  13173. +#include "file_util.h"
  13174. +#include "str_util.h"
  13175. +#ifdef IPKG_LIB
  13176. +#include "libipkg.h"
  13177. +#endif
  13178. +
  13179. +char *get_user_response(const char *format, ...);
  13180. +
  13181. +
  13182. +#ifdef IPKG_LIB
  13183. +static char *question = NULL;
  13184. +static int question_len = 255;
  13185. +#endif
  13186. +char *get_user_response(const char *format, ...)
  13187. +{
  13188. + int len = question_len;
  13189. + va_list ap;
  13190. + char *response;
  13191. + va_start(ap, format);
  13192. +
  13193. +#ifndef IPKG_LIB
  13194. + vprintf(format, ap);
  13195. + do {
  13196. + response = file_read_line_alloc(stdin);
  13197. + } while (response == NULL);
  13198. +#else
  13199. + do {
  13200. + if (question == NULL || len > question_len) {
  13201. + question = realloc(question, len + 1);
  13202. + question_len = len;
  13203. + }
  13204. + len = vsnprintf(question,question_len,format,ap);
  13205. + } while (len > question_len);
  13206. + response = strdup(ipkg_cb_response(question));
  13207. +#endif
  13208. + str_chomp(response);
  13209. + str_tolower(response);
  13210. +
  13211. + return response;
  13212. +}
  13213. diff -Nur busybox-1.13.4.orig/archival/libipkg/user.h busybox-1.13.4/archival/libipkg/user.h
  13214. --- busybox-1.13.4.orig/archival/libipkg/user.h 1970-01-01 01:00:00.000000000 +0100
  13215. +++ busybox-1.13.4/archival/libipkg/user.h 2009-05-31 15:40:37.129998160 +0200
  13216. @@ -0,0 +1,23 @@
  13217. +/* user.c - the itsy package management system
  13218. +
  13219. + Jamey Hicks
  13220. +
  13221. + Copyright (C) 2002 Hewlett Packard Company
  13222. + Copyright (C) 2001 University of Southern California
  13223. +
  13224. + This program is free software; you can redistribute it and/or
  13225. + modify it under the terms of the GNU General Public License as
  13226. + published by the Free Software Foundation; either version 2, or (at
  13227. + your option) any later version.
  13228. +
  13229. + This program is distributed in the hope that it will be useful, but
  13230. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13231. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13232. + General Public License for more details.
  13233. +*/
  13234. +
  13235. +#include <stdio.h>
  13236. +#include <stdarg.h>
  13237. +
  13238. +char *get_user_response(const char *format, ...);
  13239. +
  13240. diff -Nur busybox-1.13.4.orig/archival/libipkg/void_list.c busybox-1.13.4/archival/libipkg/void_list.c
  13241. --- busybox-1.13.4.orig/archival/libipkg/void_list.c 1970-01-01 01:00:00.000000000 +0100
  13242. +++ busybox-1.13.4/archival/libipkg/void_list.c 2009-05-31 15:40:37.129998160 +0200
  13243. @@ -0,0 +1,194 @@
  13244. +/* void_list.c - the itsy package management system
  13245. +
  13246. + Carl D. Worth
  13247. +
  13248. + Copyright (C) 2001 University of Southern California
  13249. +
  13250. + This program is free software; you can redistribute it and/or
  13251. + modify it under the terms of the GNU General Public License as
  13252. + published by the Free Software Foundation; either version 2, or (at
  13253. + your option) any later version.
  13254. +
  13255. + This program is distributed in the hope that it will be useful, but
  13256. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13257. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13258. + General Public License for more details.
  13259. +*/
  13260. +
  13261. +#include "ipkg.h"
  13262. +#include <errno.h>
  13263. +
  13264. +#include "void_list.h"
  13265. +
  13266. +int void_list_elt_init(void_list_elt_t *elt, void *data)
  13267. +{
  13268. + elt->next = NULL;
  13269. + elt->data = data;
  13270. +
  13271. + return 0;
  13272. +}
  13273. +
  13274. +void void_list_elt_deinit(void_list_elt_t *elt)
  13275. +{
  13276. + void_list_elt_init(elt, NULL);
  13277. +}
  13278. +
  13279. +int void_list_init(void_list_t *list)
  13280. +{
  13281. + void_list_elt_init(&list->pre_head, NULL);
  13282. + list->head = NULL;
  13283. + list->pre_head.next = list->head;
  13284. + list->tail = NULL;
  13285. +
  13286. + return 0;
  13287. +}
  13288. +
  13289. +void void_list_deinit(void_list_t *list)
  13290. +{
  13291. + void_list_elt_t *elt;
  13292. +
  13293. + while (list->head) {
  13294. + elt = void_list_pop(list);
  13295. + void_list_elt_deinit(elt);
  13296. + /* malloced in void_list_append */
  13297. + free(elt);
  13298. + }
  13299. +}
  13300. +
  13301. +int void_list_append(void_list_t *list, void *data)
  13302. +{
  13303. + void_list_elt_t *elt;
  13304. +
  13305. + /* freed in void_list_deinit */
  13306. + elt = malloc(sizeof(void_list_elt_t));
  13307. + if (elt == NULL) {
  13308. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13309. + return ENOMEM;
  13310. + }
  13311. +
  13312. + void_list_elt_init(elt, data);
  13313. +
  13314. + if (list->tail) {
  13315. + list->tail->next = elt;
  13316. + list->tail = elt;
  13317. + } else {
  13318. + list->head = elt;
  13319. + list->pre_head.next = list->head;
  13320. + list->tail = elt;
  13321. + }
  13322. +
  13323. + return 0;
  13324. +}
  13325. +
  13326. +int void_list_push(void_list_t *list, void *data)
  13327. +{
  13328. + void_list_elt_t *elt;
  13329. +
  13330. + elt = malloc(sizeof(void_list_elt_t));
  13331. + if (elt == NULL) {
  13332. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13333. + return ENOMEM;
  13334. + }
  13335. +
  13336. + void_list_elt_init(elt, data);
  13337. +
  13338. + elt->next = list->head;
  13339. + list->head->next = elt;
  13340. + if (list->tail == NULL) {
  13341. + list->tail = list->head;
  13342. + }
  13343. +
  13344. + return 0;
  13345. +}
  13346. +
  13347. +void_list_elt_t *void_list_pop(void_list_t *list)
  13348. +{
  13349. + void_list_elt_t *elt;
  13350. +
  13351. + elt = list->head;
  13352. +
  13353. + if (list->head) {
  13354. + list->head = list->head->next;
  13355. + list->pre_head.next = list->head;
  13356. + if (list->head == NULL) {
  13357. + list->tail = NULL;
  13358. + }
  13359. + }
  13360. +
  13361. + return elt;
  13362. +}
  13363. +
  13364. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
  13365. +{
  13366. + void_list_elt_t *prior;
  13367. + void_list_elt_t *old_elt;
  13368. + void *old_data;
  13369. +
  13370. + old_elt = *iter;
  13371. + old_data = old_elt->data;
  13372. +
  13373. + if (old_elt == list->head) {
  13374. + prior = &list->pre_head;
  13375. + void_list_pop(list);
  13376. + } else {
  13377. + for (prior = list->head; prior; prior = prior->next) {
  13378. + if (prior->next == old_elt) {
  13379. + break;
  13380. + }
  13381. + }
  13382. + if (prior == NULL || prior->next != old_elt) {
  13383. + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
  13384. + return NULL;
  13385. + }
  13386. + prior->next = old_elt->next;
  13387. +
  13388. + if (old_elt == list->tail) {
  13389. + list->tail = prior;
  13390. + }
  13391. + }
  13392. +
  13393. + void_list_elt_deinit(old_elt);
  13394. + *iter = prior;
  13395. +
  13396. + return old_data;
  13397. +}
  13398. +
  13399. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13400. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
  13401. +{
  13402. + void_list_elt_t *prior;
  13403. + void_list_elt_t *old_elt = NULL;
  13404. + void *old_data = NULL;
  13405. +
  13406. + /* first element */
  13407. + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
  13408. + old_elt = list->head;
  13409. + old_data = list->head->data;
  13410. + void_list_pop(list);
  13411. + } else {
  13412. + int found = 0;
  13413. + for (prior = list->head; prior && prior->next; prior = prior->next) {
  13414. + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
  13415. + old_elt = prior->next;
  13416. + old_data = old_elt->data;
  13417. + found = 1;
  13418. + break;
  13419. + }
  13420. + }
  13421. + if (!found) {
  13422. + return NULL;
  13423. + }
  13424. + prior->next = old_elt->next;
  13425. +
  13426. + if (old_elt == list->tail) {
  13427. + list->tail = prior;
  13428. + }
  13429. + }
  13430. + if (old_elt)
  13431. + void_list_elt_deinit(old_elt);
  13432. +
  13433. + if (old_data)
  13434. + return old_data;
  13435. + else
  13436. + return NULL;
  13437. +}
  13438. diff -Nur busybox-1.13.4.orig/archival/libipkg/void_list.h busybox-1.13.4/archival/libipkg/void_list.h
  13439. --- busybox-1.13.4.orig/archival/libipkg/void_list.h 1970-01-01 01:00:00.000000000 +0100
  13440. +++ busybox-1.13.4/archival/libipkg/void_list.h 2009-05-31 15:40:37.129998160 +0200
  13441. @@ -0,0 +1,59 @@
  13442. +/* void_list.h - the itsy package management system
  13443. +
  13444. + Carl D. Worth
  13445. +
  13446. + Copyright (C) 2001 University of Southern California
  13447. +
  13448. + This program is free software; you can redistribute it and/or
  13449. + modify it under the terms of the GNU General Public License as
  13450. + published by the Free Software Foundation; either version 2, or (at
  13451. + your option) any later version.
  13452. +
  13453. + This program is distributed in the hope that it will be useful, but
  13454. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13455. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13456. + General Public License for more details.
  13457. +*/
  13458. +
  13459. +#ifndef VOID_LIST_H
  13460. +#define VOID_LIST_H
  13461. +
  13462. +typedef struct void_list_elt void_list_elt_t;
  13463. +struct void_list_elt
  13464. +{
  13465. + void_list_elt_t *next;
  13466. + void *data;
  13467. +};
  13468. +
  13469. +typedef struct void_list void_list_t;
  13470. +struct void_list
  13471. +{
  13472. + void_list_elt_t pre_head;
  13473. + void_list_elt_t *head;
  13474. + void_list_elt_t *tail;
  13475. +};
  13476. +
  13477. +static inline int void_list_empty(void_list_t *list)
  13478. +{
  13479. + if (list->head == NULL)
  13480. + return 1;
  13481. + else
  13482. + return 0;
  13483. +}
  13484. +
  13485. +int void_list_elt_init(void_list_elt_t *elt, void *data);
  13486. +void void_list_elt_deinit(void_list_elt_t *elt);
  13487. +
  13488. +int void_list_init(void_list_t *list);
  13489. +void void_list_deinit(void_list_t *list);
  13490. +
  13491. +int void_list_append(void_list_t *list, void *data);
  13492. +int void_list_push(void_list_t *list, void *data);
  13493. +void_list_elt_t *void_list_pop(void_list_t *list);
  13494. +
  13495. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
  13496. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13497. +typedef int (*void_list_cmp_t)(const void *, const void *);
  13498. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
  13499. +
  13500. +#endif
  13501. diff -Nur busybox-1.13.4.orig/archival/libipkg/xsystem.c busybox-1.13.4/archival/libipkg/xsystem.c
  13502. --- busybox-1.13.4.orig/archival/libipkg/xsystem.c 1970-01-01 01:00:00.000000000 +0100
  13503. +++ busybox-1.13.4/archival/libipkg/xsystem.c 2009-05-31 15:40:37.133998111 +0200
  13504. @@ -0,0 +1,64 @@
  13505. +/* xsystem.c - system(3) with error messages
  13506. +
  13507. + Carl D. Worth
  13508. +
  13509. + Copyright (C) 2001 University of Southern California
  13510. +
  13511. + This program is free software; you can redistribute it and/or
  13512. + modify it under the terms of the GNU General Public License as
  13513. + published by the Free Software Foundation; either version 2, or (at
  13514. + your option) any later version.
  13515. +
  13516. + This program is distributed in the hope that it will be useful, but
  13517. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13518. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13519. + General Public License for more details.
  13520. +*/
  13521. +
  13522. +#include "ipkg.h"
  13523. +#include <sys/wait.h>
  13524. +
  13525. +#include "xsystem.h"
  13526. +
  13527. +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
  13528. + really need the /bin/sh invocation which takes resources and
  13529. + introduces security problems. I should switch all of this to a sort
  13530. + of execl() or execv() interface/implementation.
  13531. +*/
  13532. +
  13533. +/* Like system(3), but with error messages printed if the fork fails
  13534. + or if the child process dies due to an uncaught signal. Also, the
  13535. + return value is a bit simpler:
  13536. +
  13537. + -1 if there was any problem
  13538. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13539. + as defined in <sys/wait.h>.
  13540. +*/
  13541. +int xsystem(const char *cmd)
  13542. +{
  13543. + int err;
  13544. +
  13545. + err = system(cmd);
  13546. +
  13547. + if (err == -1) {
  13548. + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
  13549. + __FUNCTION__, cmd);
  13550. + return -1;
  13551. + }
  13552. +
  13553. + if (WIFSIGNALED(err)) {
  13554. + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
  13555. + __FUNCTION__, WTERMSIG(err), cmd);
  13556. + return -1;
  13557. + }
  13558. +
  13559. + if (WIFEXITED(err)) {
  13560. + /* Normal child exit */
  13561. + return WEXITSTATUS(err);
  13562. + }
  13563. +
  13564. + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
  13565. + __FUNCTION__, err);
  13566. + return -1;
  13567. +}
  13568. +
  13569. diff -Nur busybox-1.13.4.orig/archival/libipkg/xsystem.h busybox-1.13.4/archival/libipkg/xsystem.h
  13570. --- busybox-1.13.4.orig/archival/libipkg/xsystem.h 1970-01-01 01:00:00.000000000 +0100
  13571. +++ busybox-1.13.4/archival/libipkg/xsystem.h 2009-05-31 15:40:37.133998111 +0200
  13572. @@ -0,0 +1,34 @@
  13573. +/* xsystem.h - system(3) with error messages
  13574. +
  13575. + Carl D. Worth
  13576. +
  13577. + Copyright (C) 2001 University of Southern California
  13578. +
  13579. + This program is free software; you can redistribute it and/or
  13580. + modify it under the terms of the GNU General Public License as
  13581. + published by the Free Software Foundation; either version 2, or (at
  13582. + your option) any later version.
  13583. +
  13584. + This program is distributed in the hope that it will be useful, but
  13585. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13586. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13587. + General Public License for more details.
  13588. +*/
  13589. +
  13590. +#ifndef XSYSTEM_H
  13591. +#define XSYSTEM_H
  13592. +
  13593. +#include <stdlib.h>
  13594. +
  13595. +/* Like system(3), but with error messages printed if the fork fails
  13596. + or if the child process dies due to an uncaught signal. Also, the
  13597. + return value is a bit simpler:
  13598. +
  13599. + -1 if there was any problem
  13600. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13601. + as defined in <sys/wait.h>.
  13602. +*/
  13603. +int xsystem(const char *cmd);
  13604. +
  13605. +#endif
  13606. +
  13607. diff -Nur busybox-1.13.4.orig/archival/libunarchive/Kbuild busybox-1.13.4/archival/libunarchive/Kbuild
  13608. --- busybox-1.13.4.orig/archival/libunarchive/Kbuild 2008-11-09 18:28:02.000000000 +0100
  13609. +++ busybox-1.13.4/archival/libunarchive/Kbuild 2009-05-31 15:40:37.133998111 +0200
  13610. @@ -39,6 +39,7 @@
  13611. lib-$(CONFIG_DPKG) += $(DPKG_FILES)
  13612. lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES)
  13613. lib-$(CONFIG_GUNZIP) += decompress_unzip.o
  13614. +lib-$(CONFIG_IPKG) += open_transformer.o get_header_tar.o get_header_tar_gz.o
  13615. lib-$(CONFIG_RPM2CPIO) += decompress_unzip.o get_header_cpio.o
  13616. lib-$(CONFIG_RPM) += open_transformer.o decompress_unzip.o get_header_cpio.o
  13617. lib-$(CONFIG_TAR) += get_header_tar.o
  13618. diff -Nur busybox-1.13.4.orig/archival/libunarchive/data_extract_all.c busybox-1.13.4/archival/libunarchive/data_extract_all.c
  13619. --- busybox-1.13.4.orig/archival/libunarchive/data_extract_all.c 2008-11-09 18:28:02.000000000 +0100
  13620. +++ busybox-1.13.4/archival/libunarchive/data_extract_all.c 2009-05-31 15:40:37.133998111 +0200
  13621. @@ -146,3 +146,16 @@
  13622. }
  13623. }
  13624. }
  13625. +
  13626. +extern void FAST_FUNC data_extract_all_prefix(archive_handle_t *archive_handle)
  13627. +{
  13628. + char *name_ptr = archive_handle->file_header->name;
  13629. +
  13630. + name_ptr += strspn(name_ptr, "./");
  13631. + if (name_ptr[0] != '\0') {
  13632. + archive_handle->file_header->name = xmalloc(strlen(archive_handle->buffer) + 1 + strlen(name_ptr) + 1);
  13633. + strcpy(archive_handle->file_header->name, archive_handle->buffer);
  13634. + strcat(archive_handle->file_header->name, name_ptr);
  13635. + data_extract_all(archive_handle);
  13636. + }
  13637. +}
  13638. diff -Nur busybox-1.13.4.orig/coreutils/md5_sha1_sum.c busybox-1.13.4/coreutils/md5_sha1_sum.c
  13639. --- busybox-1.13.4.orig/coreutils/md5_sha1_sum.c 2008-11-09 18:28:07.000000000 +0100
  13640. +++ busybox-1.13.4/coreutils/md5_sha1_sum.c 2009-05-31 15:40:37.141999131 +0200
  13641. @@ -8,14 +8,12 @@
  13642. #include "libbb.h"
  13643. -typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
  13644. -
  13645. #define FLAG_SILENT 1
  13646. #define FLAG_CHECK 2
  13647. #define FLAG_WARN 4
  13648. /* This might be useful elsewhere */
  13649. -static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
  13650. +unsigned char *hash_bin_to_hex(unsigned char *hash_value,
  13651. unsigned hash_length)
  13652. {
  13653. /* xzalloc zero-terminates */
  13654. @@ -24,7 +22,7 @@
  13655. return (unsigned char *)hex_value;
  13656. }
  13657. -static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
  13658. +uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
  13659. {
  13660. int src_fd, hash_len, count;
  13661. union _ctx_ {
  13662. diff -Nur busybox-1.13.4.orig/include/applets.h busybox-1.13.4/include/applets.h
  13663. --- busybox-1.13.4.orig/include/applets.h 2008-11-09 18:28:17.000000000 +0100
  13664. +++ busybox-1.13.4/include/applets.h 2009-05-31 15:40:37.145999641 +0200
  13665. @@ -203,6 +203,7 @@
  13666. USE_IPCALC(APPLET(ipcalc, _BB_DIR_BIN, _BB_SUID_NEVER))
  13667. USE_IPCRM(APPLET(ipcrm, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
  13668. USE_IPCS(APPLET(ipcs, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
  13669. +USE_IPKG(APPLET(ipkg, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
  13670. USE_IPLINK(APPLET(iplink, _BB_DIR_BIN, _BB_SUID_NEVER))
  13671. USE_IPROUTE(APPLET(iproute, _BB_DIR_BIN, _BB_SUID_NEVER))
  13672. USE_IPRULE(APPLET(iprule, _BB_DIR_BIN, _BB_SUID_NEVER))
  13673. diff -Nur busybox-1.13.4.orig/include/libbb.h busybox-1.13.4/include/libbb.h
  13674. --- busybox-1.13.4.orig/include/libbb.h 2009-04-15 02:09:42.000000000 +0200
  13675. +++ busybox-1.13.4/include/libbb.h 2009-05-31 15:40:37.149999313 +0200
  13676. @@ -1309,6 +1309,7 @@
  13677. extern const char bb_uuenc_tbl_std[];
  13678. void bb_uuencode(char *store, const void *s, int length, const char *tbl) FAST_FUNC;
  13679. +typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
  13680. typedef struct sha1_ctx_t {
  13681. uint32_t count[2];
  13682. uint32_t hash[5];
  13683. @@ -1317,6 +1318,8 @@
  13684. void sha1_begin(sha1_ctx_t *ctx) FAST_FUNC;
  13685. void sha1_hash(const void *data, size_t length, sha1_ctx_t *ctx) FAST_FUNC;
  13686. void *sha1_end(void *resbuf, sha1_ctx_t *ctx) FAST_FUNC;
  13687. +unsigned char *hash_bin_to_hex(unsigned char *hash_value, unsigned hash_length);
  13688. +uint8_t *hash_file(const char *filename, hash_algo_t hash_algo);
  13689. typedef struct md5_ctx_t {
  13690. uint32_t A;
  13691. diff -Nur busybox-1.13.4.orig/include/unarchive.h busybox-1.13.4/include/unarchive.h
  13692. --- busybox-1.13.4.orig/include/unarchive.h 2008-11-09 18:28:17.000000000 +0100
  13693. +++ busybox-1.13.4/include/unarchive.h 2009-05-31 15:40:37.149999313 +0200
  13694. @@ -94,6 +94,7 @@
  13695. extern void data_skip(archive_handle_t *archive_handle) FAST_FUNC;
  13696. extern void data_extract_all(archive_handle_t *archive_handle) FAST_FUNC;
  13697. +extern void data_extract_all_prefix(archive_handle_t *archive_handle) FAST_FUNC;
  13698. extern void data_extract_to_stdout(archive_handle_t *archive_handle) FAST_FUNC;
  13699. extern void data_extract_to_buffer(archive_handle_t *archive_handle) FAST_FUNC;
  13700. diff -Nur busybox-1.13.4.orig/include/usage.h busybox-1.13.4/include/usage.h
  13701. --- busybox-1.13.4.orig/include/usage.h 2008-11-09 18:28:17.000000000 +0100
  13702. +++ busybox-1.13.4/include/usage.h 2009-05-31 15:40:37.154000102 +0200
  13703. @@ -1425,6 +1425,82 @@
  13704. "$ ls -la /tmp/busybox*\n" \
  13705. "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"
  13706. +#define ipkg_trivial_usage \
  13707. + "[options]... sub-command [arguments]..."
  13708. +#define ipkg_full_usage \
  13709. + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
  13710. + "\n" \
  13711. + "Sub-commands:\n" \
  13712. + "\nPackage Manipulation:\n" \
  13713. + "\tupdate Update list of available packages\n" \
  13714. + "\tupgrade Upgrade all installed packages to latest version\n" \
  13715. + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
  13716. + "\tinstall <file.ipk> Install package <file.ipk>\n" \
  13717. + "\tconfigure [<pkg>] Configure unpacked packages\n" \
  13718. + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
  13719. + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
  13720. + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
  13721. + "\n" \
  13722. + "Informational Commands:\n" \
  13723. + "\tlist List available packages and descriptions\n" \
  13724. + "\tlist_installed List all and only the installed packages and description \n" \
  13725. + "\tfiles <pkg> List all files belonging to <pkg>\n" \
  13726. + "\tsearch <file|regexp> Search for a package providing <file>\n" \
  13727. + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
  13728. + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
  13729. + "\tdownload <pkg> Download <pkg> to current directory.\n" \
  13730. + "\tcompare_versions <v1> <op> <v2>\n" \
  13731. + "\t compare versions using <= < > >= = << >>\n" \
  13732. + "\tprint_architecture prints the architecture.\n" \
  13733. + "\tprint_installation_architecture\n" \
  13734. + "\twhatdepends [-A] [pkgname|pat]+\n" \
  13735. + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
  13736. + "\twhatprovides [-A] [pkgname|pat]+\n" \
  13737. + "\twhatconflicts [-A] [pkgname|pat]+\n" \
  13738. + "\twhatreplaces [-A] [pkgname|pat]+\n" \
  13739. + "\t prints the installation architecture.\n" \
  13740. + "\n" \
  13741. + "\nOptions:\n" \
  13742. + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
  13743. + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
  13744. + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
  13745. + "\t 0 errors only\n" \
  13746. + "\t 1 normal messages (default)\n" \
  13747. + "\t 2 informative messages\n" \
  13748. + "\t 3 debug output\n" \
  13749. + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
  13750. + "\t-conf <conf_file> Default configuration file location\n" \
  13751. + " is /etc/ipkg.conf\n" \
  13752. + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
  13753. + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
  13754. + " <dest_name> should be a defined dest name from\n" \
  13755. + " the configuration file, (but can also be a\n" \
  13756. + " directory name in a pinch).\n" \
  13757. + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
  13758. + "\t-offline <offline_root> offline installation of packages.\n" \
  13759. + "\t-verbose_wget more wget messages\n" \
  13760. + "\n" \
  13761. + "Force Options (use when ipkg is too smart for its own good):\n" \
  13762. + "\t-force-depends Make dependency checks warnings instead of errors\n" \
  13763. + "\t Install/remove package in spite of failed dependences\n" \
  13764. + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
  13765. + " (no prompts). Note that this will not prevent\n" \
  13766. + " package installation scripts from prompting.\n" \
  13767. + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
  13768. + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
  13769. + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
  13770. + "\t-force_space Install even if there does not seem to be enough space.\n" \
  13771. + "\t-noaction No action -- test only\n" \
  13772. + "\t-nodeps Do not follow dependences\n" \
  13773. + "\t-force-removal-of-dependent-packages\n" \
  13774. + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
  13775. + "\t-test No action -- test only\n" \
  13776. + "\t-t Specify tmp-dir.\n" \
  13777. + "\t--tmp-dir Specify tmp-dir.\n" \
  13778. + "\n" \
  13779. + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
  13780. + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
  13781. +
  13782. #define halt_trivial_usage \
  13783. "[-d delay] [-n] [-f]" USE_FEATURE_WTMP(" [-w]")
  13784. #define halt_full_usage "\n\n" \