Action.c 164 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $TOG: Action.c /main/28 1999/09/16 14:55:25 mgreess $ */
  24. /*
  25. * (c) Copyright 1997, The Open Group
  26. */
  27. /*************************************<+>*************************************
  28. *****************************************************************************
  29. **
  30. ** File: Action.c
  31. **
  32. ** Project: DT
  33. **
  34. ** Description: This file contains the action library source code.
  35. **
  36. **
  37. ** (c) Copyright 1993, 1994 Hewlett-Packard Company
  38. ** (c) Copyright 1993, 1994 International Business Machines Corp.
  39. ** (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  40. ** (c) Copyright 1993, 1994 Novell, Inc.
  41. **
  42. **
  43. ****************************************************************************
  44. ************************************<+>*************************************/
  45. /*LINTLIBRARY*/
  46. #include <stdio.h>
  47. #include <errno.h>
  48. #include <sys/types.h>
  49. #include <sys/stat.h>
  50. #include <sys/param.h>
  51. #ifdef _SUN_OS /* Need this for the strtod () call */
  52. #include <floatingpoint.h>
  53. #endif /* _SUN_OS */
  54. #define X_INCLUDE_STRING_H
  55. #define XOS_USE_XT_LOCKING
  56. #include <X11/Xos_r.h>
  57. #include <stdlib.h>
  58. #include <limits.h>
  59. #include <X11/Intrinsic.h>
  60. #include <Dt/CmdInv.h>
  61. #include <Dt/DtP.h>
  62. #include <Dt/Dts.h>
  63. #include <Dt/Help.h>
  64. #include <Dt/Message.h>
  65. #include <Dt/Connect.h>
  66. #include <Dt/Indicator.h>
  67. #include <Dt/DtNlUtils.h>
  68. #include <Dt/CommandM.h>
  69. #include <Dt/Utility.h>
  70. #include <Dt/Service.h>
  71. #include <Dt/UserMsg.h>
  72. #include <Xm/Xm.h>
  73. #include <Xm/BulletinB.h>
  74. #include <Xm/DialogS.h>
  75. #include <Xm/Frame.h>
  76. #include <Xm/Form.h>
  77. #include <Xm/LabelG.h>
  78. #include <Xm/TextF.h>
  79. #include <Xm/SeparatoG.h>
  80. #include <Xm/PushBG.h>
  81. #include <Xm/MessageB.h>
  82. #include <Xm/MwmUtil.h>
  83. #include <Xm/Protocols.h>
  84. #include <Dt/ActionP.h>
  85. #include <Dt/ActionUtilP.h>
  86. #include <Dt/ActionDb.h>
  87. #include <Dt/ActionFind.h>
  88. #include <Tt/tttk.h>
  89. #include <Dt/Action.h>
  90. #include "myassertP.h"
  91. #include "DtSvcLock.h"
  92. #ifndef CDE_INSTALLATION_TOP
  93. #define CDE_INSTALLATION_TOP "/opt/dt"
  94. #endif
  95. extern char * _DtStripSpaces(
  96. char * string) ;
  97. extern char * _DtDbPathIdToString( DtDbPathId pathId) ;
  98. #define _MAX_MAP_ATTEMPTS 100 /* Maximum nuber of "MAPS" that will
  99. be done. */
  100. #define _DT_ACTION_MAX_CLOSE_TRIES 5
  101. /******** Public Function Declarations ********/
  102. void _DtCreateErrorDialog(
  103. Widget w,
  104. char * actionName,
  105. XmString msg) ;
  106. Boolean _DtCompileMessagePiece(
  107. Widget w,
  108. ActionRequest *request,
  109. char * relPathHost,
  110. char * relPathDir,
  111. parsedMsg * piece,
  112. Boolean initialize,
  113. unsigned long processingMask,
  114. Boolean ** paramUsed,
  115. int * promptDataIndex ) ;
  116. ActionRequest * _DtCloneRequest (
  117. ActionRequest * request) ;
  118. void _DtFreeRequest(
  119. register ActionRequest *request) ;
  120. char * _DtFindCwd( void ) ;
  121. char * _DtActMapFileName(
  122. const char * curHost,
  123. const char * dir,
  124. const char * file,
  125. const char * newHost ) ;
  126. extern void _DtProcessTtRequest(
  127. Widget w,
  128. ActionRequest *request,
  129. char * relPathHost,
  130. char * relPathDir ) ;
  131. extern Tt_status _DtInitializeToolTalk(Widget w);
  132. extern Boolean _DtEmptyString(
  133. String str) ;
  134. /******** End Public Function Declarations ********/
  135. /******** Static Function Declarations ********/
  136. static void FreeErrorDialog(
  137. Widget w,
  138. XtPointer user_data,
  139. XtPointer call_data) ;
  140. static void InvalidFilename(
  141. Widget w,
  142. char * actionName,
  143. char * filename) ;
  144. static void HostAccessError(
  145. Widget w,
  146. char * actionName,
  147. char * hostName) ;
  148. static void MultiHostAccessError(
  149. Widget w,
  150. char * actionName,
  151. char * hostList) ;
  152. static void NoActionError(
  153. Widget w,
  154. DtShmBoson origNameQuark,
  155. char * actionName,
  156. char * type,
  157. char * host,
  158. char * dir,
  159. char * file) ;
  160. static void MapError(
  161. Widget w,
  162. char * actionName ) ;
  163. static void CommandInvokerError(
  164. Widget w,
  165. char * actionName,
  166. char * errorString) ;
  167. static void NoToolTalkConnectionError(
  168. Widget w,
  169. String actionName,
  170. Tt_status status) ;
  171. static void TmpFileCreateError(
  172. Widget w,
  173. char *actionName,
  174. char *dirName) ;
  175. static void TmpFileOpenError(
  176. Widget w,
  177. char *actionName,
  178. char *fileName) ;
  179. static void TmpFileWriteError(
  180. Widget w,
  181. char *actionName,
  182. char *fileName) ;
  183. static void UnSupportedObject(
  184. Widget w,
  185. char *actionName,
  186. int objClass);
  187. static void SetExecHost(
  188. ActionRequest * request) ;
  189. static void ParseHostList (
  190. char * hostString,
  191. char *** hostListPtr,
  192. int * hostListSizePtr,
  193. int * hostCountPtr) ;
  194. static void RemoveDuplicateHostNames (
  195. char ** hostList,
  196. int * hostCountPtr ) ;
  197. static void AddFailedHostToList (
  198. ActionRequest * request,
  199. char * badHost) ;
  200. static int _DtAddEntry(
  201. register char * string,
  202. register char * **arrayPtr,
  203. register int *sizePtr) ;
  204. static void TryToTypeFile(
  205. ObjectData *obj,
  206. char * host,
  207. char * dir,
  208. char * file,
  209. char ** resolvedPath);
  210. static ActionRequest * CreateActionRequest(
  211. Widget w,
  212. char * actionName,
  213. DtActionArg *aap,
  214. int numArgs,
  215. char * termOpts,
  216. char * execHost,
  217. char * cwdHost,
  218. char * cwdDir,
  219. _DtActInvRecT *invp);
  220. static _DtActInvRecT *CreateInvocationRecord(
  221. char *actionName,
  222. Widget w,
  223. DtActionArg *aap,
  224. int numArgs);
  225. static Boolean ParseFileArgument(
  226. Widget w,
  227. ActionRequest * request,
  228. ObjectData * objectData,
  229. char * hostname,
  230. char * filename,
  231. char * filetype,
  232. Boolean typeFile) ;
  233. static void AddPrompt(
  234. register int argNum,
  235. char * prompt,
  236. register int *numPrompts,
  237. register PromptEntry **prompts) ;
  238. static int MatchParamsToAction(
  239. ActionRequest *request,
  240. int *numPrompts,
  241. PromptEntry **prompts) ;
  242. static void ProcessOneSegment(
  243. ActionRequest * request,
  244. parsedMsg * msg,
  245. PromptEntry **prompts,
  246. int *numPrompts,
  247. Boolean * argsOptionFound,
  248. int * lastArgReferenced,
  249. int * unused,
  250. Boolean * paramUsed) ;
  251. static ActionPtr CloneActionDBEntry(
  252. register ActionPtr action) ;
  253. static void CloneParsedMessage(
  254. register parsedMsg * old_pmsg,
  255. register parsedMsg * new_pmsg ) ;
  256. static void FreeParsedMessage(
  257. register parsedMsg * parsedMessage) ;
  258. static parsedMsg * CloneParsedMessageArray(
  259. register parsedMsg * pmsgArray,
  260. register int count ) ;
  261. static void FreeParsedMessageArray(
  262. register parsedMsg * parsedMessageArray,
  263. int count ) ;
  264. static Boolean InsertArgumentString(
  265. Widget w,
  266. register char **bufPtr,
  267. int * bufSizePtr,
  268. ActionRequest *request,
  269. register ObjectData *object,
  270. unsigned long mask,
  271. char * relPathHost,
  272. char * relPathDir,
  273. Boolean addLeadingSpace,
  274. unsigned long processingMask ) ;
  275. static void InsertUnmappedArgumentString(
  276. register char **bufPtr,
  277. int * bufSizePtr,
  278. register ObjectData *object,
  279. Boolean addLeadingSpace ) ;
  280. static char * GrowMsgBuffer(
  281. char * buffer,
  282. int *size,
  283. int count) ;
  284. static void CmdInvSuccessfulRequest(
  285. char *message,
  286. void *data2) ;
  287. static void CmdInvFailedRequest(
  288. char *message,
  289. void *data2) ;
  290. static void InitiateDtRequest(
  291. Widget w,
  292. ActionRequest *request) ;
  293. static Boolean ResolveDtNotifyMessagePieces(
  294. Widget w,
  295. ActionRequest *request,
  296. char * relPathHost,
  297. char * relPathDir ) ;
  298. static void InitiateDtNotifyMessage(
  299. Widget w,
  300. ActionRequest *request ) ;
  301. static void PrepareAndExecuteAction(
  302. Widget w,
  303. register ActionRequest *request);
  304. static void __ExtractCWD(
  305. register ActionRequest *request,
  306. char ** hostPtr,
  307. char ** dirPtr,
  308. Boolean useObjectInfo) ;
  309. static void ContinueRequest(
  310. Widget widget,
  311. XtPointer user_data,
  312. XtPointer call_data) ;
  313. static void CancelRequest(
  314. Widget widget,
  315. XtPointer user_data,
  316. XtPointer call_data) ;
  317. static void CreateContinueDialog(
  318. Widget w,
  319. ActionRequest *request,
  320. int numPrompts,
  321. register PromptEntry *prompts) ;
  322. static void CancelPromptDialog(
  323. Widget widget,
  324. PromptDialog *dialog,
  325. XtPointer call_data) ;
  326. static void ProcessPromptDialog(
  327. Widget widget,
  328. register PromptDialog *dialog,
  329. XtPointer call_data) ;
  330. static void ChangePromptTraversal(
  331. Widget widget,
  332. register PromptDialog *dialog,
  333. XtPointer call_data) ;
  334. static void CreatePromptDialog(
  335. Widget w,
  336. ActionRequest *request,
  337. register int numPrompts,
  338. register PromptEntry *prompts) ;
  339. static Boolean MoreArgumentsToProcess(
  340. register ActionRequest *request) ;
  341. static Boolean ProcessRequest(
  342. Widget w,
  343. register ActionRequest *request) ;
  344. static void InitLocalizedStrings( void ) ;
  345. static int LinkToTypeQuark(
  346. char * host,
  347. char * dir,
  348. char * file,
  349. char **resolvedPath) ;
  350. static void CancelOut(
  351. Widget w,
  352. XEvent *event,
  353. XtPointer params,
  354. XtPointer num_params);
  355. static void InitiateCommandInvokerRequest(
  356. Widget w,
  357. ActionRequest *request,
  358. char * host,
  359. char * dir) ;
  360. static void ProcessCommandInvokerRequest(
  361. Widget w,
  362. ActionRequest *request,
  363. char * relPathHost,
  364. char * relPathDir) ;
  365. static Boolean ResolveCommandInvokerMessagePieces(
  366. Widget w,
  367. ActionRequest *request,
  368. char * relPathHost,
  369. char * relPathDir) ;
  370. static Tt_callback_action _DbReloadCB(Tt_message m, Tt_pattern p);
  371. static void _DtActTimerCB( XtPointer clientData,
  372. XtIntervalId timerId);
  373. static void _DtActIndicatorCB( XtPointer clientData,
  374. XtIntervalId timerId);
  375. /******** End Static Function Declarations ********/
  376. /* Pointers to localizable strings */
  377. static String PromptDialogTitle;
  378. static String ErrorPostfix;
  379. static String PromptDialogLabel;
  380. static String ContinueMessage;
  381. static String HostErrorMsg;
  382. static String HostErrorMsg2;
  383. static String NoActionMsg;
  384. static String NoActionMsg2;
  385. static String NoActionMsg3;
  386. static String MapErrorMsg;
  387. static String InvalidFileMsg;
  388. static String MultiHostErrorMsg;
  389. static String IcccmReqErrorMsg;
  390. static String NoToolTalkConnMsg;
  391. static String UnSupportedObjMsg;
  392. static String TmpFileCreateErrorMsg;
  393. static String TmpFileOpenErrorMsg;
  394. static String TmpFileWriteErrorMsg;
  395. /*
  396. * RWV:
  397. * These error messages are used in the ActionTt.c file
  398. * but were declared static to this file. -- For the
  399. * time being I made them global to get things to work.
  400. */
  401. String ToolTalkErrorMsg;
  402. String ToolTalkErrorMsg2;
  403. String TtFileArgMapErr;
  404. /*
  405. * Variables needed to make the "Escape" key remove the prompt dialog.
  406. */
  407. static XtActionsRec actionTable [] = {
  408. {"Escape", (XtActionProc) CancelOut},
  409. };
  410. static char translations_escape[] = "<Key>osfCancel:Escape()";
  411. /* Help files */
  412. #define PROMPT_HELP "vg_act"
  413. /* Maximum Indicator activation duration (in milliseconds) */
  414. #define INDICATOR_TIME (120 * 1000)
  415. #define MIN_INDICATOR_TIME (5 * 1000)
  416. /******************************************************************************
  417. ******************************************************************************
  418. *
  419. * Public API Functions
  420. *
  421. ******************************************************************************
  422. *****************************************************************************/
  423. /*******************************************************************************
  424. * DtActionInvoke -- invoke an action
  425. * Widget w; ( widget for UI needs)
  426. * char *action; ( action name )
  427. * int aac; ( action arg count )
  428. * ActionArgp aap; ( action argument pointer )
  429. * char *termOpts; ( (opt) terminal options)
  430. * char *execHost; ( (opt) execution host )
  431. * char *cwd; ( (opt) cwd for this action )
  432. * int useIndicator; ( 1 ==> use indicator, 0 ==> not )
  433. * DtActionCallbackProc statusUpdateCb; (user supplied fcn)
  434. * XtPointer client_data (user supplied client data)
  435. *****************************************************************************/
  436. DtActionInvocationID
  437. DtActionInvoke(
  438. Widget w,
  439. char *action,
  440. DtActionArg *aap,
  441. int aac,
  442. char *termOpts,
  443. char *execHost,
  444. char *cwd,
  445. int useIndicator,
  446. DtActionCallbackProc statusUpdateCb,
  447. XtPointer client_data)
  448. {
  449. register int i;
  450. ActionRequest *request;
  451. char *contextHost= NULL;/* dummy to replace old parameter */
  452. _DtActInvRecT *invp; /* pointer to invocation record */
  453. Tt_status status = TT_OK;
  454. static Boolean initialized = False;
  455. extern XtAppContext *_DtInitAppContextp;
  456. _DtSvcWidgetToAppContext(w);
  457. _DtSvcAppLock(app);
  458. _DtSvcAppLock(*_DtInitAppContextp);
  459. /* We can't handle gadgets; use the parent, if necessary */
  460. if (XmIsGadget(w))
  461. w = XtParent(w);
  462. _DtSvcProcessLock();
  463. if ( !initialized )
  464. {
  465. mode_t mode;
  466. char *tmpDir;
  467. InitLocalizedStrings();
  468. /*
  469. * Make sure Tooltalk is initialized
  470. */
  471. status = _DtInitializeToolTalk(w);
  472. if (TT_OK != status)
  473. {
  474. NoToolTalkConnectionError(w, action, status);
  475. _DtSvcProcessUnlock();
  476. return 0;
  477. }
  478. /*
  479. * Create the DtTmp directory, if necessary.
  480. */
  481. tmpDir = _DtGetDtTmpDir();
  482. /* mode == 0755 */
  483. mode = (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH );
  484. if ( mkdir(tmpDir,mode) )
  485. {
  486. /*
  487. * Tmp directory creation failure.
  488. *
  489. * Make one attempt to create the parent directory if the error
  490. * was because of a missing path component -- It may be because
  491. * the "$HOME/.dt" directory hasn't yet been created.
  492. */
  493. if ( errno == ENOENT )
  494. {
  495. char *parentDir = _DtDirname(tmpDir);
  496. if (parentDir && 0 == mkdir(parentDir,mode))
  497. mkdir(tmpDir,mode);
  498. if (parentDir) XtFree(parentDir);
  499. }
  500. }
  501. XtFree(tmpDir);
  502. _DtInitializeCommandInvoker( XtDisplay(w),
  503. NULL, /* bms tool class -- ignored */
  504. NULL, /* application class -- ignored */
  505. (DtSvcMsgContext)NULL, /* reloadDBHandler -- none here */
  506. (_DtInitAppContextp ?
  507. *_DtInitAppContextp : XtWidgetToApplicationContext(w)));
  508. }
  509. initialized = True;
  510. _DtSvcProcessUnlock();
  511. /* Start the activity indicator */
  512. if ( useIndicator ) {
  513. _DtSendActivityNotification(INDICATOR_TIME);
  514. }
  515. if ( (invp = CreateInvocationRecord(action,w,aap,aac)) == NULL)
  516. {
  517. myassert( 0 ); /* no request structure --should never happen */
  518. /* give up -- cannot allocate record */
  519. if ( useIndicator ) _DtSendActivityDoneNotification();
  520. _DtSvcAppUnlock(*_DtInitAppContextp);
  521. _DtSvcAppUnlock(app);
  522. return 0;
  523. }
  524. myassert(invp->id);
  525. if ( useIndicator ) {
  526. /* Start timer for minimum blink time */
  527. XtAppAddTimeOut(XtWidgetToApplicationContext(w),
  528. MIN_INDICATOR_TIME,
  529. (XtTimerCallbackProc) _DtActIndicatorCB,
  530. (XtPointer) invp->id );
  531. }
  532. /*
  533. * Add user callback info to the new invocation record.
  534. */
  535. invp->client_data = client_data;
  536. invp->cb = statusUpdateCb;
  537. /* Create and fill in the request structure */
  538. if ( !IS_INV_FINISHED(invp->state) && (request = CreateActionRequest (
  539. w,action,aap,aac,termOpts,execHost,contextHost,cwd,invp)) != NULL)
  540. {
  541. if (ProcessRequest(w, request))
  542. {
  543. /* all done invoking ? */
  544. RESET_INV_PENDING(invp->state);
  545. /* We should only get here if all requests have been honored */
  546. SET_INV_COMPLETE(invp->state);
  547. /*
  548. * Evaluate whether we are done with this invocation.
  549. * We may have to return values to the caller.
  550. */
  551. _DtActExecutionLeafNodeCleanup(invp->id,NULL,0,True);
  552. _DtFreeRequest(request);
  553. }
  554. /* Otherwise, a dialog was posted; request will be freed later */
  555. }
  556. /*
  557. * Set the indicator that the invocation Id has been returned
  558. * add a timer so that we can return status info once the
  559. * caller has gotten the invocation Id.
  560. */
  561. SET_INV_ID_RETURNED(invp->state);
  562. XtAppAddTimeOut(XtWidgetToApplicationContext(w),
  563. 0 /* call back immediately */,
  564. (XtTimerCallbackProc) _DtActTimerCB,
  565. (XtPointer) invp->id );
  566. _DtSvcAppUnlock(*_DtInitAppContextp);
  567. _DtSvcAppUnlock(app);
  568. return invp->id;
  569. }
  570. void
  571. DtDbReloadNotify( DtDbReloadCallbackProc proc, XtPointer client_data)
  572. {
  573. Tt_status status;
  574. Tt_pattern pattern;
  575. char * sessId;
  576. extern XtAppContext *_DtInitAppContextp;
  577. if (NULL == proc) return;
  578. _DtSvcAppLock(*_DtInitAppContextp);
  579. /*
  580. * Check if we need to initialize tooltalk
  581. */
  582. status = _DtInitializeToolTalk(NULL);
  583. if (TT_OK != status) {
  584. _DtSvcAppUnlock(*_DtInitAppContextp);
  585. return;
  586. }
  587. /*
  588. * This function register a ToolTalk pattern for every
  589. * callback added.
  590. */
  591. pattern = tt_pattern_create();
  592. if (tt_ptr_error(pattern) != TT_OK) {
  593. _DtSvcAppUnlock(*_DtInitAppContextp);
  594. return;
  595. }
  596. if (tt_pattern_scope_add(pattern, TT_SESSION) != TT_OK) {
  597. _DtSvcAppUnlock(*_DtInitAppContextp);
  598. return;
  599. }
  600. if (tt_pattern_category_set(pattern, TT_OBSERVE) != TT_OK) {
  601. _DtSvcAppUnlock(*_DtInitAppContextp);
  602. return;
  603. }
  604. if (tt_pattern_class_add(pattern, TT_NOTICE) != TT_OK) {
  605. _DtSvcAppUnlock(*_DtInitAppContextp);
  606. return;
  607. }
  608. if (tt_pattern_state_add(pattern, TT_SENT) != TT_OK) {
  609. _DtSvcAppUnlock(*_DtInitAppContextp);
  610. return;
  611. }
  612. sessId = tt_default_session();
  613. if (tt_pattern_session_add(pattern, sessId) != TT_OK) {
  614. _DtSvcAppUnlock(*_DtInitAppContextp);
  615. return;
  616. }
  617. tt_free( sessId );
  618. if (tt_pattern_op_add(pattern, "DtTypes_Reloaded") != TT_OK) {
  619. _DtSvcAppUnlock(*_DtInitAppContextp);
  620. return;
  621. }
  622. /*
  623. * Store information needed by the callback in the user data
  624. * fields of the pattern.
  625. */
  626. status = tt_pattern_user_set(pattern, 0, (void *)proc);
  627. if (status != TT_OK) {
  628. _DtSvcAppUnlock(*_DtInitAppContextp);
  629. return;
  630. }
  631. status = tt_pattern_user_set(pattern, 1, (void *)client_data);
  632. if (status != TT_OK) {
  633. _DtSvcAppUnlock(*_DtInitAppContextp);
  634. return;
  635. }
  636. /*
  637. * _DbReloadCB is the ToolTalk callback which will call
  638. * the user callback.
  639. */
  640. if (tt_pattern_callback_add(pattern, _DbReloadCB) != TT_OK) {
  641. _DtSvcAppUnlock(*_DtInitAppContextp);
  642. return;
  643. }
  644. if (tt_pattern_register(pattern) != TT_OK) {
  645. _DtSvcAppUnlock(*_DtInitAppContextp);
  646. return;
  647. }
  648. _DtSvcAppUnlock(*_DtInitAppContextp);
  649. }
  650. /******************************************************************************
  651. ******************************************************************************
  652. *
  653. * Private API Functions
  654. *
  655. ******************************************************************************
  656. *****************************************************************************/
  657. static void
  658. _DtActTimerCB( XtPointer clientData, XtIntervalId IntId)
  659. {
  660. _DtActExecutionLeafNodeCleanup((unsigned long)clientData,
  661. NULL,0,True);
  662. }
  663. static void
  664. _DtActIndicatorCB( XtPointer clientData, XtIntervalId IntId )
  665. {
  666. unsigned long invocId = (unsigned long) clientData;
  667. _DtActInvRecT *invRecP = _DtActFindInvRec( invocId );
  668. if ( !invRecP || IS_INV_FINISHED(invRecP->state) )
  669. {
  670. /* Turn off the activity indicator */
  671. _DtSendActivityDoneNotification();
  672. }
  673. else
  674. {
  675. /*
  676. * Let the action turn off the indicator when invocation
  677. * is complete.
  678. */
  679. SET_INV_INDICATOR_ON(invRecP->state);
  680. }
  681. }
  682. /***************************************************************************
  683. *
  684. * Routines and static data to support DtDbReloadNotify which supplies
  685. * the user with transparent access to the messaging system for
  686. * notification of action/datatypes database changes.
  687. *
  688. ****************************************************************************/
  689. /*
  690. * _DbReloadCB
  691. * A ToolTalk callback function used to map callback arguments to
  692. * the callback function specified by the user. This function invokes the
  693. * user-defined DtReloadNotifyProc callback with the desired client_data.
  694. */
  695. static Tt_callback_action
  696. _DbReloadCB(Tt_message m, Tt_pattern p)
  697. {
  698. DtDbReloadCallbackProc proc;
  699. XtPointer client_data;
  700. /*
  701. * user data 0: DtDbReloadCallbackProc proc;
  702. * user data 1: XtPointer client_data;
  703. */
  704. proc = (DtDbReloadCallbackProc)tt_pattern_user(p, 0);
  705. client_data = (XtPointer)tt_pattern_user(p, 1);
  706. /*
  707. * Call registered callback function.
  708. */
  709. if (proc) (*proc)(client_data);
  710. return TT_CALLBACK_PROCESSED;
  711. }
  712. /***************************************************************************/
  713. /***************************************************************************/
  714. /* Error Dialog Code */
  715. /***************************************************************************/
  716. /***************************************************************************/
  717. /*
  718. * 'Ok' callback for the generic error dialogs. It will simply destroy
  719. * the dialog.
  720. */
  721. static void
  722. FreeErrorDialog(
  723. Widget w,
  724. XtPointer user_data,
  725. XtPointer call_data )
  726. {
  727. XtDestroyWidget(XtParent(w));
  728. }
  729. /*
  730. * Generic function used to create an error dialog.
  731. */
  732. void
  733. _DtCreateErrorDialog(
  734. Widget w,
  735. String actionName,
  736. XmString msg )
  737. {
  738. String title;
  739. int n;
  740. Arg args[10];
  741. Widget dialog;
  742. XmString ok;
  743. XWindowAttributes xwa;
  744. Status status;
  745. Boolean is_mapped = False;
  746. char *fmt;
  747. fmt = XtNewString((char *)Dt11GETMESSAGE(2, 1, "%1$s%2$s%3$s"));
  748. /* Create the title string for the dialog */
  749. title = (char *)XtMalloc((Cardinal)(strlen(PromptDialogTitle) +
  750. strlen(actionName) +
  751. strlen(ErrorPostfix) +
  752. strlen(fmt) + 1));
  753. (void)sprintf(title, fmt, PromptDialogTitle, actionName, ErrorPostfix);
  754. XtFree(fmt);
  755. ok = XmStringCreateLocalized((String)_DtOkString);
  756. if (XtIsRealized(w))
  757. {
  758. status = XGetWindowAttributes (XtDisplay (w), XtWindow (w), &xwa);
  759. if (status && (xwa.map_state == IsViewable))
  760. is_mapped = True;
  761. }
  762. /* Create the error dialog */
  763. n = 0;
  764. XtSetArg(args[n], XmNmessageString, msg); n++;
  765. XtSetArg(args[n], XmNtitle, title); n++;
  766. XtSetArg(args[n], XmNokLabelString, ok); n++;
  767. XtSetArg(args[n], XmNuseAsyncGeometry, True); n++;
  768. if (!is_mapped)
  769. {
  770. XtSetArg (args[n], XmNdefaultPosition, False);
  771. n++;
  772. }
  773. dialog = XmCreateErrorDialog(w, "errorDialog", args, n);
  774. XmStringFree(ok);
  775. XtFree(title);
  776. /* Set up callbacks */
  777. XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
  778. XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON));
  779. XtAddCallback(dialog, XmNokCallback, FreeErrorDialog,
  780. (XtPointer)NULL);
  781. /*
  782. * If the widget is not mapped, center this dialog.
  783. */
  784. if (!is_mapped)
  785. {
  786. Dimension dialogWd, dialogHt;
  787. Widget dialogShell = XtParent(dialog);
  788. XtSetArg(args[0], XmNmappedWhenManaged, False);
  789. XtSetValues(dialogShell, args, 1);
  790. XtManageChild(dialog);
  791. XtRealizeWidget (dialogShell);
  792. XtSetArg(args[0], XmNwidth, &dialogWd);
  793. XtSetArg(args[1], XmNheight, &dialogHt);
  794. XtGetValues(dialog, args, 2);
  795. XtSetArg (args[0], XmNx,
  796. (WidthOfScreen(XtScreen(dialog)) - dialogWd) / 2U);
  797. XtSetArg (args[1], XmNy,
  798. (HeightOfScreen(XtScreen(dialog)) - dialogHt) / 2U);
  799. XtSetValues (dialog, args, 2);
  800. XtSetArg(args[0], XmNmappedWhenManaged, True);
  801. XtSetValues(dialogShell, args, 1);
  802. }
  803. /* Display the dialog */
  804. XtManageChild(dialog);
  805. }
  806. /*
  807. * Error handler for when the user supplied a file name which cannot
  808. * be accessed. Displays an error dialog. Most often, this is caused
  809. * when a filename with an embedded space is received in the object list.
  810. */
  811. static void
  812. InvalidFilename(
  813. Widget w,
  814. String actionName,
  815. String filename )
  816. {
  817. XmString pt1, pt2, msg;
  818. /* Construct the error message */
  819. pt1 = XmStringCreateLocalized(InvalidFileMsg);
  820. pt2 = XmStringCreateLocalized(filename);
  821. msg = XmStringConcat(pt1, pt2);
  822. _DtCreateErrorDialog(w, actionName, msg);
  823. XmStringFree(pt1);
  824. XmStringFree(pt2);
  825. XmStringFree(msg);
  826. }
  827. /*
  828. * Error handler for when the user supplied a host name which cannot
  829. * be accessed. Displays an error dialog.
  830. */
  831. static void
  832. HostAccessError(
  833. Widget w,
  834. String actionName,
  835. String hostName )
  836. {
  837. XmString pt1, pt2, pt3, msg, msg2;
  838. /* Construct the error message */
  839. pt1 = XmStringCreateLocalized(HostErrorMsg);
  840. pt2 = XmStringCreateLocalized(hostName);
  841. pt3 = XmStringCreateLocalized(HostErrorMsg2);
  842. msg = XmStringConcat(pt1, pt2);
  843. msg2 = XmStringConcat(msg, pt3);
  844. _DtCreateErrorDialog(w, actionName, msg2);
  845. XmStringFree(pt1);
  846. XmStringFree(pt2);
  847. XmStringFree(pt3);
  848. XmStringFree(msg);
  849. XmStringFree(msg2);
  850. }
  851. /*
  852. * Error handler for when the user supplied a collection of host names
  853. * which cannot be accessed. Displays an error dialog.
  854. */
  855. static void
  856. MultiHostAccessError(
  857. Widget w,
  858. String actionName,
  859. String hostList )
  860. {
  861. XmString msg;
  862. char * buf = XtMalloc(strlen(MultiHostErrorMsg) + strlen(hostList) + 10);
  863. sprintf(buf, MultiHostErrorMsg, hostList);
  864. msg = XmStringCreateLocalized(buf);
  865. _DtCreateErrorDialog(w, actionName, msg);
  866. XmStringFree(msg);
  867. XtFree(buf);
  868. }
  869. /***************************************************************************
  870. *
  871. * MapError - this function creates an error message when an action
  872. * cannot be executed because of too many "MAPs".
  873. *
  874. * PARAMETERS:
  875. *
  876. * Widget w; - Widget needed for posting the error dialog.
  877. *
  878. * String actionName; - The name of the action.
  879. *
  880. * RETURN: void
  881. *
  882. ****************************************************************************/
  883. static void
  884. MapError(
  885. Widget w,
  886. String actionName )
  887. {
  888. XmString msg = XmStringCreateLocalized(MapErrorMsg);
  889. _DtCreateErrorDialog(w, actionName, msg);
  890. XmStringFree(msg);
  891. }
  892. /*
  893. * Error handler for when an action definition cannot be found to
  894. * match an object of a particular type. Displays an error dialog.
  895. * A different message is displayed when no objects is supplied.
  896. */
  897. /*
  898. * RWV:
  899. * Since we use tmp files for buffers and do not support
  900. * strings; we need not add special code for buffer and
  901. * string support.
  902. */
  903. /* fdt: Will need to also handle a string or a buffer ... eventually */
  904. static void
  905. NoActionError(
  906. Widget w,
  907. DtShmBoson origNameQuark,
  908. char * actionName,
  909. char * type,
  910. char * host,
  911. char * dir,
  912. char * file )
  913. {
  914. char *msgbuf = XtMalloc(2*MAXPATHLEN);
  915. XmString msg;
  916. char * name = NULL;
  917. /* Construct the error message */
  918. if ((host == NULL) && (dir == NULL) && (file == NULL) && (type == NULL) )
  919. {
  920. (void)sprintf(msgbuf,NoActionMsg2,actionName);
  921. }
  922. else if ( (type != NULL ) && (file == NULL) && (dir == NULL))
  923. {
  924. /*
  925. * We are dealing with a buffer object for which an action couldn't
  926. * be located.
  927. */
  928. (void)sprintf(msgbuf,NoActionMsg3,actionName,type);
  929. }
  930. else
  931. {
  932. name = (char *)XtMalloc((Cardinal)((host ? strlen(host) : 0) +
  933. (dir ? strlen(dir) : 0) +
  934. (file ? strlen(file) : 0) + 10));
  935. name[0] = '\0';
  936. /* Construct the file name */
  937. if (host)
  938. {
  939. (void)strcat(name, host);
  940. (void)strcat(name, ":");
  941. }
  942. if (dir)
  943. {
  944. (void)strcat(name, dir);
  945. if (strcmp(dir, "/") != 0)
  946. (void)strcat(name, "/");
  947. }
  948. if (file)
  949. (void)strcat(name, file);
  950. (void)sprintf(msgbuf,NoActionMsg,actionName,name,type);
  951. }
  952. msg = XmStringCreateLocalized(msgbuf);
  953. _DtCreateErrorDialog(w, actionName, msg);
  954. XmStringFree(msg);
  955. XtFree(msgbuf);
  956. XtFree(name);
  957. }
  958. /*
  959. * Error handler for when the Command Invoker detects an error, and
  960. * send us a failure response to our action request.
  961. * Display an error dialog.
  962. */
  963. static void
  964. CommandInvokerError(
  965. Widget w,
  966. String actionName,
  967. String errorString )
  968. {
  969. XmString msg;
  970. msg = XmStringCreateLocalized(errorString);
  971. _DtCreateErrorDialog(w, actionName, msg);
  972. XmStringFree(msg);
  973. }
  974. /*
  975. * If an action requires a ToolTalk connection, and we were unable to get
  976. * one, then we will fail and post an error dialog.
  977. */
  978. static void
  979. NoToolTalkConnectionError(
  980. Widget w,
  981. String actionName,
  982. Tt_status status)
  983. {
  984. XmString msg;
  985. char *errmsg, *statmsg;
  986. if (TT_OK == status)
  987. statmsg = "";
  988. else
  989. statmsg = tt_status_message(status);
  990. errmsg = XtMalloc(strlen(NoToolTalkConnMsg) + strlen(statmsg) + 2);
  991. sprintf(errmsg, NoToolTalkConnMsg, statmsg);
  992. msg = XmStringCreateLocalized(errmsg);
  993. _DtCreateErrorDialog(w, actionName, msg);
  994. XtFree(errmsg);
  995. XmStringFree(msg);
  996. }
  997. static void
  998. TmpFileCreateError( Widget w, char *actionName, char *dirName)
  999. {
  1000. XmString msg;
  1001. char *msgbuf = XtMalloc(_DtAct_MAX_BUF_SIZE);
  1002. sprintf(msgbuf,TmpFileCreateErrorMsg,_DtActNULL_GUARD(dirName),
  1003. actionName);
  1004. msg = XmStringCreateLocalized(msgbuf);
  1005. _DtCreateErrorDialog(w, actionName, msg);
  1006. XmStringFree(msg);
  1007. XtFree(msgbuf);
  1008. }
  1009. static void
  1010. TmpFileOpenError( Widget w, char *actionName, char *fileName)
  1011. {
  1012. XmString msg;
  1013. char *msgbuf = XtMalloc(_DtAct_MAX_BUF_SIZE);
  1014. sprintf(msgbuf,TmpFileOpenErrorMsg,_DtActNULL_GUARD(fileName),
  1015. actionName);
  1016. msg = XmStringCreateLocalized(msgbuf);
  1017. _DtCreateErrorDialog(w, actionName, msg);
  1018. XmStringFree(msg);
  1019. XtFree(msgbuf);
  1020. }
  1021. static void
  1022. TmpFileWriteError( Widget w, char *actionName, char *fileName)
  1023. {
  1024. XmString msg;
  1025. char *msgbuf = XtMalloc(_DtAct_MAX_BUF_SIZE);
  1026. sprintf(msgbuf,TmpFileWriteErrorMsg,_DtActNULL_GUARD(fileName),
  1027. actionName);
  1028. msg = XmStringCreateLocalized(msgbuf);
  1029. _DtCreateErrorDialog(w, actionName, msg);
  1030. XmStringFree(msg);
  1031. XtFree(msgbuf);
  1032. }
  1033. static void
  1034. UnSupportedObject( Widget w, char *actionName, int objClass)
  1035. {
  1036. XmString msg;
  1037. char *msgbuf = XtMalloc(_DtAct_MAX_BUF_SIZE);
  1038. sprintf(msgbuf,UnSupportedObjMsg,objClass,actionName);
  1039. msg = XmStringCreateLocalized(msgbuf);
  1040. _DtCreateErrorDialog(w, actionName, msg);
  1041. XmStringFree(msg);
  1042. XtFree(msgbuf);
  1043. }
  1044. /***************************************************************************/
  1045. /***************************************************************************/
  1046. /* Main Work Functions For _DtActionInvoke() */
  1047. /***************************************************************************/
  1048. /***************************************************************************/
  1049. /*
  1050. * Load the globals pointing to any localizable strings.
  1051. */
  1052. static void
  1053. InitLocalizedStrings( void )
  1054. {
  1055. PromptDialogTitle = XtNewString(((char *)Dt11GETMESSAGE(2, 3, "Action: ")));
  1056. ErrorPostfix = XtNewString(((char *)Dt11GETMESSAGE(2, 4, " [Error]")));
  1057. PromptDialogLabel = XtNewString(
  1058. ((char *)Dt11GETMESSAGE(2, 5, "Please enter the following information:")));
  1059. ContinueMessage = XtNewString(
  1060. ((char *)Dt11GETMESSAGE(2, 6, "You have supplied more parameters than the selected action requires.\n\nSelect 'Ok' to ignore extra parameters.\n\nSelect 'Cancel' to terminate the action.")));
  1061. HostErrorMsg =XtNewString(((char *)Dt11GETMESSAGE(2, 7, "The following host was not accessible:\n\n ")));
  1062. #ifdef _SUN_OS
  1063. HostErrorMsg2 =XtNewString(((char *)Dt11GETMESSAGE(2, 8, "\n\nThis may be because the remote host's file\nsystem is not properly mounted.\n\n")));
  1064. #else
  1065. HostErrorMsg2 =XtNewString(((char *)Dt11GETMESSAGE(2, 8, "\n\nCheck that the appropriate remote data access connection\nhas been made.\n\n(See \"The Common Desktop Environment User's Guide\"\nfor more information.)\n")));
  1066. #endif
  1067. NoActionMsg =XtNewString(
  1068. ((char *)Dt11GETMESSAGE(2, 9, "Either action \"%s\" was not found\n or\nthis action does not apply to the file:\n \"%s\"\nwith data attribute: \"%s%\"\n\n")));
  1069. NoActionMsg2 = XtNewString(((char *)Dt11GETMESSAGE(2, 10, "Action \"%s\" was not found.\n")));
  1070. InvalidFileMsg = XtNewString(((char *)Dt11GETMESSAGE(2, 11, "The following file was not found:\n\n ")));
  1071. MapErrorMsg = XtNewString(((char *)Dt11GETMESSAGE(2, 12, "This action cannot be executed because it contains too\nmany levels of MAPs, or the mapping is \"circular\".")));
  1072. MultiHostErrorMsg =XtNewString(((char *)Dt11GETMESSAGE(2,13, "Unable to invoke the requested action.\n\nAre the following hosts accessible?\n (%s)\nDoes the corresponding program exist?\n(Run " CDE_INSTALLATION_TOP "/bin/dttypes to match actions and programs.)\n\nHas your system run out of room to execute new processes?")));
  1073. IcccmReqErrorMsg = XtNewString(((char *)Dt11GETMESSAGE(2,14,"The request to service this action has failed")));
  1074. NoToolTalkConnMsg = XtNewString(((char *)Dt11GETMESSAGE(2,15,"The request to service this action has failed.\nA ToolTalk connection could not be established:\n\n%s")));
  1075. ToolTalkErrorMsg = XtNewString(((char *)Dt11GETMESSAGE(2,16, "The request to service this action has failed")));
  1076. ToolTalkErrorMsg2 = XtNewString(((char *)Dt11GETMESSAGE(2,17, "The request to service this action has failed for the following reason:\n\n %s")));
  1077. TtFileArgMapErr = XtNewString((char *)Dt11GETMESSAGE(2,18,"An error occurred while attempting to map one of\nthe file arguments."));
  1078. NoActionMsg3 =XtNewString(
  1079. ((char *)Dt11GETMESSAGE(2, 19, "Either action \"%s\" was not found\n or\nthis action does not apply to buffers of type:\n \"%s\"\n\n")));
  1080. UnSupportedObjMsg = XtNewString(
  1081. ((char *)Dt11GETMESSAGE(2, 21, "Unsupported input object class: \"%d\"\nfor action: \"%s\".")));
  1082. TmpFileCreateErrorMsg = XtNewString(
  1083. ((char *)Dt11GETMESSAGE(2, 22, "Unable to create a temporary file in directory: \"%s\"\nfor the action named: \"%s\"")));
  1084. TmpFileOpenErrorMsg = XtNewString(
  1085. ((char *)Dt11GETMESSAGE(2, 23, "Unable to open a temporary file: \"%s\"\nfor the action named: \"%s\"")));
  1086. TmpFileWriteErrorMsg = XtNewString(
  1087. ((char *)Dt11GETMESSAGE(2, 24, "Unable to write a temporary file: \"%s\"\nfor the action named: \"%s\"")));
  1088. }
  1089. /*
  1090. * This function takes the information supplied by the caller of
  1091. * _DtActionInvoke(), and turns it into an internal format. This
  1092. * includes parsing out each of the file names, and converting the
  1093. * type from a string to an integer.
  1094. *
  1095. * The structure returned must be freed up eventually.
  1096. */
  1097. static ActionRequest *
  1098. CreateActionRequest(
  1099. Widget w,
  1100. String actionName,
  1101. DtActionArg *aap,
  1102. int aac,
  1103. String termOpts,
  1104. String execHost,
  1105. String cwdHost,
  1106. String cwdDir,
  1107. _DtActInvRecT *invp )
  1108. {
  1109. register int i, j;
  1110. int numObjects = 0;
  1111. ObjectData * objectDataArray;
  1112. ObjectData objectData;
  1113. register ActionRequest * request;
  1114. /* Allocate a new request structure -- zero filled */
  1115. request = (ActionRequest *) XtCalloc(1,(Cardinal)sizeof(ActionRequest));
  1116. request->actionName = XtNewString(actionName);
  1117. if (termOpts)
  1118. request->termOpts = XtNewString(termOpts);
  1119. if (execHost)
  1120. request->execHost = XtNewString(execHost);
  1121. if (cwdHost)
  1122. request->cwdHost = XtNewString(cwdHost);
  1123. if (cwdDir)
  1124. request->cwdDir = XtNewString(cwdDir);
  1125. request->objsUsed = -1; /* -1 => not yet determined */
  1126. if ( invp )
  1127. request->invocId = invp->id;
  1128. /* If there are no objects, then there's no reason to continue */
  1129. if ((aac <= 0) || (aap == NULL))
  1130. return(request);
  1131. /*
  1132. * Allocate space for all the object data at once
  1133. */
  1134. objectDataArray = (ObjectData *) XtCalloc(aac,(sizeof(ObjectData)));
  1135. /*
  1136. * process object names -- assume all file names are of the form
  1137. * /path/file (do NOT allow host:/path/file)
  1138. */
  1139. for ( i = 0; i < aac ; i++ )
  1140. {
  1141. memset((void *)&objectData,0,sizeof(ObjectData));
  1142. if ( (aap+i)->argClass == DtACTION_FILE )
  1143. {
  1144. if (ParseFileArgument(w, request, &objectData, NULL ,
  1145. aap[i].u.file.name, NULL , True))
  1146. {
  1147. XtFree((char *)objectDataArray);
  1148. return(NULL);
  1149. }
  1150. }
  1151. else if ( (aap+i)->argClass == DtACTION_BUFFER )
  1152. {
  1153. /*
  1154. * Check if we've already created a tmp file for this buffer
  1155. * if so fill in the request structure as if this were a file
  1156. * object.
  1157. */
  1158. if ( invp->info[i].name )
  1159. {
  1160. /*
  1161. * Use the tmp file name and type stored in the invocation rec.
  1162. * The FILE bit will be set in the object mask -- we will also
  1163. * set the BUFFER bit to indicate that this is a tmp file
  1164. * representing a buffer.
  1165. */
  1166. if (ParseFileArgument(w, request, &objectData, NULL ,
  1167. invp->info[i].name, invp->info[i].type , True))
  1168. {
  1169. XtFree((char *)objectDataArray);
  1170. return(NULL);
  1171. }
  1172. /*
  1173. * Set the buffer object bit as well -- and check whether
  1174. * this buffer is intended to be writable, if not reset the
  1175. * writable bit set in ParseFileArgument().
  1176. */
  1177. SET_BUFFER_OBJ(objectData.mask);
  1178. if ( !(aap[i].u.buffer.writable) )
  1179. RESET_WRITE_OBJ(objectData.mask);
  1180. /*
  1181. * Save the buffer type info if we have it
  1182. */
  1183. if ( aap[i].u.buffer.type )
  1184. objectData.type = _DtDtsMMStringToBoson(aap[i].u.buffer.type);
  1185. /*
  1186. * Save the original buffer pointer and size for this
  1187. * pseudo-file.
  1188. */
  1189. if ( aap[i].u.buffer.bp )
  1190. {
  1191. objectData.u.file.bp = aap[i].u.buffer.bp;
  1192. objectData.u.file.sizebp = aap[i].u.buffer.size;
  1193. }
  1194. }
  1195. else
  1196. {
  1197. /* Do buffer stuff here */
  1198. SET_BUFFER_OBJ(objectData.mask);
  1199. if ( aap[i].u.buffer.writable )
  1200. SET_WRITE_OBJ(objectData.mask);
  1201. /*
  1202. * If the buffer type has been passed in to us save its quark
  1203. * in the object structure now. When/if the type is determined
  1204. * later this object record should be filled in with the
  1205. * necessary quark.
  1206. */
  1207. if ( aap[i].u.buffer.type )
  1208. objectData.type = _DtDtsMMStringToBoson(aap[i].u.buffer.type);
  1209. else
  1210. {
  1211. /*
  1212. * We have already determined the buffer type when creating
  1213. * the invocation record. So get the type string
  1214. * from the invocation record.
  1215. */
  1216. myassert(invp->info[i].type);
  1217. if (invp->info[i].type)
  1218. {
  1219. objectData.type = _DtDtsMMStringToBoson(invp->info[i].type);
  1220. }
  1221. }
  1222. /*
  1223. * Save buffer contents
  1224. */
  1225. if ( aap[i].u.buffer.bp )
  1226. {
  1227. objectData.u.buffer.size = aap[i].u.buffer.size;
  1228. objectData.u.buffer.bp = aap[i].u.buffer.bp;
  1229. } else
  1230. {
  1231. myassert(0 /* null buffer pointer */ );
  1232. objectData.u.buffer.bp = NULL;
  1233. objectData.u.buffer.size = 0;
  1234. }
  1235. }
  1236. }
  1237. /* structure assignment */
  1238. objectDataArray[i] = objectData;
  1239. numObjects++;
  1240. }
  1241. request->numObjects = numObjects;
  1242. request->objects = objectDataArray;
  1243. return(request);
  1244. }
  1245. /******************************************************************************
  1246. *
  1247. * static _DtActInvRecT *
  1248. * CreateInvocationRecord(actionName,w,aap,aac)
  1249. * Create an invocation record and fill in argument information
  1250. * return a pointer to the newly allocated invocation record.
  1251. *
  1252. *****************************************************************************/
  1253. static _DtActInvRecT *
  1254. CreateInvocationRecord(
  1255. char *actionName,
  1256. Widget w,
  1257. DtActionArg *aap,
  1258. int aac)
  1259. {
  1260. register int i;
  1261. _DtActInvRecT *invp; /* pointer to invocation record */
  1262. char *tmp;
  1263. /*
  1264. * allocate invocation record and ID to return to caller
  1265. */
  1266. invp = _DtActAllocInvRec();
  1267. if ( !invp )
  1268. {
  1269. /*
  1270. * RWV --> ideally we would need error message here
  1271. * but if we are unable to allocate the record we
  1272. * would in all likelyhood be unable to allocate the
  1273. * error message as well. We will essentially assume
  1274. * allocation does not fail as is done throughout the
  1275. * library.
  1276. */
  1277. return NULL;
  1278. }
  1279. myassert(invp->id != 0);
  1280. SET_INV_PENDING(invp->state);
  1281. invp->w = w;
  1282. invp->numChildren = 0;
  1283. invp->childRec = NULL;
  1284. /*
  1285. * Fill in argument information
  1286. */
  1287. invp->ac = aac;
  1288. if (aac == 0) {
  1289. invp->info = NULL;
  1290. return invp;
  1291. }
  1292. invp->info = (_DtActArgInfo *)XtCalloc(aac,sizeof(_DtActArgInfo));
  1293. for ( i=0; i < aac; i++ )
  1294. {
  1295. if ( aap[i].argClass == DtACTION_BUFFER )
  1296. {
  1297. int fd; /* tmp file descriptor */
  1298. char *format; /* name template (printf format) */
  1299. char *is_executable; /* IS_EXECUTABLE attribute */
  1300. mode_t mode;
  1301. int bytesToWrite, bytesWritten;
  1302. int closeAttempts;
  1303. SET_BUFFER_OBJ(invp->info[i].mask);
  1304. if ( aap[i].u.buffer.writable )
  1305. SET_WRITE_OBJ(invp->info[i].mask);
  1306. /* save original buffer size */
  1307. invp->info[i].size = aap[i].u.buffer.size;
  1308. /*
  1309. * Determine the type of the buffer object.
  1310. * Typing based on the object name takes precedence
  1311. * over the type "hint".
  1312. */
  1313. if ( aap[i].u.buffer.name
  1314. || (aap[i].u.buffer.type == NULL) )
  1315. {
  1316. tmp = DtDtsBufferToDataType(
  1317. aap[i].u.buffer.bp,aap[i].u.buffer.size,
  1318. aap[i].u.buffer.name);
  1319. /*
  1320. * Malloc our own copy of the type string so we won't
  1321. * have to worry about when to call DtDtsFreeDataType() later.
  1322. */
  1323. invp->info[i].type = XtNewString(tmp);
  1324. DtDtsFreeDataType(tmp);
  1325. } else
  1326. {
  1327. invp->info[i].type = XtNewString(aap[i].u.buffer.type);
  1328. }
  1329. /*
  1330. * Simply create tmp files for ALL buffers.
  1331. *
  1332. * This allows us to work around problems related to client
  1333. * programs making subsequent changes to or freeing the memory
  1334. * associated with the buffer before we are through with it.
  1335. *
  1336. * For actions of type CMD we need to have files anyway.
  1337. *
  1338. * Be sure to create tmp files with
  1339. * a suffix proper for the buffer type.
  1340. */
  1341. /* first determine the permissions for the new tmp file */
  1342. is_executable =
  1343. DtDtsDataTypeToAttributeValue(invp->info[i].type,
  1344. _DtActIS_EXECUTABLE,NULL);
  1345. /*
  1346. * The tmp file should at LEAST be readable
  1347. */
  1348. mode=( S_IRUSR | S_IRGRP | S_IROTH );
  1349. if ( aap[i].u.buffer.writable )
  1350. mode |= ( S_IWUSR | S_IWGRP | S_IWOTH );
  1351. if ( is_executable
  1352. && DtDtsIsTrue(is_executable) )
  1353. mode |= ( S_IXUSR | S_IXGRP | S_IXOTH );
  1354. DtDtsFreeAttributeValue(is_executable);
  1355. if ( aap[i].u.buffer.name )
  1356. {
  1357. /*
  1358. * Attempt to use the name supplied for the buffer.
  1359. */
  1360. invp->info[i].name = _DtActGenerateTmpFile(NULL,
  1361. aap[i].u.buffer.name,mode,&fd);
  1362. }
  1363. if ( !invp->info[i].name )
  1364. {
  1365. /*
  1366. * Generate tmp file based on format supplied for the
  1367. * file type.
  1368. */
  1369. format = DtDtsDataTypeToAttributeValue(invp->info[i].type,
  1370. _DtActNAME_TEMPLATE,NULL);
  1371. invp->info[i].name = _DtActGenerateTmpFile(NULL,format,mode,&fd);
  1372. DtDtsFreeAttributeValue(format);
  1373. }
  1374. if ( !invp->info[i].name )
  1375. {
  1376. /*
  1377. * Unable to generate usable tmp file name.
  1378. */
  1379. /*
  1380. * Error message makes assertion message redundant.
  1381. * myassert(invp->info[i].name);
  1382. */
  1383. TmpFileCreateError(w,actionName,_DtGetDtTmpDir());
  1384. RESET_INV_PENDING(invp->state);
  1385. SET_INV_ERROR(invp->state);
  1386. SET_INV_CANCEL(invp->state);
  1387. close(fd);
  1388. return invp;
  1389. }
  1390. /*
  1391. * Write contents of buffer to temp file
  1392. */
  1393. myassert( fd >= 0 );
  1394. for ( bytesToWrite = aap[i].u.buffer.size, bytesWritten = 0;
  1395. bytesToWrite > 0;
  1396. bytesToWrite -= bytesWritten)
  1397. {
  1398. bytesWritten = write(fd,aap[i].u.buffer.bp,bytesToWrite);
  1399. if ( bytesWritten < 0 )
  1400. {
  1401. if (errno == EINTR )
  1402. {
  1403. bytesWritten = 0;
  1404. continue;
  1405. }
  1406. else
  1407. {
  1408. myassert(0 /* Unrecoverable Write Error */);
  1409. TmpFileWriteError(w,actionName,invp->info[i].name);
  1410. close(fd);
  1411. (void) unlink(invp->info[i].name);
  1412. RESET_INV_PENDING(invp->state);
  1413. SET_INV_ERROR(invp->state);
  1414. SET_INV_CANCEL(invp->state);
  1415. return invp;
  1416. }
  1417. }
  1418. }
  1419. closeAttempts = 0;
  1420. while ( close(fd) )
  1421. {
  1422. /* error closing fd */
  1423. if ( closeAttempts > _DT_ACTION_MAX_CLOSE_TRIES )
  1424. break;
  1425. switch ( errno )
  1426. {
  1427. case EBADF: /* invalid fd */
  1428. myassert( 0 );
  1429. break;
  1430. case EINTR: /* interrupted sys call */
  1431. closeAttempts++;
  1432. continue; /* try again */
  1433. case ENOSPC: /* Not enough space on NFS-mounted dev */
  1434. TmpFileWriteError(w,actionName,
  1435. invp->info[i].name);
  1436. unlink(invp->info[i].name);
  1437. RESET_INV_PENDING(invp->state);
  1438. SET_INV_ERROR(invp->state);
  1439. SET_INV_CANCEL(invp->state);
  1440. /* try another close */
  1441. if ( close(fd) )
  1442. {
  1443. /* It should have worked this time */
  1444. myassert(0);
  1445. }
  1446. return invp;
  1447. default: /* anything else */
  1448. myassert(0);
  1449. break;
  1450. }
  1451. break; /* only try again for conditions with continue */
  1452. }
  1453. /*
  1454. * Now that we have created a tmp file for this buffer
  1455. * object set the FILE_OBJ flag as well as the buffer flag.
  1456. * Objects with both the BUFFER and FILE flags set will be
  1457. * recognized as buffers which have been written to tmp files.
  1458. */
  1459. SET_FILE_OBJ(invp->info[i].mask);
  1460. }
  1461. else if ( aap[i].argClass == DtACTION_FILE )
  1462. {
  1463. invp->info[i].name = XtNewString(aap[i].u.file.name);
  1464. SET_FILE_OBJ(invp->info[i].mask);
  1465. SET_WRITE_OBJ(invp->info[i].mask);
  1466. }
  1467. else
  1468. {
  1469. myassert( 0 /* unsupported object */ );
  1470. UnSupportedObject(w, actionName, aap[i].argClass);
  1471. RESET_INV_PENDING(invp->state);
  1472. SET_INV_ERROR(invp->state);
  1473. SET_INV_CANCEL(invp->state);
  1474. return invp;
  1475. }
  1476. }
  1477. return invp;
  1478. }
  1479. static Boolean
  1480. ParseFileArgument(
  1481. Widget w,
  1482. ActionRequest * request,
  1483. ObjectData * objectData,
  1484. String hostname,
  1485. String filename,
  1486. String filetype,
  1487. Boolean typeFile )
  1488. {
  1489. register int i, j;
  1490. String dirName;
  1491. String host;
  1492. String dir;
  1493. int hostId;
  1494. char *resolvedPath=NULL;
  1495. /********************************************************************
  1496. WE NO LONGER ACCEPT host:/path FORMAT
  1497. if (host = _DtHostString(filename))
  1498. {
  1499. hostId = _DtAddEntry(host, &request->hostNames, &request->numHostNames);
  1500. XtFree(host);
  1501. }
  1502. else
  1503. ********************************************************************/
  1504. if ( hostname )
  1505. {
  1506. hostId = _DtAddEntry(hostname, &request->hostNames,
  1507. &request->numHostNames);
  1508. }
  1509. else
  1510. {
  1511. if ( request->cwdHost != NULL )
  1512. {
  1513. hostId = _DtAddEntry(request->cwdHost, &request->hostNames,
  1514. &request->numHostNames);
  1515. }
  1516. else
  1517. {
  1518. /* if all else fails use local host */
  1519. host = _DtGetLocalHostName();
  1520. hostId = _DtAddEntry(host, &request->hostNames,
  1521. &request->numHostNames);
  1522. XtFree(host);
  1523. }
  1524. }
  1525. objectData->u.file.origFilename = XtNewString(filename);
  1526. objectData->u.file.origHostname = XtNewString(hostname);
  1527. objectData->u.file.hostIndex = hostId;
  1528. objectData->u.file.baseFilename = _DtBasename(filename);
  1529. objectData->type = -1;
  1530. /* Hash the directory name */
  1531. if ( (dirName = _DtDirname(filename)) == NULL )
  1532. {
  1533. if ( request->cwdDir )
  1534. dirName = XtNewString(request->cwdDir);
  1535. else
  1536. {
  1537. /* Default to current directory */
  1538. dirName = _DtFindCwd();
  1539. }
  1540. }
  1541. else if ( dirName[0] != '/' )
  1542. {
  1543. /*
  1544. * We have been provided with a relative path name
  1545. * interpret it relative to the context directory.
  1546. */
  1547. String tmpName;
  1548. if ( request->cwdDir )
  1549. tmpName=XtNewString(request->cwdDir);
  1550. else
  1551. tmpName=_DtFindCwd();
  1552. tmpName=XtRealloc(tmpName,strlen(tmpName)+strlen(dirName) +2);
  1553. (void)strcat(tmpName,"/");
  1554. (void)strcat(tmpName,dirName);
  1555. XtFree(dirName);
  1556. dirName=tmpName;
  1557. }
  1558. if ( objectData->u.file.baseFilename == NULL || dirName == NULL )
  1559. {
  1560. /* Invalidly formed file name */
  1561. InvalidFilename(w, request->clonedAction->label, filename);
  1562. _DtFreeRequest (request);
  1563. XtFree(dirName);
  1564. XtFree(objectData->u.file.origFilename);
  1565. XtFree(objectData->u.file.origHostname);
  1566. XtFree(objectData->u.file.baseFilename);
  1567. return(True);
  1568. }
  1569. objectData->u.file.dirIndex = _DtAddEntry(dirName, &request->dirNames,
  1570. &request->numDirNames);
  1571. SET_UNKNOWN_IF_DIR(objectData->mask);
  1572. SET_FILE_OBJ(objectData->mask);
  1573. /*
  1574. * default file objects are treated as writable/returned objects.
  1575. */
  1576. SET_WRITE_OBJ(objectData->mask);
  1577. /*
  1578. * If a type has been provided for this file -- use it.
  1579. * otherwise -- look up the type.
  1580. */
  1581. if (typeFile)
  1582. {
  1583. if ( filetype && *filetype )
  1584. objectData->type = _DtDtsMMStringToBoson(filetype);
  1585. else
  1586. {
  1587. TryToTypeFile(objectData,request->hostNames[hostId],
  1588. dirName, objectData->u.file.baseFilename,
  1589. &resolvedPath);
  1590. if ( resolvedPath )
  1591. {
  1592. struct stat sbuf;
  1593. if ( !stat(resolvedPath,&sbuf) )
  1594. {
  1595. /* successful stat of file -- check permissions */
  1596. if ( !( sbuf.st_mode&S_IWOTH
  1597. || sbuf.st_mode&S_IWGRP
  1598. || sbuf.st_mode&S_IWUSR) )
  1599. {
  1600. RESET_WRITE_OBJ(objectData->mask);
  1601. }
  1602. }
  1603. }
  1604. }
  1605. }
  1606. XtFree(resolvedPath);
  1607. XtFree(dirName);
  1608. return(False);
  1609. }
  1610. /*
  1611. * Returns a string representing the current working directory
  1612. * for this process. This string must be freed up by the caller.
  1613. * NOTE:This function does not replace sym_links with real paths.
  1614. * This may be useful on networks where nfs mounts and symbolic
  1615. * consistently named symbolic links are used to give the
  1616. * impression of a single large network file system.
  1617. */
  1618. String
  1619. _DtFindCwd( void )
  1620. {
  1621. String tmp = 0;
  1622. char buf[MAXPATHLEN + 1];
  1623. if ((tmp = getcwd(buf, MAXPATHLEN)) == NULL)
  1624. {
  1625. _DtSimpleError(
  1626. DtProgName, DtError, NULL,
  1627. "getcwd(): unable to get current directory", NULL);
  1628. tmp = "/";
  1629. }
  1630. return (XtNewString(tmp));
  1631. }
  1632. /*
  1633. * Generic function which checks to see if the specified string is
  1634. * already entered in the passed-in array; if so, then it will return
  1635. * the index of the existing entry within the array; if not, then it
  1636. * will grow the array, add the string into it, and then return the
  1637. * new index.
  1638. */
  1639. static int
  1640. _DtAddEntry(
  1641. register String string,
  1642. register String **arrayPtr,
  1643. register int *sizePtr )
  1644. {
  1645. register int i;
  1646. /* See if the string is already in the array */
  1647. for (i = 0; i < *sizePtr; i++)
  1648. {
  1649. if (strcmp(string, (*arrayPtr)[i]) == 0)
  1650. return(i);
  1651. }
  1652. /* Add the string */
  1653. i = *sizePtr;
  1654. (*sizePtr)++;
  1655. (*arrayPtr) = (String *)XtRealloc((String)*arrayPtr,
  1656. (Cardinal)(sizeof(String) * (*sizePtr)));
  1657. (*arrayPtr)[i] = XtNewString(string);
  1658. return(i);
  1659. }
  1660. /*
  1661. * This function will type the indicated file, only if it is the first
  1662. * parameter file; this is to improve performance, since in many cases,
  1663. * only the first argument is used to 'type' the action, and the others
  1664. * never need to be 'typed'.
  1665. */
  1666. static void
  1667. TryToTypeFile(
  1668. ObjectData *obj,
  1669. char * host,
  1670. char * dir,
  1671. char * file,
  1672. char **resolvedPath )
  1673. {
  1674. /* Follow the link when typing files */
  1675. obj->type = LinkToTypeQuark(host, dir, file, resolvedPath);
  1676. }
  1677. /*
  1678. * Given a file, follow any links, and base the filetype off of the
  1679. * final file, not the link we are passed.
  1680. */
  1681. static int
  1682. LinkToTypeQuark(
  1683. char * host,
  1684. char * dir,
  1685. char * file,
  1686. char **resolvedPath )
  1687. {
  1688. char * path;
  1689. char link_path[MAXPATHLEN + 1];
  1690. char file_name[MAXPATHLEN + 1];
  1691. int link_len;
  1692. char * end;
  1693. int history_count;
  1694. int history_size;
  1695. char ** history;
  1696. int i;
  1697. char * dtype;
  1698. DtShmBoson dquark;
  1699. /* Used to check for symbolic link loops */
  1700. history_count = 0;
  1701. history_size = 100;
  1702. history = (char **)XtMalloc(sizeof(char *) * history_size);
  1703. path = _DtActMapFileName(host, dir, file, NULL);
  1704. if (path == NULL)
  1705. {
  1706. *resolvedPath=NULL;
  1707. return(-1);
  1708. }
  1709. strcpy(file_name, path);
  1710. XtFree(path);
  1711. while ((link_len = readlink(file_name, link_path, MAXPATHLEN)) > 0)
  1712. {
  1713. link_path[link_len] = '\0';
  1714. /* Force the link to be an absolute path, if necessary */
  1715. if (link_path[0] != '/')
  1716. {
  1717. /* Relative paths are relative to the current directory */
  1718. end = DtStrrchr(file_name, '/') + 1;
  1719. *end = '\0';
  1720. strcat(file_name, link_path);
  1721. }
  1722. else
  1723. strcpy(file_name, link_path);
  1724. /* Check for a recursive loop; abort if found */
  1725. for (i = 0; i < history_count; i++)
  1726. {
  1727. if (strcmp(file_name, history[i]) == 0)
  1728. {
  1729. /* Drop back to last non-recursive portion of the path */
  1730. strcpy(file_name, history[history_count-1]);
  1731. for (i = 0; i < history_count; i++)
  1732. XtFree(history[i]);
  1733. XtFree((char *)history);
  1734. dtype = DtDtsFileToDataType(file_name);
  1735. dquark = _DtDtsMMStringToBoson(dtype);
  1736. DtDtsFreeDataType(dtype);
  1737. *resolvedPath = XtNewString(file_name);
  1738. return(dquark);
  1739. }
  1740. }
  1741. /* Add to the history list */
  1742. if (history_count >= history_size)
  1743. {
  1744. history_size += 100;
  1745. history = (char **)XtRealloc((char *)history,
  1746. sizeof(char *) * history_size);
  1747. }
  1748. history[history_count++] = XtNewString(file_name);
  1749. }
  1750. /* Free up the history list */
  1751. for (i = 0; i < history_count; i++)
  1752. XtFree(history[i]);
  1753. XtFree((char *)history);
  1754. dtype = DtDtsFileToDataType(file_name);
  1755. dquark = _DtDtsMMStringToBoson(dtype);
  1756. DtDtsFreeDataType(dtype);
  1757. *resolvedPath = XtNewString(file_name);
  1758. return(dquark);
  1759. }
  1760. /*
  1761. * Given a request, find the action to which it maps, and see if enough
  1762. * parameters were supplied to allow the action to be started. It's
  1763. * possible we may need to bring up a dialog to collect more data, or
  1764. * we may need to invoke multiple actions.
  1765. *
  1766. * The first time an action request is processed, we will check the
  1767. * parameter situation, and will prompt the user, if necessary. The
  1768. * second time the action request is processed (typically when the
  1769. * user closes the parameter collecting dialog), we will simply invoke
  1770. * the action with whatever we have; the user will not be prompted a
  1771. * second time for any missing parameters.
  1772. *
  1773. * If the request is processed (True is returned), then it is up to the
  1774. * caller to free up the request structure.
  1775. */
  1776. static Boolean
  1777. ProcessRequest(
  1778. Widget w,
  1779. register ActionRequest *request )
  1780. {
  1781. int unused;
  1782. register ActionPtr action;
  1783. int numPrompts;
  1784. PromptEntry * prompts;
  1785. DtShmBoson actionQuark;
  1786. Tt_status status = TT_OK;
  1787. /* See if this is the first pass for the request */
  1788. if (request->clonedAction == NULL)
  1789. {
  1790. /* Always start with the first host, when processing a request */
  1791. request->hostIndex = 0;
  1792. /* Find the action DB entry which we map to */
  1793. actionQuark = _DtDtsMMStringToBoson(request->actionName);
  1794. RESET_TOO_MANY_MAPS(request->mask);
  1795. if (actionQuark == -1 || (action = _DtActionFindDBEntry(request, actionQuark)) == NULL)
  1796. {
  1797. /*
  1798. * No action label is available here for error dialogs
  1799. */
  1800. if (IS_TOO_MANY_MAPS(request->mask))
  1801. {
  1802. MapError (w, request->actionName);
  1803. }
  1804. else if (request->numObjects > 0)
  1805. {
  1806. if (IS_FILE_OBJ(request->objects[0].mask))
  1807. {
  1808. NoActionError(w, actionQuark,
  1809. request->actionName,
  1810. (char *)_DtDtsMMBosonToString(request->objects[0].type),
  1811. request->hostNames[request->objects[0].u.file.hostIndex],
  1812. request->dirNames[request->objects[0].u.file.dirIndex],
  1813. request->objects[0].u.file.baseFilename);
  1814. }
  1815. else if ( IS_BUFFER_OBJ(request->objects[0].mask) )
  1816. {
  1817. /*
  1818. * RWV -- may have to modify this call to generate a
  1819. * message more suitable for buffer objects.
  1820. */
  1821. NoActionError(w, actionQuark,
  1822. request->actionName,
  1823. (char *)_DtDtsMMBosonToString(request->objects[0].type),
  1824. NULL, /* host */
  1825. NULL, /* dir */
  1826. "Memory Object" /* filename */);
  1827. } else
  1828. myassert(0 /* should never get here */ );
  1829. /* fdt: add code for strings
  1830. * else if (IS_STRING_OBJ(request->objects[0].mask))
  1831. */
  1832. }
  1833. else
  1834. NoActionError(w, actionQuark, request->actionName,
  1835. NULL, NULL, NULL, NULL);
  1836. /*
  1837. * If we are in the middle of reprocessing a single argument
  1838. * action, then continue with the next parameter. Otherwise,
  1839. * this error terminates the request, so return.
  1840. */
  1841. if (IS_REPROCESSING(request->mask) && MoreArgumentsToProcess(request))
  1842. return(ProcessRequest(w, request));
  1843. /*
  1844. * We were never able to start this action.
  1845. */
  1846. {
  1847. _DtActInvRecT *invRecP = _DtActFindInvRec(request->invocId);
  1848. if (invRecP) SET_INV_ERROR(invRecP->state);
  1849. }
  1850. return(True);
  1851. }
  1852. request->clonedAction = action;
  1853. /*
  1854. * If this is a ToolTalk message, then before proceeding any further,
  1855. * make sure we can get connected to a ToolTalk session. If we can't,
  1856. * then we need to bail out.
  1857. */
  1858. if (IS_TT_MSG(action->mask) &&
  1859. (status = _DtInitializeToolTalk(NULL)) != TT_OK)
  1860. {
  1861. NoToolTalkConnectionError(w, request->clonedAction->label, status);
  1862. {
  1863. _DtActInvRecT *invRecP = _DtActFindInvRec(request->invocId);
  1864. if (invRecP) SET_INV_ERROR(invRecP->state);
  1865. }
  1866. return(True);
  1867. }
  1868. /* Determine how we are sitting with parameters */
  1869. unused = MatchParamsToAction(request, &numPrompts, &prompts);
  1870. request->objsUsed = request->numObjects - unused;
  1871. myassert(request->objsUsed >= 0);
  1872. /*
  1873. * Do we need to create a prompt dialog?
  1874. * NOTE: if the action requires the user to be prompted, but the
  1875. * user has supplied extra parameters, so he will be asked
  1876. * to abort or continue, do the abort/continue dialog BEFORE
  1877. * the prompt dialog; there's little sense in collecting
  1878. * additional input if the user is going to abort the action!
  1879. */
  1880. if ((prompts != NULL) &&
  1881. ((unused == 0) || IS_ARG_SINGLE_ARG(action->mask) ||
  1882. IS_ARG_NONE_FOUND(action->mask)))
  1883. {
  1884. CreatePromptDialog(w, request, numPrompts, prompts);
  1885. XtFree((char *)prompts);
  1886. return(False);
  1887. }
  1888. /* Were too many parameters supplied? */
  1889. else if (unused > 0)
  1890. {
  1891. /*
  1892. * If the action only needs a single parameter, then we need
  1893. * to fire off multiple instances of the action; otherwise,
  1894. * prompt the user to continue or abort. An action requiring
  1895. * no parameters is also treated like a single parameter action.
  1896. */
  1897. if (IS_ARG_SINGLE_ARG(action->mask) || IS_ARG_NONE_FOUND(action->mask))
  1898. {
  1899. PrepareAndExecuteAction(w, request);
  1900. /* See if there are still more parameters to be processed */
  1901. if (MoreArgumentsToProcess(request))
  1902. return(ProcessRequest(w, request));
  1903. }
  1904. else
  1905. {
  1906. /*
  1907. * Postpone any further processing until the user either
  1908. * tells us to continue, or abort.
  1909. */
  1910. CreateContinueDialog(w, request, numPrompts, prompts);
  1911. XtFree((char *)prompts);
  1912. return(False);
  1913. }
  1914. }
  1915. else
  1916. {
  1917. PrepareAndExecuteAction(w, request);
  1918. }
  1919. }
  1920. else
  1921. {
  1922. PrepareAndExecuteAction(w, request);
  1923. action = request->clonedAction;
  1924. /*
  1925. * If this is a single argument action, and we have more parameters
  1926. * waiting to be processed, then continue processing them.
  1927. */
  1928. if ((IS_ARG_SINGLE_ARG(action->mask) || IS_ARG_NONE_FOUND(action->mask))
  1929. && (MoreArgumentsToProcess(request)))
  1930. {
  1931. return(ProcessRequest(w, request));
  1932. }
  1933. }
  1934. return(True);
  1935. }
  1936. /*
  1937. * This function is called at the point where we have collected all of the
  1938. * information needed to actually initiate the action. We will use the
  1939. * set of arguments passed into _DtActionInvoke(), along with any values
  1940. * supplied through the prompt dialog. It is also at this point that
  1941. * the thread of control will split, dependent upon the type of action
  1942. * being executed (Command Invoker, Tooltalk).
  1943. */
  1944. static void
  1945. PrepareAndExecuteAction(
  1946. Widget w,
  1947. register ActionRequest *request )
  1948. {
  1949. char * relPathHost;
  1950. char * relPathDir;
  1951. register int i;
  1952. register ActionPtr action = request->clonedAction;
  1953. int argNum;
  1954. _DtActInvRecT *invp; /* pointer to invocation record */
  1955. _DtActChildRecT *childrecp; /* pointer to child record */
  1956. /*
  1957. * We have gathered all the information necessary to invoke
  1958. * this action all dialogs have been posted and processed.
  1959. * Now create the action invocation record -- unless we are
  1960. * in the midst of reprocessing an already invoked action.
  1961. */
  1962. invp = _DtActFindInvRec(request->invocId);
  1963. myassert(invp);
  1964. SET_INV_WORKING(invp->state);
  1965. /*
  1966. * Allocate a child rec -- fill it in
  1967. */
  1968. if ( (childrecp = _DtActAllocChildRec(invp)) != NULL )
  1969. {
  1970. request->childId = childrecp->childId;
  1971. childrecp->childState = _DtActCHILD_PENDING_START;
  1972. childrecp->mask = action->mask;
  1973. childrecp->numObjects = request->objsUsed;
  1974. }
  1975. else
  1976. myassert( 0 /* Unable to allocate childRec */ );
  1977. /*
  1978. * Before proceeding, we need to determine what host and directory
  1979. * will be used when resolving relative pathnames.
  1980. */
  1981. __ExtractCWD(request, &relPathHost, &relPathDir, False);
  1982. if (IS_CMD(action->mask))
  1983. {
  1984. /*
  1985. * All buffer objects must be placed into temporary files for
  1986. * command actions. This has already been done when the
  1987. * request structure was created.
  1988. */
  1989. if (childrecp && childrecp->numObjects > 0)
  1990. {
  1991. childrecp->argMap =
  1992. (_DtActArgMap *)XtCalloc(childrecp->numObjects,
  1993. sizeof(_DtActArgMap));
  1994. for ( i = 0; i < childrecp->numObjects && i < invp->ac; i++ )
  1995. {
  1996. childrecp->argMap[i].argN = i+1; /* ignored for CMD actions */
  1997. childrecp->argMap[i].argIdx =
  1998. i + request->objOffset; /* idx into invp->info[] */
  1999. }
  2000. }
  2001. ProcessCommandInvokerRequest(w, request, relPathHost, relPathDir);
  2002. }
  2003. else if (IS_TT_MSG(action->mask))
  2004. {
  2005. if (childrecp)
  2006. {
  2007. /*
  2008. * create argmap for returnable arguments --
  2009. * i.e. those appearing in TT_ARGn_VALUE fields.
  2010. *
  2011. * The requirement is that one and only one action argument may
  2012. * appear in a TT_ARGn_VALUE field.
  2013. *
  2014. * argMap is a sparse array which maps TT_ARGn_VALUEs to input
  2015. * parameters. If a TT_ARGn_VALUE does not have an input parameter
  2016. * as a value then the sentinel value "-1" is provided as the index.
  2017. * Allocate enough space for all the TT_ARGn_VALUEs plus one for
  2018. * TT_FILE.
  2019. *
  2020. * The elements of the argMap array then represent:
  2021. * argMap[ TT_ARG0, TT_ARG1, ...,TT_ARGN, TT_FILE]
  2022. */
  2023. childrecp->argMap =
  2024. (_DtActArgMap *)XtCalloc( action->u.tt_msg.value_count + 1,
  2025. sizeof(_DtActArgMap));
  2026. for ( i = 0; i < action->u.tt_msg.value_count; i++)
  2027. {
  2028. /*
  2029. * Set index value to "-1". This value will indicate
  2030. * TT_ARGn_VALUES which are NOT associated with input
  2031. * parameters (action arguments). If there is an action
  2032. * argument associated with this TT_ARGn_VALUE we will set
  2033. * it below.
  2034. */
  2035. childrecp->argMap[i].argIdx = -1;
  2036. childrecp->argMap[i].argN = i;
  2037. /* null argn value is valid -- so check MsgParts*/
  2038. if (!action->u.tt_msg.tt_argn_value[i].numMsgParts)
  2039. continue;
  2040. if (action->
  2041. u.tt_msg.tt_argn_value[i].parsedMessage[0].keyword
  2042. != ARG)
  2043. continue;
  2044. /*
  2045. * TT_ARGn_VALUE fields should have only one arg keyword.
  2046. */
  2047. myassert(action->u.tt_msg.tt_argn_value[i].numMsgParts == 1);
  2048. argNum =action->
  2049. u.tt_msg.tt_argn_value[i].parsedMessage[0].argNum;
  2050. if ( ( argNum > 0 ) && ( argNum <= invp->ac ) )
  2051. {
  2052. /* The ith message part must be returned */
  2053. childrecp->argMap[i].argIdx =
  2054. argNum + request->objOffset - 1;
  2055. myassert( childrecp->argMap[i].argIdx >= 0 );
  2056. }
  2057. }
  2058. /*
  2059. * Add an argMap entry for the value of the TT_FILE field.
  2060. * Tooltalk (e.g. media messages) sometimes uses this field
  2061. * to pass values such as file names to the message receipient.
  2062. * If the TT_FILE field has a single ARG keyword
  2063. * then record that parameter number otherwise record "-1" as
  2064. * was done for the value arguments above.
  2065. */
  2066. childrecp->argMap[i].argIdx = -1;
  2067. childrecp->argMap[i].argN = -1; /* Use "-1" as TT_FILE entry idx */
  2068. if (action->u.tt_msg.tt_file.numMsgParts
  2069. && action->u.tt_msg.tt_file.parsedMessage[0].keyword == ARG )
  2070. {
  2071. argNum =action->
  2072. u.tt_msg.tt_file.parsedMessage[0].argNum;
  2073. if ( ( argNum > 0 ) && ( argNum <= invp->ac ) )
  2074. {
  2075. /* The ith message part should be the last argMap entry */
  2076. childrecp->argMap[i].argIdx =
  2077. argNum + request->objOffset - 1;
  2078. myassert( childrecp->argMap[i].argIdx >= 0 );
  2079. }
  2080. }
  2081. }
  2082. _DtProcessTtRequest(w, request, relPathHost, relPathDir);
  2083. }
  2084. /*
  2085. * For now we are through invoking this child.
  2086. * There may still be more children to invoke or we may have to
  2087. * re-invoke this child (e.g. multi-host processing for commands).
  2088. */
  2089. SET_INV_DONE(invp->state);
  2090. /* Free up the path information */
  2091. XtFree(relPathHost);
  2092. XtFree(relPathDir);
  2093. }
  2094. /*
  2095. * Determine the CWD to use; this information can be used to both
  2096. * resolve relative filepaths, and to set the CWD used when executing
  2097. * a command invoker request. When resolving relative paths, the
  2098. * information specified for the first argument is not used (see case 2
  2099. * below). It is determined using the following algorithm:
  2100. *
  2101. * 1) Use the CWD specified in the action (if a cmd invoker action).
  2102. * 2) If told to use the objects, then use the directory where the
  2103. * object lives (if a regular file), or the object itself (if
  2104. * it's a directory.
  2105. * 3) Use the CWD passed into _) by the application.
  2106. * 4) Use the physical CWD of the application.
  2107. *
  2108. * Both the host and directory paths must by freed by the caller.
  2109. */
  2110. static void
  2111. __ExtractCWD(
  2112. register ActionRequest *request,
  2113. char ** hostPtr,
  2114. char ** dirPtr,
  2115. Boolean useObjectInfo )
  2116. {
  2117. String msg;
  2118. String lastCh;
  2119. int lastChLen;
  2120. register ActionPtr action = request->clonedAction;
  2121. /* Only dropped objects will have been 'typed' at this point */
  2122. if (useObjectInfo && (IS_CMD(action->mask)) && (request->numObjects > 0) &&
  2123. (request->objects[0].type >= 0) &&
  2124. IS_FILE_OBJ(request->objects[0].mask))
  2125. {
  2126. if (action->u.cmd.contextHost != NULL)
  2127. *hostPtr = XtNewString(action->u.cmd.contextHost);
  2128. else
  2129. {
  2130. *hostPtr = XtNewString(
  2131. request->hostNames[request->objects[0].u.file.hostIndex]);
  2132. }
  2133. if (IS_UNKNOWN_IF_DIR(request->objects[0].mask))
  2134. {
  2135. String nfsPath;
  2136. char *theHost, *theDir;
  2137. struct stat statInfo;
  2138. RESET_UNKNOWN_IF_DIR(request->objects[0].mask);
  2139. /*
  2140. * The file may not have been checked yet, if it was never
  2141. * referenced in the execution string; so .. we'll check
  2142. * here.
  2143. */
  2144. theHost = request->hostNames[request->objects[0].u.file.hostIndex];
  2145. theDir = request->dirNames[request->objects[0].u.file.dirIndex];
  2146. nfsPath = _DtActMapFileName(theHost, theDir,
  2147. request->objects[0].u.file.baseFilename, NULL);
  2148. if (nfsPath && (stat(nfsPath, &statInfo) == 0) &&
  2149. ((statInfo.st_mode & S_IFMT) == S_IFDIR))
  2150. {
  2151. SET_DIR_OBJ(request->objects[0].mask);
  2152. }
  2153. XtFree(nfsPath);
  2154. }
  2155. if (IS_DIR_OBJ(request->objects[0].mask))
  2156. {
  2157. if (action->u.cmd.contextDir != NULL)
  2158. *dirPtr = XtNewString(action->u.cmd.contextDir);
  2159. else
  2160. {
  2161. *dirPtr = XtMalloc((Cardinal)
  2162. (strlen(request->dirNames[request->objects[0].u.file.dirIndex]) +
  2163. strlen(request->objects[0].u.file.baseFilename) + 2));
  2164. strcpy(*dirPtr,
  2165. request->dirNames[request->objects[0].u.file.dirIndex]);
  2166. DtLastChar(*dirPtr, &lastCh, &lastChLen);
  2167. if ((lastChLen != 1) || (*lastCh != '/'))
  2168. (void)strcat(*dirPtr, "/");
  2169. (void)strcat(*dirPtr, request->objects[0].u.file.baseFilename);
  2170. }
  2171. }
  2172. else
  2173. {
  2174. if (action->u.cmd.contextDir != NULL)
  2175. *dirPtr = XtNewString(action->u.cmd.contextDir);
  2176. else
  2177. {
  2178. *dirPtr = XtNewString(
  2179. request->dirNames[request->objects[0].u.file.dirIndex]);
  2180. }
  2181. }
  2182. }
  2183. else
  2184. {
  2185. /* Use specified context, or get process context, if necessary */
  2186. if (IS_CMD(action->mask) && (action->u.cmd.contextHost != NULL))
  2187. *hostPtr = XtNewString(action->u.cmd.contextHost);
  2188. else if (request->cwdHost)
  2189. *hostPtr = XtNewString(request->cwdHost);
  2190. else
  2191. {
  2192. *hostPtr = _DtGetLocalHostName();
  2193. }
  2194. if (IS_CMD(action->mask) && (action->u.cmd.contextDir != NULL))
  2195. *dirPtr = XtNewString(action->u.cmd.contextDir);
  2196. else if (request->cwdDir)
  2197. *dirPtr = XtNewString(request->cwdDir);
  2198. else
  2199. *dirPtr = _DtFindCwd();
  2200. }
  2201. }
  2202. /*
  2203. * This function is used to prepare for the continued processing of
  2204. * the parameters, when the action is a single argument action. It
  2205. * free up any data which was associated with the previous parameter,
  2206. * and cascades up any remaining parameters in the object array.
  2207. */
  2208. static Boolean
  2209. MoreArgumentsToProcess(
  2210. register ActionRequest *request )
  2211. {
  2212. register int i;
  2213. char * path;
  2214. char * dtype;
  2215. if (request->numObjects <= 1)
  2216. {
  2217. return(False);
  2218. }
  2219. else
  2220. {
  2221. /* Repeat processing for the next argument */
  2222. /* Cascade up the remaining, unprocess parameters */
  2223. if (IS_FILE_OBJ(request->objects[0].mask))
  2224. {
  2225. XtFree(request->objects[0].u.file.origFilename);
  2226. XtFree(request->objects[0].u.file.origHostname);
  2227. XtFree(request->objects[0].u.file.baseFilename);
  2228. }
  2229. /*
  2230. * RWV:
  2231. * Since we use tmp files for buffers and do not support
  2232. * strings; we need not add special code for buffer and
  2233. * string support.
  2234. */
  2235. /* fdt: Add support for strings and buffers here
  2236. * else if (IS_BUFFER_OBJ(request->objects[0].mask))
  2237. * XtFree(request->objects[0].u.buffer.buffer);
  2238. * else if (IS_STRING_OBJ(request->objects[0].mask))
  2239. * XtFree(request->objects[0].u.string.string);
  2240. */
  2241. for (i = 0; i < (request->numObjects - 1); i++)
  2242. {
  2243. request->objects[i] = request->objects[i+1];
  2244. }
  2245. request->numObjects--;
  2246. request->objOffset++;
  2247. request->objsUsed = 0;
  2248. request->childId = 0;
  2249. /* Free up our previously cloned action */
  2250. _DtFreeActionStruct(request->clonedAction);
  2251. request->clonedAction = NULL;
  2252. /* Free up any leftover prompt strings */
  2253. for (i = 0; i < request->numPromptInputs; i++)
  2254. XtFree(request->promptInputs[i]);
  2255. XtFree((char *)request->promptInputs);
  2256. request->promptInputs = NULL;
  2257. request->numPromptInputs = 0;
  2258. SET_REPROCESSING(request->mask);
  2259. XtFree(request->badHostList);
  2260. request->badHostList = NULL;
  2261. XtFree(request->currentHost);
  2262. request->currentHost = NULL;
  2263. request->hostIndex = 0;
  2264. /* Type the object, if possible */
  2265. if (IS_FILE_OBJ(request->objects[0].mask))
  2266. {
  2267. if ((request->objects[0].u.file.hostIndex >= 0) &&
  2268. (request->objects[0].u.file.dirIndex >= 0))
  2269. {
  2270. path = _DtActMapFileName(
  2271. request->hostNames[request->objects[0].u.file.hostIndex],
  2272. request->dirNames[request->objects[0].u.file.dirIndex],
  2273. request->objects[0].u.file.baseFilename, NULL);
  2274. dtype = DtDtsFileToDataType(path);
  2275. request->objects[0].type = _DtDtsMMStringToBoson(dtype);
  2276. DtDtsFreeDataType(dtype);
  2277. XtFree(path);
  2278. }
  2279. }
  2280. /*
  2281. * RWV:
  2282. * Since we use tmp files for buffers and do not support
  2283. * strings; we need not add special code for buffer and
  2284. * string support.
  2285. */
  2286. /* fdt: add support for buffers and strings here
  2287. * else if (IS_BUFFER_OBJ(request->objects[0].mask))
  2288. * {
  2289. * }
  2290. * else if (IS_STRING_OBJ(request->objects[0].mask))
  2291. * {
  2292. * }
  2293. */
  2294. return(True);
  2295. }
  2296. }
  2297. /***************************************************************************/
  2298. /***************************************************************************/
  2299. /* Functions For Cloning And Free Structures */
  2300. /***************************************************************************/
  2301. /***************************************************************************/
  2302. /*
  2303. * At the point that a request is sent, we need to save a copy of the
  2304. * request, for future reference. We need to clone the request, since
  2305. * the original request structure may get modified between the time we
  2306. * send the message, and the time we need to reference it in the future.
  2307. */
  2308. ActionRequest *
  2309. _DtCloneRequest (
  2310. ActionRequest * request)
  2311. {
  2312. ActionRequest * newRequest;
  2313. int i;
  2314. newRequest = (ActionRequest *)XtMalloc((Cardinal)sizeof(ActionRequest));
  2315. /*
  2316. * Structure assignment to clone all scalar values
  2317. * If a value is not explicitly set then it defaults to the same value
  2318. * as in the original request. Pointers to malloc-ed memory should all
  2319. * be replaced with pointers to a copy of the region.
  2320. */
  2321. (*newRequest) = (*request);
  2322. newRequest->actionName = XtNewString(request->actionName);
  2323. if (request->numObjects > 0) {
  2324. newRequest->objects = (ObjectData *)XtMalloc(sizeof(ObjectData) *
  2325. request->numObjects);
  2326. for (i = 0; i < request->numObjects; i++)
  2327. {
  2328. newRequest->objects[i] = request->objects[i];
  2329. if (IS_FILE_OBJ(request->objects[i].mask))
  2330. {
  2331. newRequest->objects[i].u.file.origFilename =
  2332. XtNewString(request->objects[i].u.file.origFilename);
  2333. newRequest->objects[i].u.file.origHostname =
  2334. XtNewString(request->objects[i].u.file.origHostname);
  2335. newRequest->objects[i].u.file.baseFilename =
  2336. XtNewString(request->objects[i].u.file.baseFilename);
  2337. }
  2338. else if ( IS_BUFFER_OBJ(request->objects[i].mask) )
  2339. {
  2340. /*
  2341. * RWV:
  2342. * Since we are creating tmp files for all buffers
  2343. * we should never have to copy a buffer's contents.
  2344. *
  2345. * We should never reach this code because the FILE_OBJ
  2346. * bit is set when we create tmp files for buffers.
  2347. */
  2348. myassert(0);
  2349. /*
  2350. * RWV:
  2351. * Can we get by without copying buffer object contents?
  2352. * if so -- how do we avoid freeing it twice OR
  2353. * not freeing it at all?
  2354. */
  2355. /* make a copy of the buffer */
  2356. if ( request->objects[i].u.buffer.bp )
  2357. {
  2358. myassert(newRequest->objects[i].u.buffer.size == request->objects[i].u.buffer.size);
  2359. newRequest->objects[i].u.buffer.bp =
  2360. XtMalloc( request->objects[i].u.buffer.size );
  2361. memcpy(newRequest->objects[i].u.buffer.bp,
  2362. request->objects[i].u.buffer.bp,
  2363. newRequest->objects[i].u.buffer.size);
  2364. }
  2365. }
  2366. else
  2367. myassert(0 /* no other object types supported */ );
  2368. }
  2369. }
  2370. newRequest->numPromptInputs = request->numPromptInputs;
  2371. if (request->numPromptInputs > 0) {
  2372. newRequest->promptInputs = (char **)XtMalloc(sizeof(char *) *
  2373. request->numPromptInputs);
  2374. for (i = 0; i < request->numPromptInputs; i++)
  2375. newRequest->promptInputs[i] = XtNewString(request->promptInputs[i]);
  2376. }
  2377. newRequest->numHostNames = request->numHostNames;
  2378. if (request->numHostNames > 0) {
  2379. newRequest->hostNames = (char **)XtMalloc(sizeof(char *) *
  2380. request->numHostNames);
  2381. for (i = 0; i < request->numHostNames; i++)
  2382. newRequest->hostNames[i] = XtNewString(request->hostNames[i]);
  2383. }
  2384. newRequest->numDirNames = request->numDirNames;
  2385. if (request->numDirNames > 0) {
  2386. newRequest->dirNames = (char **)XtMalloc(sizeof(char *) *
  2387. request->numDirNames);
  2388. for (i = 0; i < request->numDirNames; i++)
  2389. newRequest->dirNames[i] = XtNewString(request->dirNames[i]);
  2390. }
  2391. newRequest->termOpts = XtNewString(request->termOpts);
  2392. newRequest->cwdHost = XtNewString(request->cwdHost);
  2393. newRequest->cwdDir = XtNewString(request->cwdDir);
  2394. if (request->clonedAction)
  2395. newRequest->clonedAction = CloneActionDBEntry(request->clonedAction);
  2396. else
  2397. newRequest->clonedAction = NULL;
  2398. newRequest->badHostList = XtNewString(request->badHostList);
  2399. newRequest->currentHost = XtNewString(request->currentHost);
  2400. newRequest->execHost = XtNewString(request->execHost);
  2401. return(newRequest);
  2402. }
  2403. /*
  2404. * Free up the contents of a request structure
  2405. */
  2406. void
  2407. _DtFreeRequest(
  2408. register ActionRequest *request )
  2409. {
  2410. register int i;
  2411. XtFree(request->actionName);
  2412. for (i = 0; i < request->numObjects; i++)
  2413. {
  2414. if (IS_FILE_OBJ(request->objects[i].mask))
  2415. {
  2416. XtFree(request->objects[i].u.file.origFilename);
  2417. XtFree(request->objects[i].u.file.origHostname);
  2418. XtFree(request->objects[i].u.file.baseFilename);
  2419. }
  2420. /*
  2421. * RWV:
  2422. * Since we use tmp files for buffers and do not support
  2423. * strings; we need not add special code for buffer and
  2424. * string support.
  2425. */
  2426. /* fdt: Add support for buffers and strings here
  2427. * else if (IS_BUFFER_OBJ(request->objects[i].mask)
  2428. * XtFree(request->objects[i].u.buffer.buffer);
  2429. * else if (IS_STRING_OBJ(request->objects[i].mask)
  2430. * XtFree(request->objects[i].u.string.string);
  2431. */
  2432. }
  2433. /*
  2434. * Since the objectDataArray was malloced at once
  2435. * we can free it at once.
  2436. */
  2437. if (request->objects) XtFree((char *)request->objects);
  2438. for (i = 0; i < request->numPromptInputs; i++)
  2439. XtFree(request->promptInputs[i]);
  2440. if (request->promptInputs) XtFree((char *)request->promptInputs);
  2441. for (i = 0; i < request->numHostNames; i++)
  2442. XtFree(request->hostNames[i]);
  2443. if (request->hostNames) XtFree((char *)request->hostNames);
  2444. for (i = 0; i < request->numDirNames; i++)
  2445. XtFree(request->dirNames[i]);
  2446. if (request->dirNames) XtFree((char *)request->dirNames);
  2447. XtFree(request->termOpts);
  2448. XtFree(request->cwdHost);
  2449. XtFree(request->cwdDir);
  2450. _DtFreeActionStruct(request->clonedAction);
  2451. XtFree(request->badHostList);
  2452. XtFree(request->currentHost);
  2453. XtFree(request->execHost);
  2454. XtFree ((char *)request);
  2455. }
  2456. /*
  2457. * Create a clone of an action DB entry
  2458. */
  2459. static ActionPtr
  2460. CloneActionDBEntry(
  2461. register ActionPtr action )
  2462. {
  2463. register ActionPtr newAction = (ActionPtr)XtMalloc((Cardinal)sizeof(Action));
  2464. register int i;
  2465. /* Clone each field */
  2466. newAction->action = action->action;
  2467. newAction->file_name_id = action->file_name_id;
  2468. newAction->label = XtNewString(action->label);
  2469. newAction->description = XtNewString(action->description);
  2470. newAction->type_count = action->type_count;
  2471. if (action->type_count > 0) {
  2472. newAction->arg_types = (DtShmBoson *)XtMalloc(sizeof(DtShmBoson) *
  2473. newAction->type_count);
  2474. for (i = 0; i < newAction->type_count; i++)
  2475. newAction->arg_types[i] = action->arg_types[i];
  2476. }
  2477. else {
  2478. newAction->arg_types = NULL;
  2479. }
  2480. newAction->arg_count = action->arg_count;
  2481. newAction->mask = action->mask;
  2482. if (IS_CMD(action->mask))
  2483. {
  2484. cmdAttr * newCmd = &(newAction->u.cmd);
  2485. cmdAttr * oldCmd = &(action->u.cmd);
  2486. CloneParsedMessage(&(oldCmd->execString), &(newCmd->execString));
  2487. CloneParsedMessage(&(oldCmd->termOpts), &(newCmd->termOpts));
  2488. newCmd->contextDir = XtNewString(oldCmd->contextDir);
  2489. newCmd->contextHost = XtNewString(oldCmd->contextHost);
  2490. CloneParsedMessage(&(oldCmd->execHosts), &(newCmd->execHosts));
  2491. newCmd->execHostCount = oldCmd->execHostCount;
  2492. if (oldCmd->execHostCount > 0) {
  2493. newCmd->execHostArray = (char **)XtMalloc(sizeof(char *) *
  2494. newCmd->execHostCount);
  2495. for (i = 0; i < newCmd->execHostCount; i++)
  2496. newCmd->execHostArray[i] = XtNewString(oldCmd->execHostArray[i]);
  2497. }
  2498. else {
  2499. newCmd->execHostArray = NULL;
  2500. }
  2501. }
  2502. else if (IS_MAP(action->mask))
  2503. {
  2504. newAction->u.map.map_action = action->u.map.map_action;
  2505. }
  2506. else if (IS_TT_MSG(action->mask))
  2507. {
  2508. tt_msgAttr * newMsg = &(newAction->u.tt_msg);
  2509. tt_msgAttr * oldMsg = &(action->u.tt_msg);
  2510. newMsg->tt_class = oldMsg->tt_class;
  2511. newMsg->tt_scope = oldMsg->tt_scope;
  2512. CloneParsedMessage(&(oldMsg->tt_op), &(newMsg->tt_op));
  2513. CloneParsedMessage(&(oldMsg->tt_file), &(newMsg->tt_file));
  2514. newMsg->mode_count = oldMsg->mode_count;
  2515. if (oldMsg->mode_count > 0) {
  2516. newMsg->tt_argn_mode =
  2517. (int *)XtMalloc(sizeof(int) * newMsg->mode_count);
  2518. for (i = 0; i < newMsg->mode_count; i++)
  2519. newMsg->tt_argn_mode[i] = oldMsg->tt_argn_mode[i];
  2520. }
  2521. else {
  2522. newMsg->tt_argn_mode = NULL;
  2523. }
  2524. newMsg->vtype_count = oldMsg->vtype_count;
  2525. newMsg->tt_argn_vtype = CloneParsedMessageArray(oldMsg->tt_argn_vtype,
  2526. oldMsg->vtype_count);
  2527. newMsg->value_count = oldMsg->value_count;
  2528. newMsg->tt_argn_value = CloneParsedMessageArray(oldMsg->tt_argn_value,
  2529. oldMsg->value_count);
  2530. newMsg->rep_type_count = oldMsg->rep_type_count;
  2531. if (oldMsg->rep_type_count > 0) {
  2532. newMsg->tt_argn_rep_type = (int *)XtMalloc(sizeof(int) *
  2533. newMsg->rep_type_count);
  2534. for (i = 0; i < newMsg->rep_type_count; i++)
  2535. newMsg->tt_argn_rep_type[i] = oldMsg->tt_argn_rep_type[i];
  2536. }
  2537. else {
  2538. newMsg->tt_argn_rep_type = NULL;
  2539. }
  2540. }
  2541. return(newAction);
  2542. }
  2543. /*
  2544. * Free up the contents of a request structure
  2545. */
  2546. void
  2547. _DtFreeActionStruct(
  2548. register ActionPtr action )
  2549. {
  2550. register int i;
  2551. if (action == NULL)
  2552. return;
  2553. XtFree(action->label);
  2554. XtFree(action->description);
  2555. if (action->arg_types) XtFree((char *)action->arg_types);
  2556. if (IS_CMD(action->mask))
  2557. {
  2558. FreeParsedMessage(&(action->u.cmd.execString));
  2559. FreeParsedMessage(&(action->u.cmd.termOpts));
  2560. XtFree(action->u.cmd.contextDir);
  2561. XtFree(action->u.cmd.contextHost);
  2562. FreeParsedMessage(&(action->u.cmd.execHosts));
  2563. for (i = 0; i < action->u.cmd.execHostCount; i++)
  2564. XtFree(action->u.cmd.execHostArray[i]);
  2565. if (action->u.cmd.execHostArray) {
  2566. XtFree((char *)action->u.cmd.execHostArray);
  2567. }
  2568. }
  2569. else if (IS_TT_MSG(action->mask))
  2570. {
  2571. FreeParsedMessage(&(action->u.tt_msg.tt_op));
  2572. FreeParsedMessage(&(action->u.tt_msg.tt_file));
  2573. if (action->u.tt_msg.tt_argn_mode) {
  2574. XtFree((char *)action->u.tt_msg.tt_argn_mode);
  2575. }
  2576. FreeParsedMessageArray(action->u.tt_msg.tt_argn_vtype,
  2577. action->u.tt_msg.vtype_count);
  2578. FreeParsedMessageArray(action->u.tt_msg.tt_argn_value,
  2579. action->u.tt_msg.value_count);
  2580. if (action->u.tt_msg.tt_argn_rep_type) {
  2581. XtFree((char *)action->u.tt_msg.tt_argn_rep_type);
  2582. }
  2583. }
  2584. XtFree((char *)action);
  2585. }
  2586. static void
  2587. CloneParsedMessage(
  2588. register parsedMsg * old_pmsg,
  2589. register parsedMsg * new_pmsg )
  2590. {
  2591. int i;
  2592. register MsgComponent * piece;
  2593. register MsgComponent * newPiece;
  2594. new_pmsg->numMsgParts = old_pmsg->numMsgParts;
  2595. if (old_pmsg->compiledMessage)
  2596. {
  2597. /*
  2598. * Some day these may not always be null-terminated strings
  2599. */
  2600. new_pmsg->compiledMessage = (char *)XtMalloc(old_pmsg->msgLen);
  2601. memcpy(new_pmsg->compiledMessage,
  2602. old_pmsg->compiledMessage,
  2603. old_pmsg->msgLen);
  2604. new_pmsg->msgLen = old_pmsg->msgLen;
  2605. }
  2606. else
  2607. {
  2608. new_pmsg->compiledMessage = NULL;
  2609. new_pmsg->msgLen = 0;
  2610. }
  2611. /* Clone the message components */
  2612. if (old_pmsg->numMsgParts > 0)
  2613. {
  2614. new_pmsg->parsedMessage = (MsgComponent *)
  2615. XtMalloc((Cardinal)(sizeof(MsgComponent) * old_pmsg->numMsgParts));
  2616. for (i = 0; i < old_pmsg->numMsgParts; i++)
  2617. {
  2618. piece = &(old_pmsg->parsedMessage[i]);
  2619. newPiece = &(new_pmsg->parsedMessage[i]);
  2620. /* Clone each subcomponent of this message */
  2621. if (piece->precedingText)
  2622. newPiece->precedingText = XtNewString(piece->precedingText);
  2623. else
  2624. newPiece->precedingText = NULL;
  2625. if (piece->prompt)
  2626. newPiece->prompt = XtNewString(piece->prompt);
  2627. else
  2628. newPiece->prompt = NULL;
  2629. newPiece->keyword = piece->keyword;
  2630. newPiece->argNum = piece->argNum;
  2631. newPiece->mask = piece->mask;
  2632. }
  2633. }
  2634. else
  2635. new_pmsg->parsedMessage = NULL;
  2636. }
  2637. /*
  2638. * Free up the contents of a parsedMsg structure, but not the structure
  2639. * itself (since many of our structures contain in-line instances of
  2640. * the parsedMsg structure).
  2641. */
  2642. static void
  2643. FreeParsedMessage(
  2644. register parsedMsg * parsedMessage )
  2645. {
  2646. int i;
  2647. /* Free up the message components */
  2648. if (parsedMessage->numMsgParts > 0)
  2649. {
  2650. for (i = 0; i < parsedMessage->numMsgParts; i++)
  2651. {
  2652. XtFree(parsedMessage->parsedMessage[i].precedingText);
  2653. XtFree(parsedMessage->parsedMessage[i].prompt);
  2654. }
  2655. XtFree((char *)parsedMessage->parsedMessage);
  2656. }
  2657. XtFree(parsedMessage->compiledMessage);
  2658. }
  2659. /*
  2660. * Allocate an array to hold a copy of all of the parsedMsg structures.
  2661. * This array must be freed eventually by the caller.
  2662. */
  2663. static parsedMsg *
  2664. CloneParsedMessageArray(
  2665. register parsedMsg * pmsgArray,
  2666. register int count )
  2667. {
  2668. parsedMsg * newArray;
  2669. int i;
  2670. if (count == 0)
  2671. return(NULL);
  2672. newArray = (parsedMsg *)XtMalloc(sizeof(parsedMsg) * count);
  2673. for (i = 0; i < count; i++)
  2674. CloneParsedMessage(pmsgArray + i, newArray + i);
  2675. return(newArray);
  2676. }
  2677. /*
  2678. * Free up the counted array of parsedMsg structures.
  2679. * The array pointing to them also needs to be freed.
  2680. */
  2681. static void
  2682. FreeParsedMessageArray(
  2683. register parsedMsg * parsedMessageArray,
  2684. int count )
  2685. {
  2686. int i;
  2687. for (i = 0; i < count; i++)
  2688. FreeParsedMessage(parsedMessageArray + i);
  2689. XtFree((char *)parsedMessageArray);
  2690. }
  2691. /***************************************************************************/
  2692. /***************************************************************************/
  2693. /* Functions For Placing Arguments Into A Message String */
  2694. /***************************************************************************/
  2695. /***************************************************************************/
  2696. /*
  2697. * This function takes a 'parsedMsg' structure, and compiles all of its
  2698. * pieces into a single string, replacing keywords as they are encountered.
  2699. * Since a given action request can be made up of multiple pieces, this
  2700. * function uses some static variables to maintain state information between
  2701. * calls for the same action request; passing in 'True' for the 'initialize'
  2702. * parameter for the first call for a given action request will clear out
  2703. * any old static values.
  2704. */
  2705. Boolean
  2706. _DtCompileMessagePiece(
  2707. Widget w,
  2708. ActionRequest *request,
  2709. char * relPathHost,
  2710. char * relPathDir,
  2711. parsedMsg * piece,
  2712. Boolean initialize,
  2713. unsigned long processingMask,
  2714. Boolean ** paramUsed,
  2715. int * promptDataIndex )
  2716. {
  2717. register int i, j;
  2718. Boolean firstParmUsed;
  2719. register MsgComponent * segment;
  2720. char * compiledMsg = NULL;
  2721. int compiledMsgSize = 0;
  2722. ObjectData tmpObjData;
  2723. static char *sessionHostName= NULL;
  2724. static char *displayHostName = NULL;
  2725. static char *localHostName = NULL;
  2726. XtFree(piece->compiledMessage);
  2727. piece->compiledMessage = NULL;
  2728. piece->msgLen = 0;
  2729. if (initialize)
  2730. {
  2731. /*
  2732. * Keep track of which parameters have been used, so that when
  2733. * a %Args% keyword is encountered, we know which parameters
  2734. * should be substituted.
  2735. */
  2736. *promptDataIndex = 0;
  2737. if (request->numObjects > 0) {
  2738. *paramUsed = (Boolean *)XtMalloc((Cardinal)(sizeof(Boolean) *
  2739. request->numObjects));
  2740. for (i = 0; i < request->numObjects; i++)
  2741. (*paramUsed)[i] = False;
  2742. }
  2743. }
  2744. _DtSvcProcessLock();
  2745. /* We need to query our hostname the first time only */
  2746. if ( ! localHostName )
  2747. localHostName = _DtGetLocalHostName();
  2748. /*
  2749. * Determine the display host name -- default to localHostName for
  2750. * degenerate display names (i.e. :0, unix:0, local:0, ...)
  2751. */
  2752. if ( ! displayHostName )
  2753. displayHostName = _DtGetDisplayHostName(XtDisplay(w));
  2754. if ( ! sessionHostName )
  2755. sessionHostName = _DtGetSessionHostName();
  2756. _DtSvcProcessUnlock();
  2757. /*
  2758. * The message is constructed by taking each of the
  2759. * action segments, replacing any keywords, and then adding the
  2760. * information to the end of the buffer.
  2761. */
  2762. for (i = 0; i < piece->numMsgParts; i++)
  2763. {
  2764. segment = piece->parsedMessage + i;
  2765. /* Add any text preceding the keyword */
  2766. if (segment->precedingText)
  2767. {
  2768. compiledMsg = GrowMsgBuffer(compiledMsg, &compiledMsgSize,
  2769. (int)strlen(segment->precedingText));
  2770. (void)strcat(compiledMsg, segment->precedingText);
  2771. }
  2772. /* Process the keyword */
  2773. switch (segment->keyword)
  2774. {
  2775. case LOCAL_HOST:
  2776. {
  2777. /* Add in the local host name */
  2778. compiledMsg = GrowMsgBuffer(compiledMsg, &compiledMsgSize,
  2779. (int)strlen(localHostName));
  2780. (void)strcat(compiledMsg, localHostName);
  2781. break;
  2782. }
  2783. case DATABASE_HOST:
  2784. {
  2785. /*
  2786. * Add in the host associated with the DB file from which this
  2787. * action was loaded.
  2788. */
  2789. char * fullPath;
  2790. char * host;
  2791. fullPath = _DtDbPathIdToString(request->clonedAction->file_name_id);
  2792. host = _DtHostString(fullPath);
  2793. if (host)
  2794. {
  2795. compiledMsg = GrowMsgBuffer(compiledMsg, &compiledMsgSize,
  2796. host ? (int)strlen(host) : 0);
  2797. (void)strcat(compiledMsg, host);
  2798. XtFree(host);
  2799. }
  2800. XtFree(fullPath);
  2801. break;
  2802. }
  2803. case DISPLAY_HOST:
  2804. {
  2805. /*
  2806. * Use the displayHostName determined the first time thru
  2807. */
  2808. compiledMsg = GrowMsgBuffer(compiledMsg, &compiledMsgSize,
  2809. (int)strlen(displayHostName));
  2810. (void)strcat(compiledMsg, displayHostName);
  2811. break;
  2812. }
  2813. case SESSION_HOST:
  2814. {
  2815. /*
  2816. * Add in the session server host where providing the
  2817. * display management. (i.e. the host where the login client
  2818. * is running.)
  2819. */
  2820. compiledMsg = GrowMsgBuffer(compiledMsg, &compiledMsgSize,
  2821. (int)strlen(sessionHostName));
  2822. (void)strcat(compiledMsg, sessionHostName);
  2823. break;
  2824. }
  2825. case NO_KEYWORD:
  2826. {
  2827. /*
  2828. * If this is an entry which simply collected some user input,
  2829. * then add the user's input to the message buffer.
  2830. * This corresponds to the keywords:
  2831. *
  2832. * %"prompt"%
  2833. * %(String)"prompt"%
  2834. */
  2835. if (segment->prompt)
  2836. {
  2837. /* Create dummy object; makes processing easier */
  2838. if (ParseFileArgument(w, request, &tmpObjData,
  2839. NULL, request->promptInputs[*promptDataIndex],
  2840. NULL, False))
  2841. {
  2842. XtFree(compiledMsg);
  2843. return(False);
  2844. }
  2845. if (!InsertArgumentString(w, &compiledMsg, &compiledMsgSize,
  2846. request, &tmpObjData, segment->mask, relPathHost,
  2847. relPathDir, False, 0))
  2848. {
  2849. XtFree(compiledMsg);
  2850. return(False);
  2851. }
  2852. /* Signal that this prompt has been used */
  2853. (*promptDataIndex)++;
  2854. }
  2855. break;
  2856. }
  2857. case ARG:
  2858. {
  2859. if (segment->argNum == ALL_ARGS)
  2860. {
  2861. /* Insert all currently unused parameters */
  2862. for (j = 0, firstParmUsed = False; j < request->numObjects; j++)
  2863. {
  2864. /* Used or empty objects are skipped */
  2865. if ((*paramUsed)[j] == False)
  2866. {
  2867. if (IS_FILE_OBJ(request->objects[j].mask) &&
  2868. request->objects[j].u.file.origFilename)
  2869. {
  2870. if (!InsertArgumentString(w, &compiledMsg,
  2871. &compiledMsgSize,
  2872. request, request->objects+j,
  2873. segment->mask, relPathHost, relPathDir,
  2874. firstParmUsed, processingMask))
  2875. {
  2876. XtFree(compiledMsg);
  2877. return(False);
  2878. }
  2879. firstParmUsed = True;
  2880. }
  2881. /*
  2882. * RWV:
  2883. * Since we use tmp files for buffers and do not support
  2884. * strings; we need not add special code for buffer and
  2885. * string support.
  2886. */
  2887. /* fdt: add support for buffers and strings
  2888. * else if (IS_BUFFER_OBJ(request->objects[i].mask) &&
  2889. * request->objects[i].u.buffer.buffer)
  2890. * else if (IS_STRING_OBJ(request->objects[i].mask) &&
  2891. * request->objects[i].u.string.string)
  2892. */
  2893. }
  2894. }
  2895. }
  2896. else if (segment->argNum <= request->numObjects)
  2897. {
  2898. if (IS_FILE_OBJ(request->objects[segment->argNum-1].mask) &&
  2899. request->objects[segment->argNum-1].u.file.origFilename)
  2900. {
  2901. /* Replace only with the specified argument */
  2902. (*paramUsed)[segment->argNum-1] = True;
  2903. /*
  2904. * All buffer objects have been written to tmp files.
  2905. * This code replaces a reference to an object with its
  2906. * (tmp) file name.
  2907. * Tooltalk processing code elsewhere
  2908. * (ActionTt.c) detects the conditions under which a buffer
  2909. * object reference should be replaced by the buffer contents
  2910. * instead of the tmp file name. (i.e. a value field with a
  2911. * single argument reference with no additional text). In such
  2912. * cases the compiled message string will be ignored.
  2913. */
  2914. if (!InsertArgumentString(w, &compiledMsg, &compiledMsgSize,
  2915. request, request->objects + segment->argNum - 1,
  2916. segment->mask, relPathHost, relPathDir, False,
  2917. processingMask))
  2918. {
  2919. XtFree(compiledMsg);
  2920. return(False);
  2921. }
  2922. }
  2923. /*
  2924. * RWV:
  2925. * Since we use tmp files for buffers and do not support
  2926. * strings; we need not add special code for buffer and
  2927. * string support.
  2928. */
  2929. /* fdt: add support for buffers and strings
  2930. * else if (IS_BUFFER_OBJ(request->objects[i].mask) &&
  2931. * request->objects[i].u.buffer.buffer)
  2932. * else if (IS_STRING_OBJ(request->objects[i].mask) &&
  2933. * request->objects[i].u.string.string)
  2934. */
  2935. }
  2936. break;
  2937. }
  2938. }
  2939. }
  2940. if ((piece->compiledMessage = compiledMsg) == NULL)
  2941. piece->msgLen = 0;
  2942. else
  2943. piece->msgLen = compiledMsg ? strlen(compiledMsg) + 1: 0;
  2944. return(True);
  2945. }
  2946. /*
  2947. * Given an object, add it to the end of the message buffer. The
  2948. * object may refer to a file, thus possibly requiring that it be
  2949. * converted to another format.
  2950. */
  2951. static Boolean
  2952. InsertArgumentString(
  2953. Widget w,
  2954. register char **bufPtr,
  2955. int * bufSizePtr,
  2956. ActionRequest *request,
  2957. register ObjectData *object,
  2958. unsigned long mask,
  2959. char * relPathHost,
  2960. char * relPathDir,
  2961. Boolean addLeadingSpace,
  2962. unsigned long processingMask )
  2963. {
  2964. int len;
  2965. String lastCh;
  2966. int lastChLen;
  2967. char * path;
  2968. char * value;
  2969. char * dataType;
  2970. char * mediaAttr;
  2971. if (processingMask & _DTAct_TT_VTYPE)
  2972. SET_TREAT_AS_FILE(mask);
  2973. if (IS_TREAT_AS_FILE(mask))
  2974. {
  2975. if (object->type == -1)
  2976. {
  2977. /* Object still needs to be typed */
  2978. if (IS_FILE_OBJ(object->mask))
  2979. {
  2980. char * origInfo = object->u.file.origFilename;
  2981. ParseFileArgument(w, request, object, NULL, origInfo, NULL, True);
  2982. XtFree(origInfo);
  2983. }
  2984. /*
  2985. * RWV:
  2986. * Since we use tmp files for buffers and do not support
  2987. * strings; we need not add special code for buffer and
  2988. * string support.
  2989. */
  2990. /* fdt: add support for buffers and strings
  2991. * else if (IS_BUFFER_OBJ(object->mask))
  2992. * else if (IS_STRING_OBJ(object->mask))
  2993. */
  2994. }
  2995. if (IS_FILE_OBJ(object->mask))
  2996. {
  2997. if (processingMask & _DTAct_TT_VTYPE)
  2998. {
  2999. /*
  3000. * Instead of inserting the object referred to by "Arg_n",
  3001. * we need to instead insert the MEDIA attribute for the
  3002. * object. If the MEDIA attribute is not defined for the
  3003. * datatype associated with this object, then use the
  3004. * datatype name itself. If the thing can't be defined, then
  3005. * do nothing.
  3006. */
  3007. if (object->type != (-1))
  3008. {
  3009. dataType = (char *)_DtDtsMMBosonToString(object->type);
  3010. if ((path = _DtActMapFileName(
  3011. request->hostNames[object->u.file.hostIndex],
  3012. request->dirNames[object->u.file.dirIndex],
  3013. object->u.file.baseFilename,
  3014. NULL)) == NULL)
  3015. {
  3016. path = NULL;
  3017. }
  3018. mediaAttr = DtDtsDataTypeToAttributeValue(dataType, "MEDIA",
  3019. path);
  3020. XtFree(path);
  3021. if (mediaAttr)
  3022. {
  3023. value = XtNewString(mediaAttr);
  3024. DtDtsFreeAttributeValue(mediaAttr);
  3025. }
  3026. else
  3027. value = XtNewString(dataType);
  3028. *bufPtr = GrowMsgBuffer(*bufPtr, bufSizePtr, strlen(value) + 1);
  3029. if (addLeadingSpace)
  3030. strcat(*bufPtr, " ");
  3031. strcat(*bufPtr, value);
  3032. XtFree(value);
  3033. }
  3034. return(True);
  3035. }
  3036. if (IS_CMD(request->clonedAction->mask))
  3037. {
  3038. /* Map into a real path, relative to the execution host */
  3039. if ((path = _DtActMapFileName(
  3040. request->hostNames[object->u.file.hostIndex],
  3041. request->dirNames[object->u.file.dirIndex],
  3042. object->u.file.baseFilename,
  3043. request->currentHost)) == NULL)
  3044. {
  3045. AddFailedHostToList(request, request->currentHost);
  3046. return(False);
  3047. }
  3048. *bufPtr = GrowMsgBuffer(*bufPtr, bufSizePtr, strlen(path) + 1);
  3049. if (addLeadingSpace)
  3050. (void)strcat(*bufPtr, " ");
  3051. strcat(*bufPtr, path);
  3052. XtFree(path);
  3053. }
  3054. else if (IS_TT_MSG(request->clonedAction->mask))
  3055. {
  3056. /*
  3057. * ToolTalk automatically translates the 'filename' field within
  3058. * a message, and expects the incoming name to be relative to
  3059. * the local host. So ... we simply need to map the name to
  3060. * be relative to the local host. However, if this is not the
  3061. * filename, but is instead one of the 'args', then we must
  3062. * insert it in a 'neutral' form.
  3063. */
  3064. if (processingMask & _DTAct_TT_ARG)
  3065. {
  3066. /* Map into "host:/path" */
  3067. /* fdt: May need to instead map into 'network indep' form */
  3068. InsertUnmappedArgumentString(bufPtr, bufSizePtr, object,
  3069. addLeadingSpace);
  3070. }
  3071. else
  3072. {
  3073. if ((path = _DtActMapFileName(
  3074. request->hostNames[object->u.file.hostIndex],
  3075. request->dirNames[object->u.file.dirIndex],
  3076. object->u.file.baseFilename, NULL)) == NULL)
  3077. {
  3078. return(False);
  3079. }
  3080. *bufPtr = GrowMsgBuffer(*bufPtr, bufSizePtr, strlen(path) + 1);
  3081. if (addLeadingSpace)
  3082. (void)strcat(*bufPtr, " ");
  3083. strcat(*bufPtr, path);
  3084. XtFree(path);
  3085. }
  3086. }
  3087. }
  3088. /*
  3089. * RWV:
  3090. * Since we use tmp files for buffers and do not support
  3091. * strings; we need not add special code for buffer and
  3092. * string support.
  3093. */
  3094. /* fdt: add support for buffers and strings
  3095. * else if (IS_BUFFER_OBJ(object->mask))
  3096. * else if (IS_STRING_OBJ(object->mask))
  3097. */
  3098. }
  3099. else
  3100. InsertUnmappedArgumentString(bufPtr, bufSizePtr, object, addLeadingSpace);
  3101. return(True);
  3102. }
  3103. /*
  3104. * This function knows how to insert a string in "host:/path" format;
  3105. * this is essentually an 'unmapped' filename. File arguments which
  3106. * have been preceded by the "(String)" qualifier will be saved in
  3107. * this fashion. Likewise, any filenames (either in "String" or "File"
  3108. * form) for an message will be saved in this format, due to the
  3109. * fact that we don't know the execution host, and thus cannot properly
  3110. * map the filename using the ToolTalk filename mapping functions.
  3111. */
  3112. static void
  3113. InsertUnmappedArgumentString(
  3114. register char **bufPtr,
  3115. int * bufSizePtr,
  3116. register ObjectData *object,
  3117. Boolean addLeadingSpace )
  3118. {
  3119. char * host = NULL;
  3120. int size;
  3121. /* No mapping is necessary here. */
  3122. if (IS_FILE_OBJ(object->mask))
  3123. {
  3124. size = strlen(object->u.file.origFilename) + 4;
  3125. *bufPtr = GrowMsgBuffer(*bufPtr, bufSizePtr, size);
  3126. if (addLeadingSpace)
  3127. (void)strcat(*bufPtr, " ");
  3128. strcat(*bufPtr, object->u.file.origFilename);
  3129. }
  3130. /*
  3131. * RWV:
  3132. * Since we use tmp files for buffers and do not support
  3133. * strings; we need not add special code for buffer and
  3134. * string support.
  3135. */
  3136. /* fdt: add support for buffers and strings
  3137. * else if (IS_BUFFER_OBJ(object->mask))
  3138. * else if (IS_STRING_OBJ(object->mask))
  3139. */
  3140. }
  3141. /*
  3142. * This function checks to see if the message buffer is large enough
  3143. * to hold the current contents + 'count' more bytes. If it is not
  3144. * large enough, then the buffer will be grown. The buffer MUST BE
  3145. * NULL terminated.
  3146. */
  3147. static String
  3148. GrowMsgBuffer(
  3149. String buffer,
  3150. int *size,
  3151. int count )
  3152. {
  3153. int currentBufUsed = buffer ? strlen(buffer) : 0;
  3154. if ((currentBufUsed + count + 1) >= *size)
  3155. {
  3156. (*size) += (count+1 > 1024) ? count + 1 : 1024;
  3157. buffer = (char *)XtRealloc(buffer, (Cardinal)*size);
  3158. /* If this is the first alloc for the buffer, then terminate the buffer */
  3159. if(currentBufUsed == 0)
  3160. buffer[0] = '\0';
  3161. }
  3162. return(buffer);
  3163. }
  3164. /***************************************************************************/
  3165. /***************************************************************************/
  3166. /* Functions For Matching Arguments To A Message String */
  3167. /***************************************************************************/
  3168. /***************************************************************************/
  3169. /*
  3170. * If the specified prompt has not already been added to the array of
  3171. * prompt strings, then add it. The exception is for stand-alone
  3172. * prompt strings, which always are added.
  3173. */
  3174. static void
  3175. AddPrompt(
  3176. register int argNum,
  3177. String prompt,
  3178. register int *numPrompts,
  3179. register PromptEntry **prompts )
  3180. {
  3181. register int i;
  3182. /*
  3183. * Standard arguments only want their prompts entered once.
  3184. * Stand-alone prompts all have argNum == NO_ARG, and each one
  3185. * must be saved. It's a special case.
  3186. */
  3187. if (argNum != NO_ARG)
  3188. {
  3189. for (i = 0; i < *numPrompts; i++)
  3190. {
  3191. if ((*prompts)[i].argIndex == argNum)
  3192. return;
  3193. }
  3194. }
  3195. (*numPrompts)++;
  3196. *prompts = (PromptEntry *)XtRealloc((char *)*prompts,
  3197. (Cardinal)(sizeof(PromptEntry) * *numPrompts));
  3198. (*prompts)[(*numPrompts) - 1].argIndex = argNum;
  3199. (*prompts)[(*numPrompts) - 1].prompt = prompt;
  3200. }
  3201. /*
  3202. * This function takes an action DB entry and an action request, and
  3203. * determines if enough information was supplied to create the message
  3204. * needed to get the work done. If information was missing, then this
  3205. * function will return an array of prompt strings, which can be used
  3206. * to create a dialog for collecting the missing information. This
  3207. * function also returns an indication of how many of the parameters
  3208. * were left unused.
  3209. *
  3210. * The caller is responsible for freeing up the prompt array, but the
  3211. * entries in the array MUST NOT be freed up.
  3212. */
  3213. static int
  3214. MatchParamsToAction(
  3215. ActionRequest *request,
  3216. int *numPrompts,
  3217. PromptEntry **prompts )
  3218. {
  3219. Boolean * paramUsed = NULL;
  3220. int unused;
  3221. Boolean argsOptionFound;
  3222. register int i;
  3223. int lastArgReferenced;
  3224. ActionPtr action = request->clonedAction;
  3225. /* Initialize things */
  3226. *numPrompts = 0;
  3227. *prompts = NULL;
  3228. argsOptionFound = False;
  3229. lastArgReferenced = -1;
  3230. /*
  3231. * This array lets us know which parameters can be used when we
  3232. * encounter the %Args% keyword.
  3233. */
  3234. unused = request->numObjects;
  3235. if (unused > 0) {
  3236. paramUsed = (Boolean *)XtMalloc((Cardinal)(sizeof(Boolean) * unused));
  3237. for (i = 0; i < unused; i++)
  3238. paramUsed[i] = False;
  3239. }
  3240. if (IS_CMD(action->mask))
  3241. {
  3242. /*
  3243. * NOTE: The current implementation of prompt strings requires that
  3244. * the segments be evaluated in the same order in which the
  3245. * message fields were parsed.
  3246. * (See ResolveCommandInvokerMessagePieces() )
  3247. * This order is currently "execHost", "execString" and
  3248. * "termOpts". This situation arises because
  3249. * the existing prompt data structures do NOT identify the
  3250. * location of the prompt and hence where to put the
  3251. * user-supplied value; except by order of occurrence.
  3252. */
  3253. ProcessOneSegment(request, &(action->u.cmd.execHosts), prompts,
  3254. numPrompts, &argsOptionFound, &lastArgReferenced,
  3255. &unused, paramUsed);
  3256. ProcessOneSegment(request, &(action->u.cmd.execString), prompts,
  3257. numPrompts, &argsOptionFound, &lastArgReferenced,
  3258. &unused, paramUsed);
  3259. ProcessOneSegment(request, &(action->u.cmd.termOpts), prompts,
  3260. numPrompts, &argsOptionFound, &lastArgReferenced,
  3261. &unused, paramUsed);
  3262. }
  3263. else if (IS_TT_MSG(action->mask))
  3264. {
  3265. ProcessOneSegment(request, &(action->u.tt_msg.tt_op), prompts,
  3266. numPrompts, &argsOptionFound, &lastArgReferenced,
  3267. &unused, paramUsed);
  3268. ProcessOneSegment(request, &(action->u.tt_msg.tt_file), prompts,
  3269. numPrompts, &argsOptionFound, &lastArgReferenced,
  3270. &unused, paramUsed);
  3271. for (i = 0; i < action->u.tt_msg.vtype_count; i++)
  3272. {
  3273. ProcessOneSegment(request, &(action->u.tt_msg.tt_argn_vtype[i]),
  3274. prompts, numPrompts, &argsOptionFound,
  3275. &lastArgReferenced, &unused, paramUsed);
  3276. }
  3277. for (i = 0; i < action->u.tt_msg.value_count; i++)
  3278. {
  3279. /*
  3280. * We require that at most ONE argument be consumed by a
  3281. * tt_argn_value field.
  3282. */
  3283. ProcessOneSegment(request, &(action->u.tt_msg.tt_argn_value[i]),
  3284. prompts, numPrompts, &argsOptionFound,
  3285. &lastArgReferenced, &unused, paramUsed);
  3286. }
  3287. }
  3288. /*
  3289. * Now that we have processed all of the pieces which will ultimately
  3290. * used to construct our message, determine if any of the arguments
  3291. * passed to _DtActionInvoke were not used; this allows us to tell
  3292. * the user that there were unused arguments, so they can choose
  3293. * to continue or abort the request.
  3294. * If we ever encountered a %Args% keyword, then ultimately all of
  3295. * the parameters will be used.
  3296. */
  3297. if (argsOptionFound)
  3298. unused = 0;
  3299. else
  3300. {
  3301. /*
  3302. * Determine how many arguments were actually unused; only count
  3303. * those arguments AFTER the last referenced one. i.e. if arg2
  3304. * is referenced, but arg1 and arg3 are not, then only count arg3
  3305. * as an unused (and thus extra) parameter.
  3306. */
  3307. for (i = 0; ((i < lastArgReferenced - 1) && (i < request->numObjects));
  3308. i++)
  3309. {
  3310. if (!paramUsed[i])
  3311. unused--;
  3312. }
  3313. /* This should never happen, but ... */
  3314. if (unused < 0)
  3315. unused = 0;
  3316. }
  3317. if (paramUsed) XtFree(paramUsed);
  3318. return(unused);
  3319. }
  3320. static void
  3321. ProcessOneSegment(
  3322. ActionRequest * request,
  3323. parsedMsg * msg,
  3324. PromptEntry **prompts,
  3325. int *numPrompts,
  3326. Boolean * argsOptionFound,
  3327. int * lastArgReferenced,
  3328. int * unused,
  3329. Boolean * paramUsed )
  3330. {
  3331. MsgComponent * piece;
  3332. int i;
  3333. /*
  3334. * Check each piece of this message component, to see if the parameter
  3335. * it expects has been supplied. If the parameter is missing, and
  3336. * a prompt was supplied, then add the prompt to the prompt array.
  3337. */
  3338. for (i = 0; i < msg->numMsgParts; i++)
  3339. {
  3340. piece = msg->parsedMessage + i;
  3341. /*
  3342. * We only care about %Args% and %Arg_<n>% keywords, and
  3343. * entries which have no keyword, but do have a prompt.
  3344. */
  3345. if (piece->keyword == ARG)
  3346. {
  3347. if (piece->argNum == ALL_ARGS)
  3348. {
  3349. /*
  3350. * When a %Args% keyword is found, this implies that there
  3351. * will ultimately be no unused parameters, because this
  3352. * keyword is replaced by all unused parameters.
  3353. */
  3354. *argsOptionFound = True;
  3355. }
  3356. else if (piece->argNum > 0)
  3357. {
  3358. /* Keep track of the largest arg index referenced */
  3359. if (piece->argNum > *lastArgReferenced)
  3360. *lastArgReferenced = piece->argNum;
  3361. /* See if a parameter was supplied for this argNum */
  3362. if (piece->argNum > request->numObjects)
  3363. {
  3364. /* Parameter is missing; see if a prompt was given */
  3365. if (piece->prompt)
  3366. AddPrompt(piece->argNum, piece->prompt, numPrompts, prompts);
  3367. }
  3368. else
  3369. {
  3370. /* Mark this parameter as having been used */
  3371. if (!paramUsed[piece->argNum - 1])
  3372. {
  3373. paramUsed[piece->argNum - 1] = True;
  3374. (*unused)--;
  3375. }
  3376. }
  3377. }
  3378. }
  3379. else if ((piece->keyword == NO_KEYWORD) && (piece->prompt))
  3380. {
  3381. /* Entries may be nothing but a prompt */
  3382. AddPrompt(NO_ARG, piece->prompt, numPrompts, prompts);
  3383. }
  3384. }
  3385. }
  3386. /***************************************************************************/
  3387. /***************************************************************************/
  3388. /* Prompt Dialog Support */
  3389. /***************************************************************************/
  3390. /***************************************************************************/
  3391. /*
  3392. * This is the event handler which catches the 'escape' key when typed
  3393. * into the prompt. It will unpost the dialog.
  3394. */
  3395. static void
  3396. CancelOut(
  3397. Widget w,
  3398. XEvent *event,
  3399. XtPointer params,
  3400. XtPointer num_params)
  3401. {
  3402. Arg args[10];
  3403. Widget cancel;
  3404. /* Get the cancel button widget id */
  3405. XtSetArg(args[0], XmNuserData, &cancel);
  3406. XtGetValues(w, args, 1);
  3407. /* Unpost the text annotation dialog */
  3408. XtCallCallbacks(cancel, XmNactivateCallback, NULL);
  3409. }
  3410. /*
  3411. * 'Cancel' callback for the dialog used to collect missing parameters
  3412. * from the user. It will free up the memory holding the cancelled
  3413. * request and will destroy the dialog.
  3414. */
  3415. static void
  3416. CancelPromptDialog(
  3417. Widget widget,
  3418. PromptDialog *dialog,
  3419. XtPointer call_data )
  3420. {
  3421. unsigned long evalStatus;
  3422. unsigned long userStatus;
  3423. _DtActInvRecT *invp;
  3424. /* Destroy the dialog */
  3425. XtDestroyWidget(XtParent(dialog->topLevel));
  3426. /* Free up the prompt sub-structure */
  3427. XtFree((char *)dialog->prompts);
  3428. invp = _DtActFindInvRec(dialog->request->invocId);
  3429. myassert(invp); /* There should always be an invocation record */
  3430. /* Free up the original request structure */
  3431. _DtFreeRequest(dialog->request);
  3432. /* Free up the callback structure */
  3433. XtFree((char *)dialog);
  3434. if ( !invp )
  3435. return; /* This should never happen */
  3436. SET_INV_CANCEL(invp->state);
  3437. /*
  3438. * Evaluate whether we are done with this invocation -- are there
  3439. * uncompleted children? There should not be any subsequent invocations
  3440. * to worry about since this cancel effectively aborts further processing.
  3441. *
  3442. * We may have to return values to the caller.
  3443. */
  3444. _DtActExecutionLeafNodeCleanup(invp->id,NULL,0,True);
  3445. }
  3446. /*
  3447. * This function changes the focus from the given "widget's"
  3448. * tab group to the next tab group.
  3449. */
  3450. static void
  3451. ChangePromptTraversal(
  3452. Widget widget,
  3453. register PromptDialog *dialog,
  3454. XtPointer call_data )
  3455. {
  3456. XmProcessTraversal (widget, XmTRAVERSE_NEXT_TAB_GROUP);
  3457. }
  3458. /*
  3459. * 'Ok' callback for the dialog used to collect missing parameters
  3460. * from the user. It will redo the array of parameter strings, and
  3461. * then execute the command, given whatever the user has supplied.
  3462. * It will also destroy the dialog box.
  3463. */
  3464. static void
  3465. ProcessPromptDialog(
  3466. Widget widget,
  3467. register PromptDialog *dialog,
  3468. XtPointer call_data )
  3469. {
  3470. register int i, j;
  3471. String value;
  3472. /* Unpost the dialog */
  3473. XtUnmanageChild(dialog->topLevel);
  3474. /*
  3475. * Given the set of strings supplied by the user, update the
  3476. * object array which is part of the original request.
  3477. */
  3478. for (i = 0; i < dialog->numPrompts; i++)
  3479. {
  3480. value = XmTextFieldGetString(dialog->prompts[i].promptWidget);
  3481. /* Do we need to grow the object array? */
  3482. if (dialog->prompts[i].argIndex > 0)
  3483. {
  3484. if (_DtEmptyString(value))
  3485. {
  3486. XtFree(value);
  3487. continue;
  3488. }
  3489. if (dialog->prompts[i].argIndex > dialog->request->numObjects)
  3490. {
  3491. dialog->request->objects = (ObjectData *)
  3492. XtRealloc((char *)dialog->request->objects,
  3493. (Cardinal)(sizeof(ObjectData) * (dialog->prompts[i].argIndex)));
  3494. /* Initialize the new array entries */
  3495. for (j = dialog->request->numObjects;
  3496. j < dialog->prompts[i].argIndex;
  3497. j++)
  3498. {
  3499. dialog->request->objects[j].mask = 0;
  3500. SET_FILE_OBJ(dialog->request->objects[j].mask);
  3501. dialog->request->objects[j].type = -1;
  3502. dialog->request->objects[j].u.file.hostIndex = -1;
  3503. dialog->request->objects[j].u.file.dirIndex = -1;
  3504. dialog->request->objects[j].u.file.origFilename = NULL;
  3505. dialog->request->objects[j].u.file.origHostname = NULL;
  3506. dialog->request->objects[j].u.file.baseFilename = NULL;
  3507. dialog->request->objects[j].u.file.bp = 0;
  3508. dialog->request->objects[j].u.file.sizebp = 0;
  3509. dialog->request->objects[j].u.buffer.bp = 0;
  3510. dialog->request->objects[j].u.buffer.size = 0;
  3511. dialog->request->objects[j].u.string.string = 0;
  3512. SET_UNKNOWN_IF_DIR(dialog->request->objects[j].mask);
  3513. }
  3514. dialog->request->numObjects = dialog->prompts[i].argIndex;
  3515. }
  3516. /*
  3517. * These values cannot be broken up into host/dir/file components,
  3518. * nor can they be typed, until we know it they refer to a file.
  3519. * This can't be determined until we construct the action message.
  3520. */
  3521. dialog->request->objects[dialog->prompts[i].argIndex-1].u.file.
  3522. origFilename = value;
  3523. }
  3524. else /* Prompt-only input */
  3525. {
  3526. /*
  3527. * Prompt-only input can't fit in our ordered object array,
  3528. * since they don't have a unique argIndex which can be used
  3529. * as the index into the object array.
  3530. */
  3531. dialog->request->numPromptInputs++;
  3532. dialog->request->promptInputs = (String *)
  3533. XtRealloc((char *)dialog->request->promptInputs,
  3534. (Cardinal)(dialog->request->numPromptInputs * sizeof(String)));
  3535. dialog->request->promptInputs[dialog->request->numPromptInputs-1] =
  3536. value;
  3537. }
  3538. }
  3539. /* Destroy the dialog */
  3540. XtDestroyWidget(XtParent(dialog->topLevel));
  3541. XmUpdateDisplay(widget);
  3542. /*
  3543. * Invoke the action using the information we've collected.
  3544. * If this was a single argument action, then the reprocessing
  3545. * of it may have generated another dialog, so we can only free
  3546. * up the request, when all processing is done.
  3547. */
  3548. if (ProcessRequest(dialog->associatedWidget, dialog->request))
  3549. {
  3550. _DtActInvRecT *invp;
  3551. unsigned long evalStatus;
  3552. unsigned long userStatus;
  3553. if ( (invp = _DtActFindInvRec(dialog->request->invocId)) )
  3554. {
  3555. /* all done invoking ? */
  3556. RESET_INV_PENDING(invp->state);
  3557. /* We should only get here if all requests have been honored */
  3558. SET_INV_COMPLETE(invp->state);
  3559. /*
  3560. * evaluate whether all child actions have been completed
  3561. * and if its time to call the user callback.
  3562. */
  3563. _DtActExecutionLeafNodeCleanup(invp->id,NULL,0,True);
  3564. }
  3565. myassert(invp); /* there should always be one to find */
  3566. _DtFreeRequest(dialog->request);
  3567. }
  3568. /* Free up the prompt sub-structure */
  3569. XtFree((char *)dialog->prompts);
  3570. /* Free up the callback structure */
  3571. XtFree((char *)dialog);
  3572. }
  3573. /*
  3574. * This function takes the array of prompt strings, and creates a
  3575. * dialog box, using these prompt strings as the labels for a set
  3576. * of text widgets.
  3577. */
  3578. static void
  3579. CreatePromptDialog(
  3580. Widget w,
  3581. ActionRequest *request,
  3582. register int numPrompts,
  3583. register PromptEntry *prompts )
  3584. {
  3585. register PromptDialog * dialog;
  3586. register DialogPromptEntry * promptDes;
  3587. XmString pt1;
  3588. String title;
  3589. Widget shell, bboard, frame, form, label;
  3590. Widget promptLabel, topAttach;
  3591. Widget separator, ok, cancel;
  3592. register int count;
  3593. int n, i;
  3594. Arg args[20];
  3595. XmString labelString;
  3596. XWindowAttributes xwa;
  3597. Status status;
  3598. Boolean is_mapped = False;
  3599. static XtTranslations trans_table;
  3600. static Boolean first = True;
  3601. Atom xa_WM_DELETE_WINDOW;
  3602. /*
  3603. * Want to set up the Escape key so that it will unpost the dialog.
  3604. */
  3605. _DtSvcProcessLock();
  3606. if (first)
  3607. {
  3608. XtAppAddActions(XtWidgetToApplicationContext(w), actionTable, 1);
  3609. trans_table = XtParseTranslationTable(translations_escape);
  3610. first = False;
  3611. }
  3612. _DtSvcProcessUnlock();
  3613. /* Allocate the structures we'll be needing */
  3614. dialog = (PromptDialog *)XtMalloc((Cardinal)sizeof(PromptDialog));
  3615. promptDes = (DialogPromptEntry *)XtMalloc((Cardinal)
  3616. (sizeof(DialogPromptEntry) * numPrompts));
  3617. /* Create the shell, frame and form used for the dialog. */
  3618. title = (char *)XtMalloc((Cardinal)
  3619. (strlen(PromptDialogTitle)+ strlen(request->clonedAction->label) + 1));
  3620. (void)sprintf(title, "%1$s%2$s", PromptDialogTitle, request->clonedAction->label);
  3621. n = 0;
  3622. XtSetArg (args[n], XmNallowShellResize, True); n++;
  3623. XtSetArg (args[n], XmNtitle, title); n++;
  3624. shell = XmCreateDialogShell (w, "promptDialog", args, n);
  3625. XtFree(title);
  3626. if (XtIsRealized(w))
  3627. {
  3628. status = XGetWindowAttributes (XtDisplay (w), XtWindow (w), &xwa);
  3629. if (status && (xwa.map_state == IsViewable))
  3630. is_mapped = True;
  3631. }
  3632. n = 0;
  3633. XtSetArg (args[n], XmNmarginWidth, 0); n++;
  3634. XtSetArg (args[n], XmNmarginHeight, 0); n++;
  3635. if (!is_mapped)
  3636. {
  3637. XtSetArg (args[n], XmNdefaultPosition, False);
  3638. n++;
  3639. }
  3640. bboard = XmCreateBulletinBoard (shell, "bboard", args, n);
  3641. n = 0;
  3642. XtSetArg (args[n], XmNshadowThickness, 1); n++;
  3643. XtSetArg (args[n], XmNshadowType, XmSHADOW_OUT); n++;
  3644. frame = XmCreateFrame (bboard, "frame", args, n);
  3645. XtManageChild (frame);
  3646. n = 0;
  3647. XtSetArg (args[n], XmNautoUnmanage, False); n++;
  3648. XtSetArg (args[n], XmNtextTranslations, trans_table); n++;
  3649. form = XmCreateForm (frame, "form", args, n);
  3650. XtManageChild (form);
  3651. /* Create the dialog description label */
  3652. pt1 = XmStringCreateLocalized(PromptDialogLabel);
  3653. n = 0;
  3654. XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  3655. XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  3656. XtSetArg(args[n], XmNleftOffset, 20); n++;
  3657. XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  3658. XtSetArg(args[n], XmNrightOffset, 20); n++;
  3659. XtSetArg(args[n], XmNtopOffset, 15); n++;
  3660. XtSetArg(args[n], XmNlabelString, pt1); n++;
  3661. label = XmCreateLabelGadget(form, "label", args, n);
  3662. XtManageChild (label);
  3663. XmStringFree(pt1);
  3664. /* Create each of the needed prompts */
  3665. topAttach = label;
  3666. for (count = 0; count < numPrompts; count++)
  3667. {
  3668. promptDes[count].argIndex = prompts[count].argIndex;
  3669. pt1 = XmStringCreateLocalized(prompts[count].prompt);
  3670. n = 0;
  3671. XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  3672. XtSetArg(args[n], XmNtopWidget, topAttach); n++;
  3673. XtSetArg(args[n], XmNtopOffset, 10); n++;
  3674. XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  3675. XtSetArg(args[n], XmNleftOffset, 30); n++;
  3676. XtSetArg(args[n], XmNlabelString, pt1); n++;
  3677. promptLabel = XmCreateLabelGadget(form, "promptLabel", args, n);
  3678. XtManageChild(promptLabel);
  3679. XmStringFree(pt1);
  3680. n = 0;
  3681. XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  3682. XtSetArg(args[n], XmNtopWidget, topAttach); n++;
  3683. XtSetArg(args[n], XmNtopOffset, 8); n++;
  3684. XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  3685. XtSetArg(args[n], XmNrightOffset, 30); n++;
  3686. XtSetArg(args[n], XmNtraversalOn, True); n++;
  3687. XtSetArg(args[n], XmNleftAttachment,XmATTACH_WIDGET ); n++;
  3688. XtSetArg(args[n], XmNleftWidget, promptLabel); n++;
  3689. XtSetArg(args[n], XmNleftOffset, 15); n++;
  3690. promptDes[count].promptWidget = XmCreateTextField(form, "text", args, n);
  3691. XtManageChild(promptDes[count].promptWidget);
  3692. XmAddTabGroup(promptDes[count].promptWidget);
  3693. topAttach = promptDes[count].promptWidget;
  3694. }
  3695. /* Create a separator between the buttons */
  3696. n = 0;
  3697. XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  3698. XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  3699. XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  3700. XtSetArg (args[n], XmNtopWidget, topAttach); n++;
  3701. XtSetArg (args[n], XmNtopOffset, 20); n++;
  3702. separator = XmCreateSeparatorGadget (form, "separator", args, n);
  3703. XtManageChild (separator);
  3704. /* Create the ok and cancel buttons */
  3705. n = 0;
  3706. labelString = XmStringCreateLocalized((String)_DtOkString);
  3707. XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  3708. XtSetArg (args[n], XmNleftPosition, 5 + 10); n++;
  3709. XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
  3710. XtSetArg (args[n], XmNrightPosition, 31 + 10); n++;
  3711. XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  3712. XtSetArg (args[n], XmNtopWidget, separator); n++;
  3713. XtSetArg (args[n], XmNtopOffset, 16); n++;
  3714. XtSetArg (args[n], XmNbottomOffset, 16); n++;
  3715. XtSetArg (args[n], XmNmarginHeight, 4); n++;
  3716. XtSetArg (args[n], XmNshowAsDefault, True); n++;
  3717. XtSetArg (args[n], XmNlabelString, labelString); n++;
  3718. ok = XmCreatePushButtonGadget (form, "ok", args, n);
  3719. XtManageChild(ok);
  3720. XtAddCallback(ok, XmNactivateCallback, (XtCallbackProc)ProcessPromptDialog,
  3721. (XtPointer)dialog);
  3722. XmStringFree(labelString);
  3723. /* Set the default action */
  3724. if (numPrompts <= 1)
  3725. {
  3726. n = 0;
  3727. XtSetArg (args[n], XmNdefaultButton, ok); n++;
  3728. XtSetValues(bboard, args, n);
  3729. }
  3730. else
  3731. {
  3732. int i;
  3733. /*
  3734. * Want to set the traversal so that if "return" is hit in the
  3735. * last prompt, the "ProcessPromptDialog" callback is invoked.
  3736. * Otherwise, the "return" should move the focus to the next
  3737. * which is in a different (tab group).
  3738. */
  3739. for (i = 0; i < numPrompts; i++)
  3740. {
  3741. if (i <= (numPrompts - 2))
  3742. XtAddCallback(promptDes[i].promptWidget, XmNactivateCallback,
  3743. (XtCallbackProc)ChangePromptTraversal,
  3744. (XtPointer)dialog);
  3745. else
  3746. XtAddCallback(promptDes[i].promptWidget, XmNactivateCallback,
  3747. (XtCallbackProc)ProcessPromptDialog,
  3748. (XtPointer)dialog);
  3749. }
  3750. }
  3751. n = 0;
  3752. labelString = XmStringCreateLocalized((String)_DtCancelString);
  3753. XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  3754. XtSetArg (args[n], XmNleftPosition, 37 + 22); n++;
  3755. XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
  3756. XtSetArg (args[n], XmNrightPosition, 63 + 22); n++;
  3757. XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  3758. XtSetArg (args[n], XmNtopWidget, separator); n++;
  3759. XtSetArg (args[n], XmNtopOffset, 21); n++;
  3760. XtSetArg (args[n], XmNbottomOffset, 21); n++;
  3761. XtSetArg (args[n], XmNmarginHeight, 4); n++;
  3762. XtSetArg (args[n], XmNlabelString, labelString); n++;
  3763. cancel = XmCreatePushButtonGadget (form, "cancel", args, n);
  3764. XtManageChild(cancel);
  3765. XtAddCallback(cancel, XmNactivateCallback, (XtCallbackProc)CancelPromptDialog,
  3766. (XtPointer)dialog);
  3767. XmStringFree(labelString);
  3768. /*
  3769. * For each prompt, must set up the Escape key to be equivalent
  3770. * to the "Cancel button.
  3771. */
  3772. for (i = 0; i < numPrompts; i++) {
  3773. n = 0;
  3774. XtSetArg(args[n], XmNuserData, cancel); n++;
  3775. XtSetValues(promptDes[i].promptWidget, args, n);
  3776. }
  3777. /*
  3778. * If the widget is not mapped, center this dialog.
  3779. */
  3780. if (!is_mapped)
  3781. {
  3782. Dimension dialogWd, dialogHt;
  3783. XtSetArg(args[0], XmNmappedWhenManaged, False);
  3784. XtSetValues(shell, args, 1);
  3785. XtManageChild(bboard);
  3786. XtRealizeWidget(shell);
  3787. XtSetArg(args[0], XmNwidth, &dialogWd);
  3788. XtSetArg(args[1], XmNheight, &dialogHt);
  3789. XtGetValues(bboard, args, 2);
  3790. XtSetArg (args[0], XmNx,
  3791. (WidthOfScreen(XtScreen(bboard)) - dialogWd) / 2U);
  3792. XtSetArg (args[1], XmNy,
  3793. (HeightOfScreen(XtScreen(bboard)) - dialogHt) / 2U);
  3794. XtSetValues (bboard, args, 2);
  3795. }
  3796. /* Adjust the decorations for the dialog shell of the dialog */
  3797. n = 0;
  3798. XtSetArg (args[n], XmNmwmDecorations,
  3799. MWM_DECOR_BORDER | MWM_DECOR_MENU | MWM_DECOR_TITLE); n++;
  3800. XtSetValues(shell, args, n);
  3801. xa_WM_DELETE_WINDOW =
  3802. XInternAtom(XtDisplay(shell), "WM_DELETE_WINDOW", False);
  3803. XmAddWMProtocolCallback(
  3804. shell, xa_WM_DELETE_WINDOW,
  3805. (XtCallbackProc) CancelPromptDialog, (XtPointer) dialog);
  3806. /* Fill in our instance structure */
  3807. dialog->request = request;
  3808. dialog->topLevel = bboard;
  3809. dialog->numPrompts = count;
  3810. dialog->prompts = promptDes;
  3811. dialog->associatedWidget = w;
  3812. /* Post the dialog */
  3813. XtSetArg(args[0], XmNmappedWhenManaged, True);
  3814. XtSetValues(shell, args, 1);
  3815. XtManageChild(bboard);
  3816. /* Make the first prompt automatically get the focus. */
  3817. if (numPrompts >= 0)
  3818. XmProcessTraversal(promptDes[0].promptWidget, XmTRAVERSE_CURRENT);
  3819. }
  3820. /***************************************************************************/
  3821. /***************************************************************************/
  3822. /* Continue Dialog Support */
  3823. /***************************************************************************/
  3824. /***************************************************************************/
  3825. /*
  3826. * 'Ok' callback for the abort/continue dialog. It will continue with the
  3827. * processing of the request, ignoring any unused parameters.
  3828. */
  3829. static void
  3830. ContinueRequest(
  3831. Widget widget,
  3832. XtPointer user_data,
  3833. XtPointer call_data )
  3834. {
  3835. register int i;
  3836. register ContinueDialog *dialog = (ContinueDialog *)user_data;
  3837. /* Destroy the dialog */
  3838. XtDestroyWidget(XtParent(dialog->topLevel));
  3839. XmUpdateDisplay(widget);
  3840. /*
  3841. * If we need to collect some prompt input from the user, then
  3842. * post the prompt dialog; otherwise, send the action request.
  3843. */
  3844. if (dialog->numPrompts == 0)
  3845. {
  3846. if (ProcessRequest(dialog->associatedWidget, dialog->request))
  3847. {
  3848. _DtActInvRecT *invp;
  3849. if((invp=_DtActFindInvRec(dialog->request->invocId))!=NULL)
  3850. {
  3851. /* all done invoking ? */
  3852. RESET_INV_PENDING(invp->state);
  3853. /* We should only get here if all requests have been honored */
  3854. SET_INV_COMPLETE(invp->state);
  3855. /*
  3856. * evaluate whether all child actions have been completed
  3857. * and if its time to call the user callback.
  3858. */
  3859. _DtActExecutionLeafNodeCleanup(invp->id,NULL,0,True);
  3860. }
  3861. myassert(invp); /* there should always be one to find */
  3862. _DtFreeRequest(dialog->request);
  3863. }
  3864. }
  3865. else
  3866. {
  3867. CreatePromptDialog(dialog->associatedWidget, dialog->request,
  3868. dialog->numPrompts,
  3869. dialog->prompts);
  3870. }
  3871. /* Free up the prompt sub-structure */
  3872. for (i = 0; i < dialog->numPrompts; i++)
  3873. XtFree(dialog->prompts[i].prompt);
  3874. XtFree((char *)dialog->prompts);
  3875. /* Free up the callback structure */
  3876. XtFree((char *)dialog);
  3877. }
  3878. /*
  3879. * 'Cancel' callback for the dialog which prompts the user to continue
  3880. * or abort, when too many parameters have been supplied. This will
  3881. * free up the dialog data and the request and will destroy the dialog.
  3882. */
  3883. static void
  3884. CancelRequest(
  3885. Widget widget,
  3886. XtPointer user_data,
  3887. XtPointer call_data )
  3888. {
  3889. register int i;
  3890. register ContinueDialog *dialog = (ContinueDialog *)user_data;
  3891. unsigned long evalStatus;
  3892. unsigned long userStatus;
  3893. _DtActInvRecT *invp;
  3894. /* Destroy the dialog */
  3895. XtDestroyWidget(XtParent(dialog->topLevel));
  3896. /* Free up the prompt sub-structure */
  3897. for (i = 0; i < dialog->numPrompts; i++)
  3898. XtFree(dialog->prompts[i].prompt);
  3899. XtFree((char *)dialog->prompts);
  3900. /* get the invocation record */
  3901. invp = _DtActFindInvRec(dialog->request->invocId);
  3902. myassert(invp); /* There should always be one available */
  3903. /* Free up the original request structure */
  3904. _DtFreeRequest(dialog->request);
  3905. /* Free up the callback structure */
  3906. XtFree((char *)dialog);
  3907. if ( !invp )
  3908. return; /* should never happen */
  3909. SET_INV_CANCEL(invp->state);
  3910. /*
  3911. * Evaluate whether we are done with this invocation -- are there
  3912. * uncompleted children? There should not be any subsequent invocations
  3913. * to worry about since this cancel effectively aborts further processing.
  3914. *
  3915. * We may have to return values to the caller.
  3916. */
  3917. _DtActExecutionLeafNodeCleanup(invp->id,NULL,0,True);
  3918. }
  3919. /*
  3920. * When an action is requested, and more parameters than are needed
  3921. * are supplied, the user will be prompted to continue with the
  3922. * operation (ignoring the extra parameters), or to abort the request.
  3923. *
  3924. * This function builds the dialog which will collect the user's response.
  3925. */
  3926. static void
  3927. CreateContinueDialog(
  3928. Widget w,
  3929. ActionRequest *request,
  3930. int numPrompts,
  3931. register PromptEntry *prompts )
  3932. {
  3933. register ContinueDialog * dialog;
  3934. String title;
  3935. XmString label;
  3936. register int i;
  3937. int n;
  3938. Arg args[10];
  3939. XmString ok, cancel;
  3940. char *fmt;
  3941. /* Allocate the structures we'll be needing */
  3942. dialog = (ContinueDialog *)XtMalloc((Cardinal)sizeof(ContinueDialog));
  3943. dialog->request = request;
  3944. dialog->associatedWidget = w;
  3945. dialog->numPrompts = numPrompts;
  3946. /*
  3947. * We need to make a clone of the prompt array, since the strings
  3948. * it contains are not ones we can guarantee will be around when
  3949. * the user finally responds to this dialog.
  3950. */
  3951. if (prompts)
  3952. {
  3953. dialog->prompts = (PromptEntry *)
  3954. XtMalloc((Cardinal)(sizeof(PromptEntry) * numPrompts));
  3955. for (i = 0; i < numPrompts; i++)
  3956. {
  3957. dialog->prompts[i].argIndex = prompts[i].argIndex;
  3958. dialog->prompts[i].prompt = XtNewString(prompts[i].prompt);
  3959. }
  3960. }
  3961. else
  3962. dialog->prompts = NULL;
  3963. ok = XmStringCreateLocalized((String)_DtOkString);
  3964. cancel = XmStringCreateLocalized((String)_DtCancelString);
  3965. /* Create the error dialog */
  3966. fmt = XtNewString((char *)Dt11GETMESSAGE(2, 2, "%1$s%2$s"));
  3967. title = (char *)XtMalloc((Cardinal)
  3968. (strlen(PromptDialogTitle) +
  3969. strlen(request->clonedAction->label) +
  3970. strlen(fmt) + 1));
  3971. (void)sprintf(title, fmt, PromptDialogTitle, request->clonedAction->label);
  3972. label = XmStringCreateLocalized(ContinueMessage);
  3973. XtFree(fmt);
  3974. n = 0;
  3975. XtSetArg(args[n], XmNmessageString, label); n++;
  3976. XtSetArg(args[n], XmNtitle, title); n++;
  3977. XtSetArg(args[n], XmNokLabelString, ok); n++;
  3978. XtSetArg(args[n], XmNcancelLabelString, cancel); n++;
  3979. dialog->topLevel = XmCreateWarningDialog(w, "continueDialog", args, n);
  3980. XtFree(title);
  3981. XmStringFree(ok);
  3982. XmStringFree(cancel);
  3983. XmStringFree(label);
  3984. XtUnmanageChild(XmMessageBoxGetChild(dialog->topLevel,
  3985. XmDIALOG_HELP_BUTTON));
  3986. XtAddCallback(dialog->topLevel, XmNokCallback, ContinueRequest,
  3987. (XtPointer)dialog);
  3988. XtAddCallback(dialog->topLevel, XmNcancelCallback, CancelRequest,
  3989. (XtPointer)dialog);
  3990. XtManageChild(dialog->topLevel);
  3991. }
  3992. /***************************************************************************/
  3993. /***************************************************************************/
  3994. /* Command Invoker Specific Functions */
  3995. /***************************************************************************/
  3996. /***************************************************************************/
  3997. /*
  3998. * This is the entry point into the command-specific world. All of the code
  3999. * before this has been written to handle any of the different transport
  4000. * types. The code from this point on will know specifically how to
  4001. * interact with the command invoker layer. We will start by taking each
  4002. * of the pieces of information making up the command invoker request, and
  4003. * resolving any of the keywords, by replacing them with the appropriate
  4004. * information. If this fails (which it only should do if we try to map
  4005. * a file to a host which cannot be accessed), then we will either continue,
  4006. * using the next exec host, or we will terminate, if no more hosts are left.
  4007. */
  4008. static void
  4009. ProcessCommandInvokerRequest(
  4010. Widget w,
  4011. ActionRequest *request,
  4012. char * relPathHost,
  4013. char * relPathDir )
  4014. {
  4015. char * cwdHost;
  4016. char * cwdDir;
  4017. ActionPtr action = request->clonedAction;
  4018. _DtActInvRecT *invp = NULL;
  4019. _DtActChildRecT *childp = NULL;
  4020. if (ResolveCommandInvokerMessagePieces(w, request, relPathHost, relPathDir))
  4021. {
  4022. /*
  4023. * Issue the request; the success/failure notification comes
  4024. * asynchronously; that's when everything gets cleaned up, or
  4025. * tried again, for the next exec host.
  4026. */
  4027. __ExtractCWD(request, &cwdHost, &cwdDir, True);
  4028. InitiateCommandInvokerRequest( w, request, cwdHost, cwdDir);
  4029. XtFree(cwdHost);
  4030. XtFree(cwdDir);
  4031. }
  4032. else
  4033. {
  4034. if ( !(invp = _DtActFindInvRec(request->invocId) ) )
  4035. myassert( 0 /* could not find invocation record */ );
  4036. if ( !(childp=_DtActFindChildRec(request->invocId,request->childId)))
  4037. myassert( 0 /* could not find child record */ );
  4038. /*
  4039. * The only way we could have reached here is if the execution host
  4040. * was not accessible, and we tried to map one of the data files to
  4041. * be relative to this host. If there are other hosts to be tried,
  4042. * then we will retry the request on the next host; otherwise, we
  4043. * will post an error dialog, and bail out.
  4044. */
  4045. request->hostIndex++;
  4046. if (request->hostIndex >= action->u.cmd.execHostCount)
  4047. {
  4048. /* No more hosts to try; report an error, and bail out */
  4049. if ( invp && childp )
  4050. {
  4051. SET_INV_ERROR(invp->state);
  4052. childp->childState = _DtActCHILD_FAILED;
  4053. }
  4054. /*
  4055. * Cleanup should happen later when we return up the stack.
  4056. */
  4057. if (action->u.cmd.execHostCount <= 1)
  4058. {
  4059. /* Display error dialog listing just the one failed exec host */
  4060. HostAccessError(w, request->clonedAction->label, request->badHostList);
  4061. }
  4062. else
  4063. {
  4064. /* Display error dialog listing all failed exec hosts */
  4065. MultiHostAccessError(w, request->clonedAction->label, request->badHostList);
  4066. }
  4067. }
  4068. else
  4069. {
  4070. if ( invp && childp )
  4071. {
  4072. /*
  4073. * Delete child record for failed exec on this host
  4074. */
  4075. _DtActDeleteChildRec(invp,childp);
  4076. SET_INV_PENDING(invp->state);
  4077. if ( ! invp->numChildren )
  4078. RESET_INV_WORKING(invp->state);
  4079. }
  4080. /* Retry the request, using the next exec host */
  4081. PrepareAndExecuteAction(w, request);
  4082. return;
  4083. }
  4084. }
  4085. }
  4086. /*
  4087. * This function takes all of the pieces making up a command invoker request,
  4088. * and resolves any references to keywords, using both the passed-in
  4089. * arguments, and any information collected from the prompt dialog.
  4090. */
  4091. static Boolean
  4092. ResolveCommandInvokerMessagePieces(
  4093. Widget w,
  4094. ActionRequest *request,
  4095. char * relPathHost,
  4096. char * relPathDir )
  4097. {
  4098. ActionPtr action = request->clonedAction;
  4099. cmdAttr * cmd = &(action->u.cmd);
  4100. char * termOpts;
  4101. Boolean * paramUsed = NULL;
  4102. int promptDataIndex = 0;
  4103. /*
  4104. * NOTE: The current implementation of prompt strings requires that
  4105. * the segments be evaluated in the same order in which the
  4106. * action fields were parsed. (See MatchParamsToAction() )
  4107. * This order is currently "execHost", "execString" and
  4108. * "termOpts". This situation arises because
  4109. * the existing prompt data structures do NOT identify the
  4110. * location of the prompt and hence where to put the
  4111. * user-supplied value; except by order of occurrence.
  4112. */
  4113. /* Set up the next host to execute on */
  4114. _DtCompileMessagePiece(w, request, relPathHost, relPathDir,
  4115. &(action->u.cmd.execHosts), True, 0, &paramUsed,
  4116. &promptDataIndex);
  4117. SetExecHost(request);
  4118. if ((_DtCompileMessagePiece(w, request, relPathHost, relPathDir,
  4119. &(cmd->execString), False, 0, &paramUsed,
  4120. &promptDataIndex) == False) ||
  4121. (_DtCompileMessagePiece(w, request, relPathHost, relPathDir,
  4122. &(cmd->termOpts), False, 0, &paramUsed,
  4123. &promptDataIndex) == False))
  4124. {
  4125. /* Free up any intermediate work we've done here */
  4126. XtFree(cmd->execString.compiledMessage);
  4127. XtFree(cmd->termOpts.compiledMessage);
  4128. XtFree(cmd->execHosts.compiledMessage);
  4129. cmd->execString.compiledMessage = NULL;
  4130. cmd->termOpts.compiledMessage = NULL;
  4131. cmd->execHosts.compiledMessage = NULL;
  4132. XtFree(paramUsed);
  4133. return(False);
  4134. }
  4135. /*
  4136. * If term_opts were passed in to the _DtActionInvoke() function, then
  4137. * append them to the term_opts derived from the action definition and
  4138. * internal defaults. This should give precedence to the last defined
  4139. * options.
  4140. */
  4141. if ( request->termOpts )
  4142. {
  4143. termOpts = XtMalloc( strlen(cmd->termOpts.compiledMessage) +
  4144. strlen(request->termOpts) + 2 );
  4145. strcpy(termOpts,cmd->termOpts.compiledMessage);
  4146. strcat(termOpts," ");
  4147. strcat(termOpts,request->termOpts);
  4148. XtFree(cmd->termOpts.compiledMessage);
  4149. cmd->termOpts.compiledMessage = termOpts;
  4150. }
  4151. XtFree(paramUsed);
  4152. return(True);
  4153. }
  4154. /*
  4155. * Process a command-invoker request.
  4156. */
  4157. static void
  4158. InitiateCommandInvokerRequest(
  4159. Widget w,
  4160. ActionRequest *request,
  4161. String host,
  4162. String dir)
  4163. {
  4164. char procIdBuf[_DtAct_MAX_BUF_SIZE];
  4165. char tmpFileBuf[_DtAct_MAX_BUF_SIZE];
  4166. char *procId; /* for dtexec command line */
  4167. char *tmpFiles = NULL; /* for dtexec command line */
  4168. _DtActInvRecT *invp;
  4169. _DtActChildRecT *childp;
  4170. CallbackData *data=(CallbackData *)XtMalloc((Cardinal)sizeof(CallbackData));
  4171. ActionPtr action = request->clonedAction;
  4172. tmpFileBuf[0]='\0'; /* seed the buffer with a null string */
  4173. /*
  4174. * Generate the procId option string for dtexec
  4175. */
  4176. /* Get the default procId from toolTalk */
  4177. switch ( tt_ptr_error(procId = tt_default_procid()) )
  4178. {
  4179. case TT_ERR_NOMP:
  4180. ; /* fall through */
  4181. case TT_ERR_PROCID: /* Try to establish a connection */
  4182. tt_free(procId) ;
  4183. if ( !_DtInitializeToolTalk(NULL) )
  4184. procId=NULL;
  4185. else if ( tt_ptr_error(procId = tt_default_procid()) != TT_OK )
  4186. {
  4187. myassert( 0 ); /* we should never get here */
  4188. procId = NULL;
  4189. }
  4190. break;
  4191. case TT_OK:
  4192. break;
  4193. default:
  4194. tt_free(procId);
  4195. procId = NULL;
  4196. break;
  4197. }
  4198. /*
  4199. * The string generated for procId should never exceed the procId buf size.
  4200. */
  4201. sprintf(procIdBuf,"%s_%d_%lu",
  4202. _DtActNULL_GUARD(procId),
  4203. (int) request->invocId,
  4204. request->childId );
  4205. myassert( strlen(procIdBuf) < sizeof(procIdBuf) );
  4206. if (procId)
  4207. tt_free(procId);
  4208. procId = procIdBuf; /* no need to malloc */
  4209. /*
  4210. * Generate string of tmp file args for dtexec.
  4211. */
  4212. if ( (invp = _DtActFindInvRec(request->invocId)) != NULL )
  4213. {
  4214. if ( (childp =
  4215. _DtActFindChildRec(request->invocId,request->childId)) != NULL )
  4216. {
  4217. int i;
  4218. char *p;
  4219. int len = 0;
  4220. for(i = 0; i < childp->numObjects; i++)
  4221. {
  4222. if(!(IS_BUFFER_OBJ(invp->info[childp->argMap[i].argIdx].mask)))
  4223. continue; /* not a buffer object */
  4224. if ( !(p = invp->info[childp->argMap[i].argIdx].name) )
  4225. continue; /* no tmp file name */
  4226. /* Add up the string length of the file name */
  4227. if((len += strlen(" -tmp ") + strlen(p)) < sizeof(tmpFileBuf))
  4228. {
  4229. /*
  4230. * Use the automatic tmpFileBuf if possible
  4231. */
  4232. strcat(tmpFileBuf," -tmp ");
  4233. strcat(tmpFileBuf,p);
  4234. }
  4235. else
  4236. {
  4237. /*
  4238. * Malloc more space if necessary
  4239. */
  4240. XtFree(tmpFiles);
  4241. tmpFiles = XtMalloc(len + 1);
  4242. strcpy(tmpFiles,tmpFileBuf);
  4243. strcpy(tmpFiles," -tmp ");
  4244. strcpy(tmpFiles,p);
  4245. }
  4246. }
  4247. if ( len > 0 && len < sizeof(tmpFileBuf) )
  4248. tmpFiles = tmpFileBuf;
  4249. }
  4250. else
  4251. {
  4252. myassert( 0 /* could not find child rec */ );
  4253. tmpFiles = NULL;
  4254. }
  4255. }
  4256. else
  4257. tmpFiles = NULL;
  4258. /* Fill out the callback structure */
  4259. data->actionLabel = XtNewString(request->clonedAction->label);
  4260. data->associatedWidget = w;
  4261. data->offset = 0;
  4262. data->actionPtr = action;
  4263. data->requestPtr = _DtCloneRequest(request);
  4264. if ( _DtActionCommandInvoke(action->mask & _DtAct_WINTYPE_BITS, host, dir,
  4265. action->u.cmd.execString.compiledMessage,
  4266. action->u.cmd.termOpts.compiledMessage,
  4267. request->currentHost,
  4268. procId,
  4269. tmpFiles,
  4270. CmdInvSuccessfulRequest, (XtPointer)data,
  4271. CmdInvFailedRequest, (XtPointer)data) )
  4272. if (invp)
  4273. SET_INV_CMD_QUEUED(invp->state);
  4274. if ( tmpFiles != tmpFileBuf )
  4275. XtFree(tmpFiles);
  4276. }
  4277. /*
  4278. * Sets the 'currentHost' field within the request structure to
  4279. * the name of the next exec host to try. Before any of the exec hosts
  4280. * in the action definition are tried, we will try the host passed in as
  4281. * part of the request, if one was specified.
  4282. */
  4283. static void
  4284. SetExecHost (
  4285. ActionRequest * request )
  4286. {
  4287. ActionPtr action = request->clonedAction;
  4288. int hostCount = 0;
  4289. int hostListSize = 0;
  4290. char ** hostList = NULL;
  4291. XtFree(request->currentHost);
  4292. /* If this is the first call, we may need to parse the host list */
  4293. if (action->u.cmd.execHostArray == NULL)
  4294. {
  4295. /* Explicitly specified execHost overrides action definition execHost */
  4296. if (request->execHost)
  4297. ParseHostList(request->execHost, &hostList, &hostListSize, &hostCount);
  4298. else if (action->u.cmd.execHosts.compiledMessage)
  4299. {
  4300. ParseHostList(action->u.cmd.execHosts.compiledMessage, &hostList,
  4301. &hostListSize, &hostCount);
  4302. }
  4303. RemoveDuplicateHostNames(hostList, &hostCount);
  4304. action->u.cmd.execHostArray = hostList;
  4305. action->u.cmd.execHostCount = hostCount;
  4306. }
  4307. if (action->u.cmd.execHostCount == 0)
  4308. {
  4309. /*
  4310. * Oh boy ... someone is trying to be nasty! The only way we could
  4311. * have gotten here was to have the action's 'EXEC_HOST' field set
  4312. * to nothing but a prompt string, and then the user left the string
  4313. * empty! We'll default the local host, and hope it works.
  4314. */
  4315. /*
  4316. * fdt: we really should default to whatever has been configured
  4317. * as the default execution host, followed by the LocalHost,
  4318. * if they are not the same.
  4319. */
  4320. request->currentHost = _DtGetLocalHostName();
  4321. }
  4322. else
  4323. {
  4324. request->currentHost =
  4325. XtNewString(action->u.cmd.execHostArray[request->hostIndex]);
  4326. }
  4327. }
  4328. /*
  4329. * This function takes a string of comma-separated host names, and adds them
  4330. * to the passed-in string array.
  4331. */
  4332. static void
  4333. ParseHostList (
  4334. char * hostString,
  4335. char *** hostListPtr,
  4336. int * hostListSizePtr,
  4337. int * hostCountPtr )
  4338. {
  4339. char * workString;
  4340. char * nextHost;
  4341. _Xstrtokparams strtok_buf;
  4342. workString = XtNewString(hostString);
  4343. nextHost = _XStrtok(workString, ",", strtok_buf);
  4344. while(nextHost)
  4345. {
  4346. nextHost = _DtStripSpaces(nextHost);
  4347. if (strlen(nextHost) > 0)
  4348. {
  4349. if (*hostCountPtr >= *hostListSizePtr)
  4350. {
  4351. (*hostListSizePtr) += 5;
  4352. (*hostListPtr) = (char **)XtRealloc((char *)(*hostListPtr),
  4353. sizeof(char *) * (*hostListSizePtr));
  4354. }
  4355. (*hostListPtr)[*hostCountPtr] = XtNewString(nextHost);
  4356. (*hostCountPtr)++;
  4357. }
  4358. nextHost = _XStrtok(NULL, ",", strtok_buf);
  4359. }
  4360. XtFree(workString);
  4361. }
  4362. /*
  4363. * This function goes through the compiled list of exec hosts, and removes
  4364. * any duplicate entries. It is not very useful to attempt to execute on
  4365. * a given host, more than once.
  4366. */
  4367. static void
  4368. RemoveDuplicateHostNames (
  4369. char ** hostList,
  4370. int * hostCountPtr )
  4371. {
  4372. int i,j,k;
  4373. for (i = 0; i < *hostCountPtr; i++)
  4374. {
  4375. for (j = i+1; j < *hostCountPtr; )
  4376. {
  4377. if (strcmp(hostList[i], hostList[j]) == 0)
  4378. {
  4379. /* Remove the second entry */
  4380. XtFree(hostList[j]);
  4381. for (k = j; k < (*hostCountPtr) - 1; k++)
  4382. hostList[k] = hostList[k+1];
  4383. (*hostCountPtr)--;
  4384. }
  4385. else
  4386. j++;
  4387. }
  4388. }
  4389. }
  4390. /*
  4391. * When one of the exec hosts fails, we add it to the list of failed
  4392. * hostnames, so that if ultimately all of the hosts fail, we have a
  4393. * list we can display within the error dialog.
  4394. */
  4395. static void
  4396. AddFailedHostToList (
  4397. ActionRequest * request,
  4398. String badHost )
  4399. {
  4400. int curLen;
  4401. if (request->badHostList)
  4402. curLen = strlen(request->badHostList);
  4403. else
  4404. curLen = 0;
  4405. request->badHostList = XtRealloc(request->badHostList,
  4406. curLen + 10 + strlen(badHost));
  4407. if (curLen > 0)
  4408. {
  4409. strcat(request->badHostList, ", ");
  4410. strcat(request->badHostList, badHost);
  4411. }
  4412. else
  4413. strcpy(request->badHostList, badHost);
  4414. }
  4415. /*
  4416. *
  4417. * This callback is invoked when the Command Invoker library has successfully
  4418. * exectued an action. We need to free up everything associated with this
  4419. * request.
  4420. */
  4421. static void
  4422. CmdInvSuccessfulRequest(
  4423. char *message,
  4424. void *data2)
  4425. {
  4426. _DtActInvRecT *invp = NULL;
  4427. _DtActChildRecT *childrecp = NULL;
  4428. CallbackData *data = (CallbackData *) data2;
  4429. /*
  4430. * Mark this invocation step as done
  4431. * The child process itself may not be done.
  4432. */
  4433. if ((invp = _DtActFindInvRec(data->requestPtr->invocId)) != NULL )
  4434. {
  4435. extern void *_DtCmdCheckQForId(DtActionInvocationID id);
  4436. SET_INV_DONE(invp->state);
  4437. RESET_INV_CMD_QUEUED(invp->state);
  4438. /*
  4439. * Are there still more commands queued for this request ?
  4440. */
  4441. if ( _DtCmdCheckQForId(invp->id) )
  4442. {
  4443. /*
  4444. * If so; set the command queued bit
  4445. */
  4446. SET_INV_CMD_QUEUED(invp->state);
  4447. }
  4448. /*
  4449. * RWV:
  4450. * This may not be the right place to set the child state for
  4451. * command actions. The child process may already have communicated
  4452. * its status via TT messaging OR it may already have exited.
  4453. * For now we set the state here -- till we find a better place.
  4454. */
  4455. if ((childrecp = _DtActFindChildRec(invp->id,data->requestPtr->childId)))
  4456. childrecp->childState = _DtActCHILD_ALIVE_UNKNOWN;
  4457. else
  4458. myassert(0 /* could not find child record */ );
  4459. _DtActExecutionLeafNodeCleanup(invp->id,NULL,0,True);
  4460. }
  4461. else
  4462. myassert( 0 /* Couldn't find an invocation record */);
  4463. _DtFreeRequest(data->requestPtr);
  4464. XtFree(data->actionLabel);
  4465. XtFree((char *)data);
  4466. }
  4467. /*
  4468. * This callback is invoked when the Command Invoker library has failed
  4469. * to exectue an action. It there are additional execHosts to be processed,
  4470. * then try the command again, using the next host. If there are no more
  4471. * hosts, then post an error dialog, and give up (freeing all data
  4472. * associated with this request).
  4473. */
  4474. static void
  4475. CmdInvFailedRequest(
  4476. char *error_message,
  4477. void *data2)
  4478. {
  4479. CallbackData * data = (CallbackData *) data2;
  4480. String msg = error_message;
  4481. ActionPtr action;
  4482. ActionRequest * request;
  4483. _DtActChildRecT *childp = NULL;
  4484. _DtActInvRecT *invp = NULL;
  4485. /*
  4486. * If this was not the last host in the execHost list, then retry
  4487. * the request, using the next host; if this was the last host,
  4488. * then we failed, and it is time to post an error dialog. If the
  4489. * host list had only one item, then to be backwards compatible,
  4490. * we will display the message returned by the command invoker.
  4491. * Otherwise, we will simple display the list of execHosts, along
  4492. * with a message saying they could not be accessed.
  4493. */
  4494. request = data->requestPtr;
  4495. if (request->clonedAction)
  4496. action = request->clonedAction;
  4497. else
  4498. action = data->actionPtr;
  4499. request->hostIndex++;
  4500. AddFailedHostToList(request, request->currentHost);
  4501. if ( !(invp = _DtActFindInvRec(request->invocId) ) )
  4502. myassert( 0 /* could not find invocation record */ );
  4503. if ( !(childp=_DtActFindChildRec(request->invocId,request->childId)))
  4504. myassert( 0 /* could not find child record */ );
  4505. /*
  4506. * Make sure the CMD_QUEUED bit is set correctly
  4507. */
  4508. if ( invp )
  4509. {
  4510. extern void *_DtCmdCheckQForId(DtActionInvocationID id);
  4511. SET_INV_DONE(invp->state);
  4512. RESET_INV_CMD_QUEUED(invp->state);
  4513. /*
  4514. * Are there still more commands queued for this request ?
  4515. */
  4516. if ( _DtCmdCheckQForId(invp->id) )
  4517. {
  4518. /*
  4519. * If so; set the command queued bit
  4520. */
  4521. SET_INV_CMD_QUEUED(invp->state);
  4522. }
  4523. }
  4524. if (request->hostIndex < action->u.cmd.execHostCount)
  4525. {
  4526. /*
  4527. * Free up the child structure for the failed command request
  4528. * We may be trying again on another host but a new child rec
  4529. * will be allocated in PrepareAndExecute().
  4530. */
  4531. if ( invp && childp )
  4532. {
  4533. /*
  4534. * Delete child record for failed exec on this host
  4535. */
  4536. _DtActDeleteChildRec(invp,childp);
  4537. SET_INV_PENDING(invp->state);
  4538. if ( ! invp->numChildren )
  4539. RESET_INV_WORKING(invp->state);
  4540. }
  4541. /* Retry, using the next host */
  4542. PrepareAndExecuteAction(data->associatedWidget, request);
  4543. }
  4544. else
  4545. {
  4546. if ( invp && childp )
  4547. {
  4548. /*
  4549. * RWV ---
  4550. * How can we tell if the Invocation COMPLETE bit
  4551. * needs to be set here?
  4552. * How about if no invocation is pending or working?
  4553. */
  4554. SET_INV_ERROR(invp->state);
  4555. childp->childState = _DtActCHILD_FAILED;
  4556. }
  4557. /* No more hosts (they all failed); put up error dialog */
  4558. if (action->u.cmd.execHostCount <= 1)
  4559. {
  4560. /* Be backwards compatible */
  4561. CommandInvokerError(data->associatedWidget,
  4562. action->label,
  4563. msg + data->offset);
  4564. }
  4565. else
  4566. {
  4567. MultiHostAccessError(data->associatedWidget, request->clonedAction->label,
  4568. request->badHostList);
  4569. }
  4570. /* Cleanup */
  4571. _DtActExecutionLeafNodeCleanup(invp->id,NULL,0,True);
  4572. _DtFreeRequest(request);
  4573. XtFree(data->actionLabel);
  4574. }
  4575. XtFree((char *)data);
  4576. }
  4577. /*
  4578. * This function maps a filename relative to 'host' to be relative to
  4579. * 'newHost'. If newHost is NULL, then the local host is assumed.
  4580. *
  4581. * The returned string must be freed by the caller.
  4582. */
  4583. char *
  4584. _DtActMapFileName(
  4585. const char * curHost,
  4586. const char * dir,
  4587. const char * file,
  4588. const char * newHost )
  4589. {
  4590. char buf[MAXPATHLEN];
  4591. char *chp = NULL;
  4592. int clen = 0;
  4593. char *netpath = NULL;
  4594. char *path = NULL;
  4595. /*
  4596. * Create the full path name relative to curHost
  4597. */
  4598. buf[0]='\0'; /* empty string to start with */
  4599. if ( dir )
  4600. strcpy(buf,dir);
  4601. if ( file )
  4602. {
  4603. /* check if there is already a '/' separator */
  4604. if ( *file != '/' )
  4605. {
  4606. DtLastChar(buf,&chp,&clen);
  4607. if ( !( (clen == 1) && (*chp == '/')) )
  4608. strcat(buf,"/");
  4609. }
  4610. strcat(buf,file);
  4611. }
  4612. /* We should have constructed a file name string now */
  4613. myassert(buf[0] != '\0');
  4614. if (newHost)
  4615. {
  4616. if ( _DtIsSameHost(curHost,newHost) )
  4617. {
  4618. /*
  4619. * The current host is the same as the new host
  4620. * so no file name translation is necessary
  4621. */
  4622. return XtNewString(buf);
  4623. }
  4624. /*
  4625. * The current host is not the same as the new host -- find the
  4626. * cannonical netfile name then reinterpret it on the new host.
  4627. */
  4628. switch ( tt_ptr_error(netpath = tt_host_file_netfile(curHost,buf)) )
  4629. {
  4630. case TT_OK:
  4631. break;
  4632. case TT_ERR_PATH:
  4633. netpath = NULL;
  4634. break;
  4635. case TT_ERR_DBAVAIL:
  4636. netpath = NULL;
  4637. break;
  4638. case TT_ERR_DBEXIST:
  4639. netpath = NULL;
  4640. break;
  4641. case TT_ERR_INTERNAL:
  4642. netpath = NULL;
  4643. break;
  4644. default:
  4645. netpath = NULL;
  4646. break;
  4647. }
  4648. if ( netpath )
  4649. {
  4650. switch ( tt_ptr_error(path = tt_host_netfile_file(newHost,netpath)) )
  4651. {
  4652. case TT_OK:
  4653. break;
  4654. case TT_ERR_PATH:
  4655. path = NULL;
  4656. break;
  4657. case TT_ERR_DBAVAIL:
  4658. path = NULL;
  4659. break;
  4660. case TT_ERR_DBEXIST:
  4661. path = NULL;
  4662. break;
  4663. case TT_ERR_INTERNAL:
  4664. path = NULL;
  4665. break;
  4666. default:
  4667. path = NULL;
  4668. break;
  4669. }
  4670. }
  4671. } else
  4672. {
  4673. /*
  4674. * Convert the file path which is relative to curHost to be
  4675. * relative to the local host.
  4676. */
  4677. if ( _DtIsSameHost(curHost,NULL) )
  4678. {
  4679. /*
  4680. * The current host is the same as the local host
  4681. * so no file name translation is necessary
  4682. */
  4683. return XtNewString(buf);
  4684. }
  4685. /*
  4686. * The current host is not the same as the local host -- find the
  4687. * cannonical netfile name then reinterpret it on the local host.
  4688. */
  4689. switch ( tt_ptr_error(netpath = tt_host_file_netfile(curHost,buf)) )
  4690. {
  4691. case TT_OK:
  4692. break;
  4693. case TT_ERR_PATH:
  4694. netpath = NULL;
  4695. break;
  4696. case TT_ERR_DBAVAIL:
  4697. netpath = NULL;
  4698. break;
  4699. case TT_ERR_DBEXIST:
  4700. netpath = NULL;
  4701. break;
  4702. case TT_ERR_INTERNAL:
  4703. netpath = NULL;
  4704. break;
  4705. default:
  4706. netpath = NULL;
  4707. break;
  4708. }
  4709. if ( netpath )
  4710. {
  4711. switch ( tt_ptr_error(path = tt_netfile_file(netpath)) )
  4712. {
  4713. case TT_OK:
  4714. break;
  4715. case TT_ERR_PATH:
  4716. path = NULL;
  4717. break;
  4718. case TT_ERR_DBAVAIL:
  4719. path = NULL;
  4720. break;
  4721. case TT_ERR_DBEXIST:
  4722. path = NULL;
  4723. break;
  4724. case TT_ERR_INTERNAL:
  4725. path = NULL;
  4726. break;
  4727. default:
  4728. path = NULL;
  4729. break;
  4730. }
  4731. }
  4732. }
  4733. /*
  4734. * Free up the memory allocated by tooltalk filenaming code here so
  4735. * downstream code need not worry about it.
  4736. */
  4737. if ( netpath )
  4738. tt_free(netpath);
  4739. if ( path )
  4740. {
  4741. char *s = path;
  4742. path = XtNewString(s);
  4743. tt_free(s);
  4744. }
  4745. return path;
  4746. }