main.cpp 214 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576
  1. /*
  2. * Copyright 2005 - 2016 Zarafa and its licensors
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Affero General Public License, version 3,
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Affero General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Affero General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. */
  17. #include "phpconfig.h"
  18. #include <kopano/platform.h>
  19. #include <kopano/ecversion.h>
  20. #include <memory>
  21. #include <new>
  22. #include <cstdio>
  23. #include <cstdlib>
  24. #include <syslog.h>
  25. #include <ctime>
  26. #include <kopano/ECConfig.h>
  27. #include <kopano/ECLogger.h>
  28. #include <kopano/mapi_ptr.h>
  29. #include <kopano/memory.hpp>
  30. #include <kopano/tie.hpp>
  31. #include <kopano/MAPIErrors.h>
  32. #include "ECRulesTableProxy.h"
  33. #include <ICalToMAPI.h>
  34. #include <MAPIToICal.h>
  35. #include <libicalmapi/mapitovcf.hpp>
  36. #include <libicalmapi/vcftomapi.hpp>
  37. #define LOGFILE_PATH "/var/log/kopano"
  38. /*
  39. * Things to notice when reading/editing this source:
  40. *
  41. * - RETURN_... returns in the define, the rest of the function is skipped.
  42. * - RETVAL_... only sets the return value, the rest of the function is processed.
  43. *
  44. * - do not use E_ERROR as it cannot be fetched by the php script. Use E_WARNING.
  45. *
  46. * - do not create HRESULT variables, but use MAPI_G(hr) so the php script
  47. * can retrieve the value with mapi_last_hresult()
  48. *
  49. * - all internal functions need to pass TSRMLS_CC in the end, so win32 version compiles
  50. *
  51. * - when using "l" in zend_parse_parameters(), use 'long' (64-bit) as variable type, not ULONG (32-bit)
  52. * - when using "s" in zend_parse_parameters(), the string length is 32 bits, so use 'unsigned int' or 'ULONG'
  53. *
  54. */
  55. /*
  56. * Some information on objects, refcounts, and how PHP manages memory:
  57. *
  58. * Each ZVAL is allocated when doing MAKE_STD_ZVAL or INIT_ALLOC_ZVAL. These allocate the
  59. * space for the ZVAL struct and nothing else. When you put a value in it, INTs and other small
  60. * values are stored in the ZVAL itself. When you add a string, more memory is allocated
  61. * (eg through ZVAL_STRING()) to the ZVAL. Some goes for arrays and associated arrays.
  62. *
  63. * The data is freed by PHP by traversing the entire ZVAL and freeing each part of the ZVAL
  64. * it encounters. So, for an array or string ZVAL, it will be doing more frees than just the base
  65. * value. The freeing is done in zval_dtor().
  66. *
  67. * This system means that MAKE_STD_ZVAL(&zval); ZVAL_STRING(zval, "hello", 0); zval_dtor(zval) will
  68. * segfault. This is because it will try to free the "hello" string, which was not allocated by PHP.
  69. * So, always use the 'copy' flag when using constant strings (eg ZVAL_STRING(zval, "hello", 1)). This
  70. * wastes memory, but makes life a lot easier.
  71. *
  72. * There is also a referencing system in PHP that is basically the same as the AddRef() and Release()
  73. * COM scheme. When you MAKE_STD_ZVAL or ALLOC_INIT_ZVAL, the refcount is 1. You should then always
  74. * make sure that you never destroy the value with zval_dtor (directly calls the destructor and then
  75. * calls FREE_ZVAL) when somebody else *could* have a reference to it. Using zval_dtor on values that
  76. * users may have a reference to is a security hole. (see http://www.php-security.org/MOPB/MOPB-24-2007.html)
  77. * Although I think this should only happen when you're calling into PHP user space with call_user_function()
  78. *
  79. * What you *should* do is use zval_ptr_dtor(). This is not just the same as zval_dtor!!! It first decreases
  80. * the refcount, and *then* destroys the zval, but only if the refcount is 0. So zval_ptr_dtor is the
  81. * same as Release() in COM.
  82. *
  83. * This means that you should basically always use MAKE_STD_ZVAL and then zval_ptr_dtor(), and you
  84. * should always be safe. You can easily break things by calling ZVAL_DELREF() too many times. Worst thing is,
  85. * you won't notice that you've broken it until a while later in the PHP script ...
  86. *
  87. * We have one thing here which doesn't follow this pattern: some functions use RETVAL_ZVAL to copy the value
  88. * of one zval into the 'return_value' zval. Seen as we don't want to do a real copy and then a free, we use
  89. * RETVAL_ZVAL(val, 0, 0), specifying that the value of the zval should not be copied, but just referenced, and
  90. * we also specify 0 for the 'dtor' flag. This would cause PHP to destruct the old value, but the old value is
  91. * pointing at the same data als the return_value zval! So we want to release *only* the ZVAL itself, which we do
  92. * via FREE_ZVAL.
  93. *
  94. * I think.
  95. *
  96. * Steve
  97. *
  98. */
  99. /***************************************************************
  100. * PHP Includes
  101. ***************************************************************/
  102. // we need to include this in c++ space because php.h also includes it in
  103. // 'extern "C"'-space which doesn't work in win32
  104. #include <cmath>
  105. extern "C" {
  106. // Remove these defines to remove warnings
  107. #undef PACKAGE_VERSION
  108. #undef PACKAGE_TARNAME
  109. #undef PACKAGE_NAME
  110. #undef PACKAGE_STRING
  111. #undef PACKAGE_BUGREPORT
  112. #include "php.h"
  113. #include "php_globals.h"
  114. #include "php_ini.h"
  115. #include "zend_exceptions.h"
  116. #include "ext/standard/info.h"
  117. #include "ext/standard/php_string.h"
  118. }
  119. // Destructor functions needed for the PHP resources.
  120. static void _php_free_mapi_session(zend_rsrc_list_entry *rsrc TSRMLS_DC);
  121. static void _php_free_mapi_rowset(zend_rsrc_list_entry *rsrc TSRMLS_DC);
  122. static void _php_free_mapi_object(zend_rsrc_list_entry *rsrc TSRMLS_DC);
  123. static void _php_free_istream(zend_rsrc_list_entry *rsrc TSRMLS_DC);
  124. static void _php_free_fb_object(zend_rsrc_list_entry *rsrc TSRMLS_DC);
  125. // Not defined anymore in PHP 5.3.0
  126. // we only use first and fourth versions, so just define those.
  127. #if ZEND_MODULE_API_NO >= 20071006
  128. ZEND_BEGIN_ARG_INFO(first_arg_force_ref, 0)
  129. ZEND_ARG_PASS_INFO(1)
  130. ZEND_END_ARG_INFO()
  131. ZEND_BEGIN_ARG_INFO(fourth_arg_force_ref, 0)
  132. ZEND_ARG_PASS_INFO(0)
  133. ZEND_ARG_PASS_INFO(0)
  134. ZEND_ARG_PASS_INFO(0)
  135. ZEND_ARG_PASS_INFO(1)
  136. ZEND_END_ARG_INFO()
  137. #endif
  138. #define LOG_BEGIN() { \
  139. if (mapi_debug & 1) { \
  140. php_error_docref(NULL TSRMLS_CC, E_NOTICE, "[IN] %s", __FUNCTION__); \
  141. } \
  142. }
  143. #define LOG_END() { \
  144. if (mapi_debug & 2) { \
  145. HRESULT hrx = MAPI_G(hr); \
  146. php_error_docref(NULL TSRMLS_CC, E_NOTICE, "[OUT] %s hr=0x%08x", __FUNCTION__, hrx); \
  147. } \
  148. }
  149. /* Only PHP >= 5.6 (or so) has the type of "resource_type_name" properly */
  150. #define ZEND_FETCH_RESOURCE_C(rsrc, rsrc_type, passed_id, default_id, resource_type_name, resource_type) \
  151. ZEND_FETCH_RESOURCE((rsrc), rsrc_type, (passed_id), (default_id), const_cast<char *>(resource_type_name), (resource_type))
  152. #define UOBJ_REGISTER_RESOURCE(rv, obj, categ) \
  153. ZEND_REGISTER_RESOURCE((rv), static_cast<IUnknown *>(obj), categ)
  154. // A very, very nice PHP #define that causes link errors in MAPI when you have multiple
  155. // files referencing MAPI....
  156. #undef inline
  157. /***************************************************************
  158. * MAPI Includes
  159. ***************************************************************/
  160. #include <mapi.h>
  161. #include <mapix.h>
  162. #include <mapiutil.h>
  163. #include <mapispi.h>
  164. #include <mapitags.h>
  165. #include <mapidefs.h>
  166. #include <kopano/IECServiceAdmin.h>
  167. #include <kopano/IECSecurity.h>
  168. #include <kopano/IECUnknown.h>
  169. #include "IECExportChanges.h"
  170. #include "IECMultiStoreTable.h"
  171. #include <kopano/IECLicense.h>
  172. #include <kopano/ECTags.h>
  173. #include <kopano/ECDefs.h>
  174. #define USES_IID_IMAPIProp
  175. #define USES_IID_IMAPIContainer
  176. #define USES_IID_IMsgStore
  177. #define USES_IID_IMessage
  178. #define USES_IID_IExchangeManageStore
  179. #define USES_IID_IECExportChanges
  180. #include <string>
  181. #include "util.h"
  182. #include "rtfutil.h"
  183. #include <kopano/CommonUtil.h>
  184. #include "ECImportContentsChangesProxy.h"
  185. #include "ECImportHierarchyChangesProxy.h"
  186. #include "ECMemStream.h"
  187. #include <inetmapi/inetmapi.h>
  188. #include <inetmapi/options.h>
  189. #include <edkmdb.h>
  190. #include <mapiguid.h>
  191. #include <kopano/ECGuid.h>
  192. #include <edkguid.h>
  193. //Freebusy includes
  194. #include "ECFreeBusySupport.h"
  195. #include "favoritesutil.h"
  196. // at last, the php-plugin extension headers
  197. #include "main.h"
  198. #include "typeconversion.h"
  199. #include "MAPINotifSink.h"
  200. #include <kopano/charset/convert.h>
  201. #include <kopano/charset/utf8string.h>
  202. #include "charset/localeutil.h"
  203. #define PMEASURE_FUNC pmeasure __pmobject(__PRETTY_FUNCTION__);
  204. using namespace KCHL;
  205. class pmeasure {
  206. public:
  207. pmeasure(const std::string &);
  208. ~pmeasure(void);
  209. private:
  210. std::string what;
  211. unsigned long long start_ts = 0;
  212. };
  213. using namespace std;
  214. static ECLogger *lpLogger = NULL;
  215. #define MAPI_ASSERT_EX
  216. static unsigned int mapi_debug;
  217. static char *perf_measure_file;
  218. pmeasure::pmeasure(const std::string &whatIn)
  219. {
  220. if (perf_measure_file == NULL || *perf_measure_file == '\0')
  221. return;
  222. what = whatIn;
  223. struct timespec ts;
  224. clock_gettime(CLOCK_MONOTONIC, &ts);
  225. start_ts = ts.tv_sec * 1000 * 1000 + ts.tv_nsec / 1000;
  226. }
  227. pmeasure::~pmeasure(void)
  228. {
  229. if (perf_measure_file == NULL || *perf_measure_file == '\0')
  230. return;
  231. struct timespec ts;
  232. clock_gettime(CLOCK_MONOTONIC, &ts);
  233. FILE *fh = fopen(perf_measure_file, "a+");
  234. if (fh == NULL) {
  235. if (lpLogger != NULL)
  236. lpLogger->Log(EC_LOGLEVEL_ERROR, "~pmeasure: cannot open \"%s\": %s", perf_measure_file, strerror(errno));
  237. return;
  238. }
  239. unsigned long long int now = ts.tv_sec * 1000 * 1000 + ts.tv_nsec / 1000;
  240. unsigned long long int tdiff = now - start_ts;
  241. fprintf(fh, "%lld %s\n", tdiff, what.c_str());
  242. fclose(fh);
  243. }
  244. /* function list so that the Zend engine will know what's here */
  245. zend_function_entry mapi_functions[] =
  246. {
  247. ZEND_FE(mapi_last_hresult, NULL)
  248. ZEND_FE(mapi_prop_type, NULL)
  249. ZEND_FE(mapi_prop_id, NULL)
  250. ZEND_FE(mapi_is_error, NULL)
  251. ZEND_FE(mapi_make_scode, NULL)
  252. ZEND_FE(mapi_prop_tag, NULL)
  253. ZEND_FE(mapi_createoneoff, NULL)
  254. ZEND_FE(mapi_parseoneoff, NULL)
  255. ZEND_FE(mapi_logon, NULL)
  256. ZEND_FE(mapi_logon_zarafa, NULL)
  257. ZEND_FE(mapi_getmsgstorestable, NULL)
  258. ZEND_FE(mapi_openmsgstore, NULL)
  259. ZEND_FE(mapi_openprofilesection, NULL)
  260. ZEND_FE(mapi_openaddressbook, NULL)
  261. ZEND_FE(mapi_openentry, NULL)
  262. ZEND_FE(mapi_ab_openentry, NULL)
  263. // TODO: add other functions for le_mapi_mailuser and le_mapi_distlist
  264. ZEND_FE(mapi_ab_resolvename, NULL)
  265. ZEND_FE(mapi_ab_getdefaultdir, NULL)
  266. ZEND_FE(mapi_msgstore_createentryid, NULL)
  267. ZEND_FE(mapi_msgstore_getarchiveentryid, NULL)
  268. ZEND_FE(mapi_msgstore_openentry, NULL)
  269. ZEND_FE(mapi_msgstore_getreceivefolder, NULL)
  270. ZEND_FE(mapi_msgstore_entryidfromsourcekey, NULL)
  271. ZEND_FE(mapi_msgstore_openmultistoretable, NULL)
  272. ZEND_FE(mapi_msgstore_advise, NULL)
  273. ZEND_FE(mapi_msgstore_unadvise, NULL)
  274. ZEND_FE(mapi_sink_create, NULL)
  275. ZEND_FE(mapi_sink_timedwait, NULL)
  276. ZEND_FE(mapi_table_queryallrows, NULL)
  277. ZEND_FE(mapi_table_queryrows, NULL)
  278. ZEND_FE(mapi_table_getrowcount, NULL)
  279. ZEND_FE(mapi_table_setcolumns, NULL)
  280. ZEND_FE(mapi_table_seekrow, NULL)
  281. ZEND_FE(mapi_table_sort, NULL)
  282. ZEND_FE(mapi_table_restrict, NULL)
  283. ZEND_FE(mapi_table_findrow, NULL)
  284. ZEND_FE(mapi_table_createbookmark, NULL)
  285. ZEND_FE(mapi_table_freebookmark, NULL)
  286. ZEND_FE(mapi_folder_gethierarchytable, NULL)
  287. ZEND_FE(mapi_folder_getcontentstable, NULL)
  288. ZEND_FE(mapi_folder_createmessage, NULL)
  289. ZEND_FE(mapi_folder_createfolder, NULL)
  290. ZEND_FE(mapi_folder_deletemessages, NULL)
  291. ZEND_FE(mapi_folder_copymessages, NULL)
  292. ZEND_FE(mapi_folder_emptyfolder, NULL)
  293. ZEND_FE(mapi_folder_copyfolder, NULL)
  294. ZEND_FE(mapi_folder_deletefolder, NULL)
  295. ZEND_FE(mapi_folder_setreadflags, NULL)
  296. ZEND_FE(mapi_folder_openmodifytable, NULL)
  297. ZEND_FE(mapi_folder_setsearchcriteria, NULL)
  298. ZEND_FE(mapi_folder_getsearchcriteria, NULL)
  299. ZEND_FE(mapi_message_getattachmenttable, NULL)
  300. ZEND_FE(mapi_message_getrecipienttable, NULL)
  301. ZEND_FE(mapi_message_openattach, NULL)
  302. ZEND_FE(mapi_message_createattach, NULL)
  303. ZEND_FE(mapi_message_deleteattach, NULL)
  304. ZEND_FE(mapi_message_modifyrecipients, NULL)
  305. ZEND_FE(mapi_message_submitmessage, NULL)
  306. ZEND_FE(mapi_message_setreadflag, NULL)
  307. ZEND_FE(mapi_openpropertytostream, NULL)
  308. ZEND_FE(mapi_stream_write, NULL)
  309. ZEND_FE(mapi_stream_read, NULL)
  310. ZEND_FE(mapi_stream_stat, NULL)
  311. ZEND_FE(mapi_stream_seek, NULL)
  312. ZEND_FE(mapi_stream_commit, NULL)
  313. ZEND_FE(mapi_stream_setsize, NULL)
  314. ZEND_FE(mapi_stream_create, NULL)
  315. ZEND_FE(mapi_attach_openobj, NULL)
  316. ZEND_FE(mapi_savechanges, NULL)
  317. ZEND_FE(mapi_getprops, NULL)
  318. ZEND_FE(mapi_setprops, NULL)
  319. ZEND_FE(mapi_copyto, NULL)
  320. ZEND_FE(mapi_openproperty, NULL)
  321. ZEND_FE(mapi_deleteprops, NULL)
  322. ZEND_FE(mapi_getnamesfromids, NULL)
  323. ZEND_FE(mapi_getidsfromnames, NULL)
  324. ZEND_FE(mapi_decompressrtf, NULL)
  325. ZEND_FE(mapi_rules_gettable, NULL)
  326. ZEND_FE(mapi_rules_modifytable, NULL)
  327. ZEND_FE(mapi_zarafa_createuser, NULL)
  328. ZEND_FE(mapi_zarafa_setuser, NULL)
  329. ZEND_FE(mapi_zarafa_getuser_by_id, NULL)
  330. ZEND_FE(mapi_zarafa_getuser_by_name, NULL)
  331. ZEND_FE(mapi_zarafa_deleteuser, NULL)
  332. ZEND_FE(mapi_zarafa_createstore, NULL)
  333. ZEND_FE(mapi_zarafa_getuserlist, NULL)
  334. ZEND_FE(mapi_zarafa_getquota, NULL)
  335. ZEND_FE(mapi_zarafa_setquota, NULL)
  336. ZEND_FE(mapi_zarafa_creategroup, NULL)
  337. ZEND_FE(mapi_zarafa_deletegroup, NULL)
  338. ZEND_FE(mapi_zarafa_addgroupmember, NULL)
  339. ZEND_FE(mapi_zarafa_deletegroupmember, NULL)
  340. ZEND_FE(mapi_zarafa_setgroup, NULL)
  341. ZEND_FE(mapi_zarafa_getgroup_by_id, NULL)
  342. ZEND_FE(mapi_zarafa_getgroup_by_name, NULL)
  343. ZEND_FE(mapi_zarafa_getgrouplist, NULL)
  344. ZEND_FE(mapi_zarafa_getgrouplistofuser, NULL)
  345. ZEND_FE(mapi_zarafa_getuserlistofgroup, NULL)
  346. ZEND_FE(mapi_zarafa_createcompany, NULL)
  347. ZEND_FE(mapi_zarafa_deletecompany, NULL)
  348. ZEND_FE(mapi_zarafa_getcompany_by_id, NULL)
  349. ZEND_FE(mapi_zarafa_getcompany_by_name, NULL)
  350. ZEND_FE(mapi_zarafa_getcompanylist, NULL)
  351. ZEND_FE(mapi_zarafa_add_company_remote_viewlist, NULL)
  352. ZEND_FE(mapi_zarafa_del_company_remote_viewlist, NULL)
  353. ZEND_FE(mapi_zarafa_get_remote_viewlist, NULL)
  354. ZEND_FE(mapi_zarafa_add_user_remote_adminlist, NULL)
  355. ZEND_FE(mapi_zarafa_del_user_remote_adminlist, NULL)
  356. ZEND_FE(mapi_zarafa_get_remote_adminlist, NULL)
  357. ZEND_FE(mapi_zarafa_add_quota_recipient, NULL)
  358. ZEND_FE(mapi_zarafa_del_quota_recipient, NULL)
  359. ZEND_FE(mapi_zarafa_get_quota_recipientlist, NULL)
  360. ZEND_FE(mapi_zarafa_check_license, NULL)
  361. ZEND_FE(mapi_zarafa_getcapabilities, NULL)
  362. ZEND_FE(mapi_zarafa_getpermissionrules, NULL)
  363. ZEND_FE(mapi_zarafa_setpermissionrules, NULL)
  364. ZEND_FE(mapi_freebusysupport_open, NULL)
  365. ZEND_FE(mapi_freebusysupport_close, NULL)
  366. ZEND_FE(mapi_freebusysupport_loaddata, NULL)
  367. ZEND_FE(mapi_freebusysupport_loadupdate, NULL)
  368. ZEND_FE(mapi_freebusydata_enumblocks, NULL)
  369. ZEND_FE(mapi_freebusydata_getpublishrange, NULL)
  370. ZEND_FE(mapi_freebusydata_setrange, NULL)
  371. ZEND_FE(mapi_freebusyenumblock_reset, NULL)
  372. ZEND_FE(mapi_freebusyenumblock_next, NULL)
  373. ZEND_FE(mapi_freebusyenumblock_skip, NULL)
  374. ZEND_FE(mapi_freebusyenumblock_restrict, NULL)
  375. ZEND_FE(mapi_freebusyupdate_publish, NULL)
  376. ZEND_FE(mapi_freebusyupdate_reset, NULL)
  377. ZEND_FE(mapi_freebusyupdate_savechanges, NULL)
  378. ZEND_FE(mapi_favorite_add, NULL)
  379. ZEND_FE(mapi_exportchanges_config, NULL)
  380. ZEND_FE(mapi_exportchanges_synchronize, NULL)
  381. ZEND_FE(mapi_exportchanges_updatestate, NULL)
  382. ZEND_FE(mapi_exportchanges_getchangecount, NULL)
  383. ZEND_FE(mapi_importcontentschanges_config, NULL)
  384. ZEND_FE(mapi_importcontentschanges_updatestate, NULL)
  385. ZEND_FE(mapi_importcontentschanges_importmessagechange, fourth_arg_force_ref)
  386. ZEND_FE(mapi_importcontentschanges_importmessagedeletion, NULL)
  387. ZEND_FE(mapi_importcontentschanges_importperuserreadstatechange, NULL)
  388. ZEND_FE(mapi_importcontentschanges_importmessagemove, NULL)
  389. ZEND_FE(mapi_importhierarchychanges_config, NULL)
  390. ZEND_FE(mapi_importhierarchychanges_updatestate, NULL)
  391. ZEND_FE(mapi_importhierarchychanges_importfolderchange, NULL)
  392. ZEND_FE(mapi_importhierarchychanges_importfolderdeletion, NULL)
  393. ZEND_FE(mapi_wrap_importcontentschanges, first_arg_force_ref)
  394. ZEND_FE(mapi_wrap_importhierarchychanges, first_arg_force_ref)
  395. ZEND_FE(mapi_inetmapi_imtoinet, NULL)
  396. ZEND_FE(mapi_inetmapi_imtomapi, NULL)
  397. ZEND_FE(mapi_icaltomapi, nullptr)
  398. ZEND_FE(mapi_mapitoical, nullptr)
  399. ZEND_FE(mapi_vcftomapi, nullptr)
  400. ZEND_FE(mapi_mapitovcf, nullptr)
  401. ZEND_FE(mapi_enable_exceptions, NULL)
  402. ZEND_FE(mapi_feature, NULL)
  403. ZEND_FALIAS(mapi_attach_openbin, mapi_openproperty, NULL)
  404. ZEND_FALIAS(mapi_msgstore_getprops, mapi_getprops, NULL)
  405. ZEND_FALIAS(mapi_msgstore_setprops, mapi_setprops, NULL)
  406. ZEND_FALIAS(mapi_folder_getprops, mapi_getprops, NULL)
  407. ZEND_FALIAS(mapi_folder_openproperty, mapi_openproperty, NULL)
  408. ZEND_FALIAS(mapi_folder_setprops, mapi_setprops, NULL)
  409. ZEND_FALIAS(mapi_message_getprops, mapi_getprops, NULL)
  410. ZEND_FALIAS(mapi_message_setprops, mapi_setprops, NULL)
  411. ZEND_FALIAS(mapi_message_openproperty, mapi_openproperty, NULL)
  412. ZEND_FALIAS(mapi_attach_getprops, mapi_getprops, NULL)
  413. ZEND_FALIAS(mapi_attach_setprops, mapi_setprops, NULL)
  414. ZEND_FALIAS(mapi_attach_openproperty, mapi_openproperty, NULL)
  415. ZEND_FALIAS(mapi_message_savechanges, mapi_savechanges, NULL)
  416. // old versions
  417. ZEND_FALIAS(mapi_zarafa_getuser, mapi_zarafa_getuser_by_name, NULL)
  418. ZEND_FALIAS(mapi_zarafa_getgroup, mapi_zarafa_getgroup_by_name, NULL)
  419. {NULL, NULL, NULL}
  420. };
  421. ZEND_DECLARE_MODULE_GLOBALS(mapi)
  422. static void php_mapi_init_globals(zend_mapi_globals *mapi_globals) {
  423. // seems to be empty ..
  424. }
  425. /* module information */
  426. zend_module_entry mapi_module_entry =
  427. {
  428. STANDARD_MODULE_HEADER,
  429. "mapi", /* name */
  430. mapi_functions, /* functionlist */
  431. PHP_MINIT(mapi), /* module startup function */
  432. PHP_MSHUTDOWN(mapi),/* module shutdown function */
  433. PHP_RINIT(mapi), /* Request init function */
  434. PHP_RSHUTDOWN(mapi),/* Request shutdown function */
  435. PHP_MINFO(mapi), /* Info function */
  436. PROJECT_VERSION_DOT_STR "-" PROJECT_SVN_REV_STR, /* version */
  437. STANDARD_MODULE_PROPERTIES
  438. };
  439. #if COMPILE_DL_MAPI
  440. BEGIN_EXTERN_C()
  441. ZEND_DLEXPORT zend_module_entry *get_module(void);
  442. ZEND_GET_MODULE(mapi)
  443. END_EXTERN_C()
  444. #endif
  445. /***************************************************************
  446. * PHP Module functions
  447. ***************************************************************/
  448. PHP_MINFO_FUNCTION(mapi)
  449. {
  450. php_info_print_table_start();
  451. php_info_print_table_row(2, "MAPI Support", "enabled");
  452. php_info_print_table_row(2, "Version", PROJECT_VERSION_EXT_STR);
  453. php_info_print_table_row(2, "Git version", PROJECT_SVN_REV_STR);
  454. php_info_print_table_end();
  455. }
  456. #define CE_PHP_MAPI_PERFORMANCE_TRACE_FILE "php_mapi_performance_trace_file"
  457. #define CE_PHP_MAPI_DEBUG "php_mapi_debug"
  458. static int LoadSettingsFile(void)
  459. {
  460. const char *const cfg_file = ECConfig::GetDefaultPath("php-mapi.cfg");
  461. struct stat st;
  462. if (stat(cfg_file, &st) == 0) {
  463. static const configsetting_t settings[] = {
  464. { "log_method", "syslog" },
  465. { "log_file", LOGFILE_PATH "/php-mapi.log" },
  466. { "log_level", "3", CONFIGSETTING_RELOADABLE },
  467. { "log_timestamp", "0" },
  468. { "log_buffer_size", "0" },
  469. { "log_buffer_size", "0" },
  470. { CE_PHP_MAPI_PERFORMANCE_TRACE_FILE, "" },
  471. { CE_PHP_MAPI_DEBUG, "0" },
  472. { NULL, NULL }
  473. };
  474. auto cfg = ECConfig::Create(std::nothrow, settings);
  475. if (!cfg)
  476. return FAILURE;
  477. if (cfg->LoadSettings(cfg_file))
  478. lpLogger = CreateLogger(cfg, "php-mapi", "PHPMapi");
  479. const char *temp = cfg->GetSetting(CE_PHP_MAPI_PERFORMANCE_TRACE_FILE);
  480. if (temp != NULL) {
  481. perf_measure_file = strdup(temp);
  482. lpLogger->Log(EC_LOGLEVEL_INFO, "PHP-MAPI Performance measuring enabled");
  483. }
  484. temp = cfg->GetSetting(CE_PHP_MAPI_DEBUG);
  485. if (temp != NULL)
  486. mapi_debug = strtoul(temp, NULL, 0);
  487. delete cfg;
  488. }
  489. if (!lpLogger)
  490. lpLogger = new(std::nothrow) ECLogger_Null();
  491. if (lpLogger == NULL)
  492. return FAILURE;
  493. lpLogger->Log(EC_LOGLEVEL_INFO, "PHP-MAPI instantiated " PROJECT_VERSION_EXT_STR);
  494. ec_log_set(lpLogger);
  495. if (mapi_debug)
  496. lpLogger->Log(EC_LOGLEVEL_INFO, "PHP-MAPI trace level set to %d", mapi_debug);
  497. return SUCCESS;
  498. }
  499. /**
  500. * Initfunction for the module, will be called once at server startup
  501. */
  502. PHP_MINIT_FUNCTION(mapi) {
  503. int ret = LoadSettingsFile();
  504. if (ret != SUCCESS)
  505. return ret;
  506. le_mapi_session = zend_register_list_destructors_ex(_php_free_mapi_session, NULL, const_cast<char *>(name_mapi_session), module_number);
  507. le_mapi_table = zend_register_list_destructors_ex(_php_free_mapi_object, NULL, const_cast<char *>(name_mapi_table), module_number);
  508. le_mapi_rowset = zend_register_list_destructors_ex(_php_free_mapi_rowset, NULL, const_cast<char *>(name_mapi_rowset), module_number);
  509. le_mapi_msgstore = zend_register_list_destructors_ex(_php_free_mapi_object, NULL, const_cast<char *>(name_mapi_msgstore), module_number);
  510. le_mapi_addrbook = zend_register_list_destructors_ex(_php_free_mapi_object, NULL, const_cast<char *>(name_mapi_addrbook), module_number);
  511. le_mapi_mailuser = zend_register_list_destructors_ex(_php_free_mapi_object, NULL, const_cast<char *>(name_mapi_mailuser), module_number);
  512. le_mapi_distlist = zend_register_list_destructors_ex(_php_free_mapi_object, NULL, const_cast<char *>(name_mapi_distlist), module_number);
  513. le_mapi_abcont = zend_register_list_destructors_ex(_php_free_mapi_object, NULL, const_cast<char *>(name_mapi_abcont), module_number);
  514. le_mapi_folder = zend_register_list_destructors_ex(_php_free_mapi_object, NULL, const_cast<char *>(name_mapi_folder), module_number);
  515. le_mapi_message = zend_register_list_destructors_ex(_php_free_mapi_object, NULL, const_cast<char *>(name_mapi_message), module_number);
  516. le_mapi_attachment = zend_register_list_destructors_ex(_php_free_mapi_object, NULL, const_cast<char *>(name_mapi_attachment), module_number);
  517. le_mapi_property = zend_register_list_destructors_ex(_php_free_mapi_object, NULL, const_cast<char *>(name_mapi_property), module_number);
  518. le_mapi_modifytable = zend_register_list_destructors_ex(_php_free_mapi_object, NULL, const_cast<char *>(name_mapi_modifytable), module_number);
  519. le_mapi_advisesink = zend_register_list_destructors_ex(_php_free_mapi_object, NULL, const_cast<char *>(name_mapi_advisesink), module_number);
  520. le_istream = zend_register_list_destructors_ex(_php_free_istream, NULL, const_cast<char *>(name_istream), module_number);
  521. // Freebusy functions
  522. le_freebusy_support = zend_register_list_destructors_ex(_php_free_fb_object, NULL, const_cast<char *>(name_fb_support), module_number);
  523. le_freebusy_data = zend_register_list_destructors_ex(_php_free_fb_object, NULL, const_cast<char *>(name_fb_data), module_number);
  524. le_freebusy_update = zend_register_list_destructors_ex(_php_free_fb_object, NULL, const_cast<char *>(name_fb_update), module_number);
  525. le_freebusy_enumblock = zend_register_list_destructors_ex(_php_free_fb_object, NULL, const_cast<char *>(name_fb_enumblock), module_number);
  526. // ICS interfaces
  527. le_mapi_exportchanges = zend_register_list_destructors_ex(_php_free_mapi_object, NULL, const_cast<char *>(name_mapi_exportchanges), module_number);
  528. le_mapi_importhierarchychanges = zend_register_list_destructors_ex(_php_free_mapi_object, NULL, const_cast<char *>(name_mapi_importhierarchychanges), module_number);
  529. le_mapi_importcontentschanges = zend_register_list_destructors_ex(_php_free_mapi_object, NULL, const_cast<char *>(name_mapi_importcontentschanges), module_number);
  530. MAPIINIT_0 MAPIINIT = { 0, MAPI_MULTITHREAD_NOTIFICATIONS };
  531. // There is also a MAPI_NT_SERVICE flag, see help page for MAPIInitialize
  532. if (MAPIInitialize(&MAPIINIT) != hrSuccess)
  533. return FAILURE;
  534. ZEND_INIT_MODULE_GLOBALS(mapi, php_mapi_init_globals, NULL);
  535. // force this program to use UTF-8, that way, we don't have to use lpszW and do all kinds of conversions from UTF-8 to WCHAR and back
  536. forceUTF8Locale(false);
  537. return SUCCESS;
  538. }
  539. // Used at the end of each MAPI call to throw exceptions if mapi_enable_exceptions() has been called
  540. #define THROW_ON_ERROR() \
  541. if (FAILED(MAPI_G(hr))) { \
  542. if (lpLogger) \
  543. lpLogger->Log(EC_LOGLEVEL_ERROR, "MAPI error: %s (%x) (method: %s, line: %d)", GetMAPIErrorMessage(MAPI_G(hr)), MAPI_G(hr), __FUNCTION__, __LINE__); \
  544. \
  545. if (MAPI_G(exceptions_enabled)) \
  546. zend_throw_exception(MAPI_G(exception_ce), "MAPI error ", MAPI_G(hr) TSRMLS_CC); \
  547. }
  548. /**
  549. *
  550. *
  551. */
  552. PHP_MSHUTDOWN_FUNCTION(mapi)
  553. {
  554. UNREGISTER_INI_ENTRIES();
  555. free(perf_measure_file);
  556. perf_measure_file = NULL;
  557. if (lpLogger)
  558. lpLogger->Log(EC_LOGLEVEL_INFO, "PHP-MAPI shutdown");
  559. MAPIUninitialize();
  560. if (lpLogger != NULL)
  561. lpLogger->Release();
  562. lpLogger = NULL;
  563. return SUCCESS;
  564. }
  565. /***************************************************************
  566. * PHP Request functions
  567. ***************************************************************/
  568. /**
  569. * Request init function, will be called before every request.
  570. *
  571. */
  572. PHP_RINIT_FUNCTION(mapi) {
  573. MAPI_G(hr) = hrSuccess;
  574. MAPI_G(exception_ce) = NULL;
  575. MAPI_G(exceptions_enabled) = false;
  576. return SUCCESS;
  577. }
  578. /**
  579. * Request shutdown function, will be called after every request.
  580. *
  581. */
  582. PHP_RSHUTDOWN_FUNCTION(mapi) {
  583. return SUCCESS;
  584. }
  585. /***************************************************************
  586. * Resource Destructor functions
  587. ***************************************************************/
  588. // This is called when our proxy object goes out of scope
  589. static void _php_free_mapi_session(zend_rsrc_list_entry *rsrc TSRMLS_DC)
  590. {
  591. PMEASURE_FUNC;
  592. auto lpSession = static_cast<IMAPISession *>(rsrc->ptr);
  593. if(lpSession) lpSession->Release();
  594. }
  595. static void _php_free_mapi_rowset(zend_rsrc_list_entry *rsrc TSRMLS_DC)
  596. {
  597. auto pRowSet = static_cast<SRowSet *>(rsrc->ptr);
  598. if (pRowSet) FreeProws(pRowSet);
  599. }
  600. static void _php_free_mapi_object(zend_rsrc_list_entry *rsrc TSRMLS_DC)
  601. {
  602. auto lpUnknown = static_cast<IUnknown *>(rsrc->ptr);
  603. if (lpUnknown) lpUnknown->Release();
  604. }
  605. static void _php_free_istream(zend_rsrc_list_entry *rsrc TSRMLS_DC)
  606. {
  607. auto pStream = static_cast<IStream *>(rsrc->ptr);
  608. if (pStream) pStream->Release();
  609. }
  610. static void _php_free_fb_object(zend_rsrc_list_entry *rsrc TSRMLS_DC)
  611. {
  612. auto lpObj = static_cast<IUnknown *>(rsrc->ptr);
  613. if (lpObj) lpObj->Release();
  614. }
  615. static HRESULT GetECObject(LPMAPIPROP lpMapiProp,
  616. IECUnknown **lppIECUnknown TSRMLS_DC)
  617. {
  618. PMEASURE_FUNC;
  619. memory_ptr<SPropValue> lpPropVal;
  620. MAPI_G(hr) = HrGetOneProp(lpMapiProp, PR_EC_OBJECT, &~lpPropVal);
  621. if (MAPI_G(hr) == hrSuccess)
  622. *lppIECUnknown = (IECUnknown *)lpPropVal->Value.lpszA;
  623. return MAPI_G(hr);
  624. }
  625. /***************************************************************
  626. * Custom Code
  627. ***************************************************************/
  628. ZEND_FUNCTION(mapi_last_hresult)
  629. {
  630. RETURN_LONG((LONG)MAPI_G(hr));
  631. }
  632. /*
  633. * PHP casts a variable to a signed long before bitshifting. So a C++ function
  634. * is used.
  635. */
  636. ZEND_FUNCTION(mapi_prop_type)
  637. {
  638. long ulPropTag;
  639. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &ulPropTag) == FAILURE) return;
  640. RETURN_LONG(PROP_TYPE(ulPropTag));
  641. }
  642. /*
  643. * PHP casts a variable to a signed long before bitshifting. So a C++ function
  644. * is used.
  645. */
  646. ZEND_FUNCTION(mapi_prop_id)
  647. {
  648. long ulPropTag;
  649. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &ulPropTag) == FAILURE) return;
  650. RETURN_LONG(PROP_ID(ulPropTag));
  651. }
  652. /**
  653. * Checks if the severity of a errorCode is set to Fail
  654. *
  655. *
  656. */
  657. ZEND_FUNCTION(mapi_is_error)
  658. {
  659. long errorcode;
  660. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &errorcode) == FAILURE) return;
  661. RETURN_BOOL(IS_ERROR(errorcode));
  662. }
  663. /*
  664. * Makes a mapi SCODE
  665. * input:
  666. * long severity
  667. * long code
  668. *
  669. */
  670. ZEND_FUNCTION(mapi_make_scode)
  671. {
  672. long sev, code;
  673. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &sev, &code) == FAILURE) return;
  674. /*
  675. * sev has two possible values: 0 for a warning, 1 for an error
  676. * err is the error code for the specific error.
  677. */
  678. RETURN_LONG(MAKE_MAPI_SCODE(sev & 1, FACILITY_ITF, code));
  679. }
  680. /*
  681. * PHP casts a variable to a signed long before bitshifting. So a C++ function
  682. * is used.
  683. */
  684. ZEND_FUNCTION(mapi_prop_tag)
  685. {
  686. long ulPropID, ulPropType;
  687. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &ulPropType, &ulPropID) == FAILURE) return;
  688. // PHP uses variable type 'long' internally. If a number in a string as key is used in add_assoc_*(),
  689. // it is re-interpreted a a number when it's smaller than LONG_MAX.
  690. // however, LONG_MAX is 2147483647L on 32-bit systems, but 9223372036854775807L on 64-bit.
  691. // this make named props (0x80000000+) fit in the 'number' description, and so this breaks on 64-bit systems
  692. // .. well, it un-breaks on 64-bit .. so we cast the unsigned proptag to a signed number here, so
  693. // the compares within .php files can be correctly performed, so named props work.
  694. // maybe we need to rewrite this system a bit, so proptags are always a string, and never interpreted
  695. // eg. by prepending the assoc keys with 'PROPTAG' or something...
  696. RETURN_LONG((LONG)PROP_TAG(ulPropType, ulPropID));
  697. }
  698. ZEND_FUNCTION(mapi_createoneoff)
  699. {
  700. PMEASURE_FUNC;
  701. LOG_BEGIN();
  702. // params
  703. char *szDisplayName = NULL;
  704. char *szType = NULL;
  705. char *szEmailAddress = NULL;
  706. unsigned int ulDisplayNameLen=0, ulTypeLen=0, ulEmailAddressLen=0;
  707. long ulFlags = MAPI_SEND_NO_RICH_INFO;
  708. // return value
  709. memory_ptr<ENTRYID> lpEntryID;
  710. ULONG cbEntryID = 0;
  711. // local
  712. wstring name;
  713. wstring type;
  714. wstring email;
  715. RETVAL_FALSE;
  716. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  717. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss|l",
  718. &szDisplayName, &ulDisplayNameLen,
  719. &szType, &ulTypeLen,
  720. &szEmailAddress, &ulEmailAddressLen, &ulFlags) == FAILURE) return;
  721. MAPI_G(hr) = TryConvert(szDisplayName, name);
  722. if(MAPI_G(hr) != hrSuccess) {
  723. php_error_docref(NULL TSRMLS_CC, E_WARNING, "CreateOneOff name conversion failed");
  724. goto exit;
  725. }
  726. MAPI_G(hr) = TryConvert(szType, type);
  727. if(MAPI_G(hr) != hrSuccess) {
  728. php_error_docref(NULL TSRMLS_CC, E_WARNING, "CreateOneOff type conversion failed");
  729. goto exit;
  730. }
  731. MAPI_G(hr) = TryConvert(szEmailAddress, email);
  732. if(MAPI_G(hr) != hrSuccess) {
  733. php_error_docref(NULL TSRMLS_CC, E_WARNING, "CreateOneOff address conversion failed");
  734. goto exit;
  735. }
  736. MAPI_G(hr) = ECCreateOneOff((LPTSTR)name.c_str(), (LPTSTR)type.c_str(), (LPTSTR)email.c_str(), MAPI_UNICODE | ulFlags, &cbEntryID, &~lpEntryID);
  737. if(MAPI_G(hr) != hrSuccess) {
  738. php_error_docref(NULL TSRMLS_CC, E_WARNING, "CreateOneOff failed");
  739. goto exit;
  740. }
  741. RETVAL_STRINGL(reinterpret_cast<const char *>(lpEntryID.get()), cbEntryID, 1);
  742. exit:
  743. // using RETVAL_* not RETURN_*, otherwise php will instantly return itself, and we won't be able to free...
  744. LOG_END();
  745. THROW_ON_ERROR();
  746. }
  747. ZEND_FUNCTION(mapi_parseoneoff)
  748. {
  749. PMEASURE_FUNC;
  750. LOG_BEGIN();
  751. // params
  752. LPENTRYID lpEntryID = NULL;
  753. ULONG cbEntryID = 0;
  754. // return value
  755. utf8string strDisplayName;
  756. utf8string strType;
  757. utf8string strAddress;
  758. std::wstring wstrDisplayName;
  759. std::wstring wstrType;
  760. std::wstring wstrAddress;
  761. RETVAL_FALSE;
  762. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  763. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &lpEntryID, &cbEntryID) == FAILURE) return;
  764. MAPI_G(hr) = ECParseOneOff(lpEntryID, cbEntryID, wstrDisplayName, wstrType, wstrAddress);
  765. if(MAPI_G(hr) != hrSuccess) {
  766. php_error_docref(NULL TSRMLS_CC, E_WARNING, "ParseOneOff failed");
  767. goto exit;
  768. }
  769. array_init(return_value);
  770. strDisplayName = convert_to<utf8string>(wstrDisplayName);
  771. strType = convert_to<utf8string>(wstrType);
  772. strAddress = convert_to<utf8string>(wstrAddress);
  773. add_assoc_string(return_value, "name", (char*)strDisplayName.c_str(), 1);
  774. add_assoc_string(return_value, "type", (char*)strType.c_str(), 1);
  775. add_assoc_string(return_value, "address", (char*)strAddress.c_str(), 1);
  776. exit:
  777. LOG_END();
  778. THROW_ON_ERROR();
  779. }
  780. /*
  781. * How sessions and stores work:
  782. * - mapi_logon_zarafa() creates a session and returns this
  783. * - mapi_getmsgstorestable() to get the entryid of the default and public store
  784. * - mapi_openmsgstore() to open the default user store + public store
  785. * - mapi_msgstore_createentryid() retuns a store entryid of requested user
  786. * - store entryid can be used with mapi_openmsgstore() to open
  787. *
  788. * Removed, how it did work in the far past:
  789. * - mapi_openmsgstore_zarafa() creates a session, opens the user's store, and the public
  790. * and returns these store pointers in an array.
  791. * - mapi_msgstore_createentryid() is used to call Store->CreateStoreEntryID()
  792. * - mapi_openmsgstore_zarafa_other() with the prev acquired entryid opens the store of another user,
  793. * - mapi_openmsgstore_zarafa_other() is therefor called with the current user id and password (and maybe the server) as well!
  794. * Only with this info we can find the session again, to get the IMAPISession, and open another store.
  795. */
  796. ZEND_FUNCTION(mapi_logon_zarafa)
  797. {
  798. PMEASURE_FUNC;
  799. LOG_BEGIN();
  800. // params
  801. char *username = NULL;
  802. int username_len = 0;
  803. char *password = NULL;
  804. int password_len = 0;
  805. const char *server = NULL;
  806. int server_len = 0;
  807. const char *sslcert = "";
  808. int sslcert_len = 0;
  809. const char *sslpass = "";
  810. int sslpass_len = 0;
  811. const char *wa_version = "";
  812. int wa_version_len = 0;
  813. const char *misc_version = "";
  814. int misc_version_len = 0;
  815. long ulFlags = EC_PROFILE_FLAGS_NO_NOTIFICATIONS;
  816. // return value
  817. object_ptr<IMAPISession> lpMAPISession;
  818. // local
  819. ULONG ulProfNum = rand_mt();
  820. char szProfName[MAX_PATH];
  821. SPropValue sPropOur[8];
  822. RETVAL_FALSE;
  823. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  824. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|ssslss",
  825. &username, &username_len, &password, &password_len, &server, &server_len,
  826. &sslcert, &sslcert_len, &sslpass, &sslpass_len, &ulFlags,
  827. &wa_version, &wa_version_len, &misc_version, &misc_version_len) == FAILURE) return;
  828. if (!server) {
  829. server = "http://localhost:236/";
  830. server_len = strlen(server);
  831. }
  832. snprintf(szProfName, MAX_PATH-1, "www-profile%010u", ulProfNum);
  833. sPropOur[0].ulPropTag = PR_EC_PATH;
  834. sPropOur[0].Value.lpszA = const_cast<char *>(server);
  835. sPropOur[1].ulPropTag = PR_EC_USERNAME_A;
  836. sPropOur[1].Value.lpszA = const_cast<char *>(username);
  837. sPropOur[2].ulPropTag = PR_EC_USERPASSWORD_A;
  838. sPropOur[2].Value.lpszA = const_cast<char *>(password);
  839. sPropOur[3].ulPropTag = PR_EC_FLAGS;
  840. sPropOur[3].Value.ul = ulFlags;
  841. // unused if PR_EC_PATH is not https
  842. sPropOur[4].ulPropTag = PR_EC_SSLKEY_FILE;
  843. sPropOur[4].Value.lpszA = const_cast<char *>(sslcert);
  844. sPropOur[5].ulPropTag = PR_EC_SSLKEY_PASS;
  845. sPropOur[5].Value.lpszA = const_cast<char *>(sslpass);
  846. sPropOur[6].ulPropTag = PR_EC_STATS_SESSION_CLIENT_APPLICATION_VERSION;
  847. sPropOur[6].Value.lpszA = const_cast<char *>(wa_version);
  848. sPropOur[7].ulPropTag = PR_EC_STATS_SESSION_CLIENT_APPLICATION_MISC;
  849. sPropOur[7].Value.lpszA = const_cast<char *>(misc_version);
  850. MAPI_G(hr) = mapi_util_createprof(szProfName, "ZARAFA6", 8, sPropOur);
  851. if (MAPI_G(hr) != hrSuccess) {
  852. php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", mapi_util_getlasterror().c_str());
  853. goto exit; // error already displayed in mapi_util_createprof
  854. }
  855. // Logon to our new profile
  856. MAPI_G(hr) = MAPILogonEx(0, reinterpret_cast<LPTSTR>(const_cast<char *>(szProfName)),
  857. reinterpret_cast<LPTSTR>(const_cast<char *>("")),
  858. MAPI_EXTENDED | MAPI_TIMEOUT_SHORT | MAPI_NEW_SESSION,
  859. &~lpMAPISession);
  860. if (MAPI_G(hr) != hrSuccess) {
  861. mapi_util_deleteprof(szProfName);
  862. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to logon to profile");
  863. goto exit;
  864. }
  865. // Delete the profile (it will be deleted when we close our session)
  866. MAPI_G(hr) = mapi_util_deleteprof(szProfName);
  867. if (MAPI_G(hr) != hrSuccess) {
  868. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to delete profile");
  869. goto exit;
  870. }
  871. ZEND_REGISTER_RESOURCE(return_value, lpMAPISession.release(), le_mapi_session);
  872. exit:
  873. LOG_END();
  874. THROW_ON_ERROR();
  875. }
  876. /**
  877. * mapi_openentry
  878. * Opens the msgstore from the session
  879. * @param Resource IMAPISession
  880. * @param String EntryID
  881. */
  882. ZEND_FUNCTION(mapi_openentry)
  883. {
  884. PMEASURE_FUNC;
  885. LOG_BEGIN();
  886. // params
  887. zval *res;
  888. IMAPISession *lpSession = NULL;
  889. ULONG cbEntryID = 0;
  890. LPENTRYID lpEntryID = NULL;
  891. long ulFlags = MAPI_BEST_ACCESS;
  892. // return value
  893. LPUNKNOWN lpUnknown; // either folder or message
  894. // local
  895. ULONG ulObjType;
  896. RETVAL_FALSE;
  897. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  898. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|sl", &res, &lpEntryID, &cbEntryID, &ulFlags) == FAILURE) return;
  899. ZEND_FETCH_RESOURCE_C(lpSession, IMAPISession *, &res, -1, name_mapi_session, le_mapi_session);
  900. MAPI_G(hr) = lpSession->OpenEntry(cbEntryID, lpEntryID, NULL, ulFlags, &ulObjType, &lpUnknown);
  901. if (FAILED(MAPI_G(hr)))
  902. goto exit;
  903. if (ulObjType == MAPI_FOLDER) {
  904. UOBJ_REGISTER_RESOURCE(return_value, lpUnknown, le_mapi_folder);
  905. }
  906. else if(ulObjType == MAPI_MESSAGE) {
  907. UOBJ_REGISTER_RESOURCE(return_value, lpUnknown, le_mapi_message);
  908. } else {
  909. if (lpUnknown)
  910. lpUnknown->Release();
  911. php_error_docref(NULL TSRMLS_CC, E_WARNING, "EntryID is not a folder or a message.");
  912. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  913. goto exit;
  914. }
  915. exit:
  916. LOG_END();
  917. THROW_ON_ERROR();
  918. }
  919. // This function cannot be used, since you currently can't create profiles directly in php
  920. ZEND_FUNCTION(mapi_logon)
  921. {
  922. PMEASURE_FUNC;
  923. LOG_BEGIN();
  924. // params
  925. const char *profilename = "";
  926. const char *profilepassword = "";
  927. int profilename_len = 0, profilepassword_len = 0;
  928. // return value
  929. LPMAPISESSION lpMAPISession = NULL;
  930. // local
  931. RETVAL_FALSE;
  932. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  933. if (ZEND_NUM_ARGS() > 0 &&
  934. zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
  935. &profilename, &profilename_len, &profilepassword, &profilepassword_len) == FAILURE)
  936. return;
  937. /*
  938. * MAPI_LOGON_UI will show a dialog when a profilename is not
  939. * found or a password is not correct, without it the dialog will never appear => that's what we want
  940. * MAPI_USE_DEFAULT |
  941. */
  942. MAPI_G(hr) = MAPILogonEx(0, (LPTSTR)profilename, (LPTSTR)profilepassword, MAPI_USE_DEFAULT | MAPI_EXTENDED | MAPI_TIMEOUT_SHORT | MAPI_NEW_SESSION, &lpMAPISession);
  943. if(MAPI_G(hr) != hrSuccess)
  944. goto exit;
  945. ZEND_REGISTER_RESOURCE(return_value, lpMAPISession, le_mapi_session);
  946. exit:
  947. LOG_END();
  948. THROW_ON_ERROR();
  949. }
  950. // IMAPISession::OpenAddressBook()
  951. // must have valid session
  952. ZEND_FUNCTION(mapi_openaddressbook)
  953. {
  954. PMEASURE_FUNC;
  955. LOG_BEGIN();
  956. // params
  957. zval *res;
  958. IMAPISession *lpSession = NULL;
  959. // return value
  960. LPADRBOOK lpAddrBook;
  961. // local
  962. RETVAL_FALSE;
  963. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  964. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) return;
  965. ZEND_FETCH_RESOURCE_C(lpSession, IMAPISession*, &res, -1, name_mapi_session, le_mapi_session);
  966. MAPI_G(hr) = lpSession->OpenAddressBook(0, NULL, AB_NO_DIALOG, &lpAddrBook);
  967. if (MAPI_G(hr) != hrSuccess)
  968. goto exit;
  969. UOBJ_REGISTER_RESOURCE(return_value, lpAddrBook, le_mapi_addrbook);
  970. exit:
  971. LOG_END();
  972. THROW_ON_ERROR();
  973. }
  974. ZEND_FUNCTION(mapi_ab_openentry) {
  975. PMEASURE_FUNC;
  976. LOG_BEGIN();
  977. // params
  978. zval *res;
  979. LPADRBOOK lpAddrBook = NULL;
  980. ULONG cbEntryID = 0;
  981. LPENTRYID lpEntryID = NULL;
  982. long ulFlags = 0; //MAPI_BEST_ACCESS;
  983. // return value
  984. ULONG ulObjType;
  985. IUnknown *lpUnknown = NULL;
  986. RETVAL_FALSE;
  987. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  988. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|sl", &res, &lpEntryID, &cbEntryID, &ulFlags) == FAILURE) return;
  989. ZEND_FETCH_RESOURCE_C(lpAddrBook, LPADRBOOK, &res, -1, name_mapi_addrbook, le_mapi_addrbook);
  990. MAPI_G(hr) = lpAddrBook->OpenEntry(cbEntryID, lpEntryID, NULL, ulFlags, &ulObjType, &lpUnknown);
  991. if (MAPI_G(hr) != hrSuccess)
  992. goto exit;
  993. switch (ulObjType) {
  994. case MAPI_MAILUSER:
  995. UOBJ_REGISTER_RESOURCE(return_value, lpUnknown, le_mapi_mailuser);
  996. break;
  997. case MAPI_DISTLIST:
  998. UOBJ_REGISTER_RESOURCE(return_value, lpUnknown, le_mapi_distlist);
  999. break;
  1000. case MAPI_ABCONT:
  1001. UOBJ_REGISTER_RESOURCE(return_value, lpUnknown, le_mapi_abcont);
  1002. break;
  1003. default:
  1004. if (lpUnknown)
  1005. lpUnknown->Release();
  1006. php_error_docref(NULL TSRMLS_CC, E_WARNING, "EntryID is not an AddressBook item");
  1007. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1008. goto exit;
  1009. }
  1010. exit:
  1011. LOG_END();
  1012. THROW_ON_ERROR();
  1013. }
  1014. ZEND_FUNCTION(mapi_ab_resolvename) {
  1015. PMEASURE_FUNC;
  1016. LOG_BEGIN();
  1017. // params
  1018. zval *res;
  1019. LPADRBOOK lpAddrBook = NULL;
  1020. zval *array;
  1021. zval *rowset;
  1022. long ulFlags = 0;
  1023. // return value
  1024. // local
  1025. adrlist_ptr lpAList;
  1026. RETVAL_FALSE;
  1027. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1028. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra|l", &res, &array, &ulFlags) == FAILURE) return;
  1029. ZEND_FETCH_RESOURCE_C(lpAddrBook, LPADRBOOK, &res, -1, name_mapi_addrbook, le_mapi_addrbook);
  1030. MAPI_G(hr) = PHPArraytoAdrList(array, nullptr, &~lpAList TSRMLS_CC);
  1031. if (MAPI_G(hr) != hrSuccess)
  1032. goto exit;
  1033. MAPI_G(hr) = lpAddrBook->ResolveName(0, ulFlags, NULL, lpAList);
  1034. switch (MAPI_G(hr)) {
  1035. case hrSuccess:
  1036. // parse back lpAList and return as array
  1037. RowSettoPHPArray(reinterpret_cast<SRowSet *>(lpAList.get()), &rowset TSRMLS_CC); // binary compatible
  1038. RETVAL_ZVAL(rowset, 0, 0);
  1039. FREE_ZVAL(rowset);
  1040. break;
  1041. case MAPI_E_AMBIGUOUS_RECIP:
  1042. case MAPI_E_NOT_FOUND:
  1043. default:
  1044. break;
  1045. };
  1046. exit:
  1047. LOG_END();
  1048. THROW_ON_ERROR();
  1049. }
  1050. ZEND_FUNCTION(mapi_ab_getdefaultdir) {
  1051. PMEASURE_FUNC;
  1052. LOG_BEGIN();
  1053. // params
  1054. zval *res;
  1055. LPADRBOOK lpAddrBook = NULL;
  1056. // return value
  1057. memory_ptr<ENTRYID> lpEntryID;
  1058. ULONG cbEntryID = 0;
  1059. RETVAL_FALSE;
  1060. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1061. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) return;
  1062. ZEND_FETCH_RESOURCE_C(lpAddrBook, LPADRBOOK, &res, -1, name_mapi_addrbook, le_mapi_addrbook);
  1063. MAPI_G(hr) = lpAddrBook->GetDefaultDir(&cbEntryID, &~lpEntryID);
  1064. if (MAPI_G(hr) != hrSuccess) {
  1065. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed GetDefaultDir of the addressbook. Error code: 0x%08X", MAPI_G(hr));
  1066. goto exit;
  1067. }
  1068. RETVAL_STRINGL(reinterpret_cast<const char *>(lpEntryID.get()), cbEntryID, 1);
  1069. exit:
  1070. LOG_END();
  1071. THROW_ON_ERROR();
  1072. }
  1073. /**
  1074. * mapi_getstores
  1075. * Gets the table with the messagestores available
  1076. *
  1077. */
  1078. ZEND_FUNCTION(mapi_getmsgstorestable)
  1079. {
  1080. PMEASURE_FUNC;
  1081. LOG_BEGIN();
  1082. // params
  1083. zval *res = NULL;
  1084. IMAPISession *lpSession = NULL;
  1085. // return value
  1086. LPMAPITABLE lpTable = NULL;
  1087. RETVAL_FALSE;
  1088. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1089. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) return;
  1090. ZEND_FETCH_RESOURCE_C(lpSession, IMAPISession *, &res, -1, name_mapi_session, le_mapi_session);
  1091. MAPI_G(hr) = lpSession->GetMsgStoresTable(0, &lpTable);
  1092. if (FAILED(MAPI_G(hr))) {
  1093. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to fetch the message store table: 0x%08X", MAPI_G(hr));
  1094. goto exit;
  1095. }
  1096. UOBJ_REGISTER_RESOURCE(return_value, lpTable, le_mapi_table);
  1097. exit:
  1098. LOG_END();
  1099. THROW_ON_ERROR();
  1100. }
  1101. /**
  1102. * mapi_openmsgstore
  1103. * Opens the messagestore for the entryid
  1104. * @param String with the entryid
  1105. * @return RowSet with messages
  1106. */
  1107. ZEND_FUNCTION(mapi_openmsgstore)
  1108. {
  1109. PMEASURE_FUNC;
  1110. LOG_BEGIN();
  1111. // params
  1112. ULONG cbEntryID = 0;
  1113. LPENTRYID lpEntryID = NULL;
  1114. zval *res = NULL;
  1115. IMAPISession * lpSession = NULL;
  1116. // return value
  1117. LPMDB pMDB = NULL;
  1118. RETVAL_FALSE;
  1119. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1120. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs",
  1121. &res, (char *)&lpEntryID, &cbEntryID) == FAILURE) return;
  1122. ZEND_FETCH_RESOURCE_C(lpSession, IMAPISession *, &res, -1, name_mapi_session, le_mapi_session);
  1123. MAPI_G(hr) = lpSession->OpenMsgStore(0, cbEntryID, lpEntryID, 0, MAPI_BEST_ACCESS | MDB_NO_DIALOG, &pMDB);
  1124. if (FAILED(MAPI_G(hr))) {
  1125. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open the messagestore: 0x%08X", MAPI_G(hr));
  1126. goto exit;
  1127. }
  1128. UOBJ_REGISTER_RESOURCE(return_value, pMDB, le_mapi_msgstore);
  1129. exit:
  1130. LOG_END();
  1131. THROW_ON_ERROR();
  1132. }
  1133. /**
  1134. * Open the profile section of given guid, and returns the php-usable IMAPIProp object
  1135. *
  1136. * @param[in] Resource mapi session
  1137. * @param[in] String mapi uid of profile section
  1138. *
  1139. * @return IMAPIProp interface of IProfSect object
  1140. */
  1141. ZEND_FUNCTION(mapi_openprofilesection)
  1142. {
  1143. PMEASURE_FUNC;
  1144. LOG_BEGIN();
  1145. // params
  1146. zval *res;
  1147. IMAPISession *lpSession = NULL;
  1148. int uidlen;
  1149. LPMAPIUID lpUID = NULL;
  1150. // return value
  1151. IMAPIProp *lpProfSectProp = NULL;
  1152. // local
  1153. RETVAL_FALSE;
  1154. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1155. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &lpUID, &uidlen) == FAILURE) return;
  1156. if (uidlen != sizeof(MAPIUID))
  1157. goto exit;
  1158. ZEND_FETCH_RESOURCE_C(lpSession, IMAPISession*, &res, -1, name_mapi_session, le_mapi_session);
  1159. // yes, you can request any compatible interface, but the return pointer is LPPROFSECT .. ohwell.
  1160. MAPI_G(hr) = lpSession->OpenProfileSection(lpUID, &IID_IMAPIProp, 0, (LPPROFSECT*)&lpProfSectProp);
  1161. if (MAPI_G(hr) != hrSuccess)
  1162. goto exit;
  1163. UOBJ_REGISTER_RESOURCE(return_value, lpProfSectProp, le_mapi_property);
  1164. exit:
  1165. LOG_END();
  1166. THROW_ON_ERROR();
  1167. }
  1168. /**
  1169. * mapi_folder_gethierarchtable
  1170. * Opens the hierarchytable from a folder
  1171. * @param Resource mapifolder
  1172. *
  1173. */
  1174. ZEND_FUNCTION(mapi_folder_gethierarchytable)
  1175. {
  1176. PMEASURE_FUNC;
  1177. LOG_BEGIN();
  1178. // params
  1179. zval *res;
  1180. LPMAPIFOLDER pFolder = NULL;
  1181. long ulFlags = 0;
  1182. // return value
  1183. LPMAPITABLE lpTable = NULL;
  1184. int type = -1;
  1185. RETVAL_FALSE;
  1186. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1187. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &res, &ulFlags) == FAILURE) return;
  1188. zend_list_find(res->value.lval, &type);
  1189. if(type == le_mapi_folder) {
  1190. ZEND_FETCH_RESOURCE_C(pFolder, LPMAPIFOLDER, &res, -1, name_mapi_folder, le_mapi_folder);
  1191. } else if (type == le_mapi_abcont) {
  1192. ZEND_FETCH_RESOURCE_C(pFolder, LPMAPIFOLDER, &res, -1, name_mapi_abcont, le_mapi_abcont);
  1193. } else if (type == le_mapi_distlist) {
  1194. ZEND_FETCH_RESOURCE_C(pFolder, LPMAPIFOLDER, &res, -1, name_mapi_distlist, le_mapi_distlist);
  1195. } else {
  1196. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Resource is not a valid IMAPIFolder or derivative");
  1197. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1198. goto exit;
  1199. }
  1200. MAPI_G(hr) = pFolder->GetHierarchyTable(ulFlags, &lpTable);
  1201. // return the returncode
  1202. if (FAILED(MAPI_G(hr)))
  1203. goto exit;
  1204. UOBJ_REGISTER_RESOURCE(return_value, lpTable, le_mapi_table);
  1205. exit:
  1206. LOG_END();
  1207. THROW_ON_ERROR();
  1208. }
  1209. /**
  1210. * mapi_msgstore_getcontentstable
  1211. *
  1212. * @param Resource MAPIMSGStore
  1213. * @param long Flags
  1214. * @return MAPIFolder
  1215. */
  1216. ZEND_FUNCTION(mapi_folder_getcontentstable)
  1217. {
  1218. PMEASURE_FUNC;
  1219. LOG_BEGIN();
  1220. // params
  1221. zval *res = NULL;
  1222. LPMAPICONTAINER pContainer = NULL;
  1223. long ulFlags = 0;
  1224. // return value
  1225. LPMAPITABLE pTable = NULL;
  1226. // local
  1227. int type = -1;
  1228. RETVAL_FALSE;
  1229. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1230. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &res, &ulFlags) == FAILURE) return;
  1231. zend_list_find(res->value.lval, &type);
  1232. if(type == le_mapi_folder) {
  1233. ZEND_FETCH_RESOURCE_C(pContainer, LPMAPICONTAINER, &res, -1, name_mapi_folder, le_mapi_folder);
  1234. } else if (type == le_mapi_abcont) {
  1235. ZEND_FETCH_RESOURCE_C(pContainer, LPMAPICONTAINER, &res, -1, name_mapi_abcont, le_mapi_abcont);
  1236. } else if( type == le_mapi_distlist) {
  1237. ZEND_FETCH_RESOURCE_C(pContainer, LPMAPICONTAINER, &res, -1, name_mapi_distlist, le_mapi_distlist);
  1238. } else {
  1239. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Resource is not a valid IMAPIContainer or derivative");
  1240. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1241. goto exit;
  1242. }
  1243. MAPI_G(hr) = pContainer->GetContentsTable(ulFlags, &pTable);
  1244. if (FAILED(MAPI_G(hr)))
  1245. goto exit;
  1246. UOBJ_REGISTER_RESOURCE(return_value, pTable, le_mapi_table);
  1247. exit:
  1248. LOG_END();
  1249. THROW_ON_ERROR();
  1250. }
  1251. /**
  1252. * mapi_folder_createmessage
  1253. *
  1254. *
  1255. */
  1256. ZEND_FUNCTION(mapi_folder_createmessage)
  1257. {
  1258. PMEASURE_FUNC;
  1259. LOG_BEGIN();
  1260. // params
  1261. zval * res;
  1262. LPMAPIFOLDER pFolder = NULL;
  1263. long ulFlags = 0;
  1264. // return value
  1265. LPMESSAGE pMessage;
  1266. RETVAL_FALSE;
  1267. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1268. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &res, &ulFlags) == FAILURE) return;
  1269. ZEND_FETCH_RESOURCE_C(pFolder, LPMAPIFOLDER, &res, -1, name_mapi_folder, le_mapi_folder);
  1270. MAPI_G(hr) = pFolder->CreateMessage(NULL, ulFlags, &pMessage);
  1271. if (FAILED(MAPI_G(hr)))
  1272. goto exit;
  1273. UOBJ_REGISTER_RESOURCE(return_value, pMessage, le_mapi_message);
  1274. exit:
  1275. LOG_END();
  1276. THROW_ON_ERROR();
  1277. }
  1278. /**
  1279. * mapi_folder_deletemessage
  1280. *
  1281. *
  1282. */
  1283. ZEND_FUNCTION(mapi_folder_deletemessages)
  1284. {
  1285. PMEASURE_FUNC;
  1286. LOG_BEGIN();
  1287. // params
  1288. LPMAPIFOLDER pFolder = NULL;
  1289. zval *res = NULL;
  1290. zval *entryid_array = NULL;
  1291. long ulFlags = 0;
  1292. // local
  1293. memory_ptr<ENTRYLIST> lpEntryList;
  1294. RETVAL_FALSE;
  1295. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1296. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra|l", &res, &entryid_array, &ulFlags) == FAILURE) return;
  1297. ZEND_FETCH_RESOURCE_C(pFolder, LPMAPIFOLDER, &res, -1, name_mapi_folder, le_mapi_folder);
  1298. MAPI_G(hr) = PHPArraytoSBinaryArray(entryid_array, NULL, &~lpEntryList TSRMLS_CC);
  1299. if(MAPI_G(hr) != hrSuccess) {
  1300. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad message list");
  1301. goto exit;
  1302. }
  1303. MAPI_G(hr) = pFolder->DeleteMessages(lpEntryList, 0, NULL, ulFlags);
  1304. if(MAPI_G(hr) != hrSuccess)
  1305. goto exit;
  1306. RETVAL_TRUE;
  1307. exit:
  1308. LOG_END();
  1309. THROW_ON_ERROR();
  1310. }
  1311. /**
  1312. * Function to copy message from the source folder to the destination folder. A folder must be opened with openentry.
  1313. *
  1314. * @param SourceFolder, Message List, DestinationFolder, flags (optional)
  1315. */
  1316. ZEND_FUNCTION(mapi_folder_copymessages)
  1317. {
  1318. PMEASURE_FUNC;
  1319. LOG_BEGIN();
  1320. // params
  1321. LPMAPIFOLDER lpSrcFolder = NULL, lpDestFolder = NULL;
  1322. zval *srcFolder = NULL, *destFolder = NULL;
  1323. zval *msgArray = NULL;
  1324. long flags = 0;
  1325. // local
  1326. memory_ptr<ENTRYLIST> lpEntryList;
  1327. RETVAL_FALSE;
  1328. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1329. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rar|l", &srcFolder, &msgArray, &destFolder, &flags) == FAILURE) return;
  1330. ZEND_FETCH_RESOURCE_C(lpSrcFolder, LPMAPIFOLDER, &srcFolder, -1, name_mapi_folder, le_mapi_folder);
  1331. ZEND_FETCH_RESOURCE_C(lpDestFolder, LPMAPIFOLDER, &destFolder, -1, name_mapi_folder, le_mapi_folder);
  1332. MAPI_G(hr) = PHPArraytoSBinaryArray(msgArray, NULL, &~lpEntryList TSRMLS_CC);
  1333. if(MAPI_G(hr) != hrSuccess) {
  1334. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad message list");
  1335. goto exit;
  1336. }
  1337. MAPI_G(hr) = lpSrcFolder->CopyMessages(lpEntryList, NULL, lpDestFolder, 0, NULL, flags);
  1338. if(MAPI_G(hr) != hrSuccess)
  1339. goto exit;
  1340. RETVAL_TRUE;
  1341. exit:
  1342. LOG_END();
  1343. THROW_ON_ERROR();
  1344. }
  1345. /*
  1346. * Function to set the read flags for a folder.
  1347. *
  1348. *
  1349. */
  1350. ZEND_FUNCTION(mapi_folder_setreadflags)
  1351. {
  1352. PMEASURE_FUNC;
  1353. LOG_BEGIN();
  1354. // params
  1355. zval *res = NULL, *entryArray = NULL;
  1356. long flags = 0;
  1357. // local
  1358. LPMAPIFOLDER lpFolder = NULL;
  1359. memory_ptr<ENTRYLIST> lpEntryList;
  1360. RETVAL_FALSE;
  1361. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1362. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra|l", &res, &entryArray, &flags) == FAILURE) return;
  1363. ZEND_FETCH_RESOURCE_C(lpFolder, LPMAPIFOLDER, &res, -1, name_mapi_folder, le_mapi_folder);
  1364. MAPI_G(hr) = PHPArraytoSBinaryArray(entryArray, NULL, &~lpEntryList TSRMLS_CC);
  1365. if(MAPI_G(hr) != hrSuccess) {
  1366. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad message list");
  1367. goto exit;
  1368. }
  1369. // Special case: if an empty array was passed, treat it as NULL
  1370. if(lpEntryList->cValues != 0)
  1371. MAPI_G(hr) = lpFolder->SetReadFlags(lpEntryList, 0, NULL, flags);
  1372. else
  1373. MAPI_G(hr) = lpFolder->SetReadFlags(NULL, 0, NULL, flags);
  1374. if(MAPI_G(hr) != hrSuccess)
  1375. goto exit;
  1376. RETVAL_TRUE;
  1377. exit:
  1378. LOG_END();
  1379. THROW_ON_ERROR();
  1380. }
  1381. ZEND_FUNCTION(mapi_folder_createfolder) {
  1382. PMEASURE_FUNC;
  1383. LOG_BEGIN();
  1384. // params
  1385. LPMAPIFOLDER lpSrcFolder = NULL;
  1386. zval *srcFolder = NULL;
  1387. long folderType = FOLDER_GENERIC, ulFlags = 0;
  1388. const char *lpszFolderName = "", *lpszFolderComment = "";
  1389. int FolderNameLen = 0, FolderCommentLen = 0;
  1390. // return value
  1391. LPMAPIFOLDER lpNewFolder = NULL;
  1392. RETVAL_FALSE;
  1393. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1394. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|sll", &srcFolder, &lpszFolderName, &FolderNameLen, &lpszFolderComment, &FolderCommentLen, &ulFlags, &folderType) == FAILURE) return;
  1395. if (FolderNameLen == 0) {
  1396. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Foldername cannot be empty");
  1397. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1398. goto exit;
  1399. }
  1400. if (FolderCommentLen == 0) {
  1401. lpszFolderComment = NULL;
  1402. }
  1403. ZEND_FETCH_RESOURCE_C(lpSrcFolder, LPMAPIFOLDER, &srcFolder, -1, name_mapi_folder, le_mapi_folder);
  1404. MAPI_G(hr) = lpSrcFolder->CreateFolder(folderType, (LPTSTR)lpszFolderName, (LPTSTR)lpszFolderComment, NULL, ulFlags & ~MAPI_UNICODE, &lpNewFolder);
  1405. if (FAILED(MAPI_G(hr)))
  1406. goto exit;
  1407. UOBJ_REGISTER_RESOURCE(return_value, lpNewFolder, le_mapi_folder);
  1408. exit:
  1409. LOG_END();
  1410. THROW_ON_ERROR();
  1411. }
  1412. ZEND_FUNCTION(mapi_folder_deletefolder)
  1413. {
  1414. PMEASURE_FUNC;
  1415. LOG_BEGIN();
  1416. // params
  1417. ENTRYID *lpEntryID = NULL;
  1418. ULONG cbEntryID = 0;
  1419. long ulFlags = 0;
  1420. zval *res = NULL;
  1421. LPMAPIFOLDER lpFolder = NULL;
  1422. RETVAL_FALSE;
  1423. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1424. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|l", &res, &lpEntryID, &cbEntryID, &ulFlags) == FAILURE) return;
  1425. ZEND_FETCH_RESOURCE_C(lpFolder, LPMAPIFOLDER, &res, -1, name_mapi_folder, le_mapi_folder);
  1426. MAPI_G(hr) = lpFolder->DeleteFolder(cbEntryID, lpEntryID, 0, NULL, ulFlags);
  1427. if (FAILED(MAPI_G(hr)))
  1428. goto exit;
  1429. RETVAL_TRUE;
  1430. exit:
  1431. LOG_END();
  1432. THROW_ON_ERROR();
  1433. }
  1434. ZEND_FUNCTION(mapi_folder_emptyfolder)
  1435. {
  1436. PMEASURE_FUNC;
  1437. LOG_BEGIN();
  1438. // params
  1439. zval *res;
  1440. LPMAPIFOLDER lpFolder = NULL;
  1441. long ulFlags = 0;
  1442. RETVAL_FALSE;
  1443. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1444. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &res, &ulFlags) == FAILURE) return;
  1445. ZEND_FETCH_RESOURCE_C(lpFolder, LPMAPIFOLDER, &res, -1, name_mapi_folder, le_mapi_folder);
  1446. MAPI_G(hr) = lpFolder->EmptyFolder(0, NULL, ulFlags);
  1447. if (FAILED(MAPI_G(hr)))
  1448. goto exit;
  1449. RETVAL_TRUE;
  1450. exit:
  1451. LOG_END();
  1452. THROW_ON_ERROR();
  1453. }
  1454. /**
  1455. * Function that copies (or moves) a folder to another folder.
  1456. *
  1457. *
  1458. */
  1459. ZEND_FUNCTION(mapi_folder_copyfolder)
  1460. {
  1461. PMEASURE_FUNC;
  1462. LOG_BEGIN();
  1463. // params
  1464. zval *zvalSrcFolder, *zvalDestFolder;
  1465. LPMAPIFOLDER lpSrcFolder = NULL, lpDestFolder = NULL;
  1466. ENTRYID *lpEntryID = NULL;
  1467. ULONG cbEntryID = 0;
  1468. long ulFlags = 0;
  1469. LPTSTR lpszNewFolderName = NULL;
  1470. int cbNewFolderNameLen = 0;
  1471. RETVAL_FALSE;
  1472. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1473. // Params: (SrcFolder, entryid, DestFolder, (opt) New foldername, (opt) Flags)
  1474. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsr|sl", &zvalSrcFolder, &lpEntryID, &cbEntryID, &zvalDestFolder, &lpszNewFolderName, &cbNewFolderNameLen, &ulFlags) == FAILURE) return;
  1475. ZEND_FETCH_RESOURCE_C(lpSrcFolder, LPMAPIFOLDER, &zvalSrcFolder, -1, name_mapi_folder, le_mapi_folder);
  1476. ZEND_FETCH_RESOURCE_C(lpDestFolder, LPMAPIFOLDER, &zvalDestFolder, -1, name_mapi_folder, le_mapi_folder);
  1477. if (lpEntryID == NULL) {
  1478. php_error_docref(NULL TSRMLS_CC, E_WARNING, "EntryID must not be empty.");
  1479. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1480. goto exit;
  1481. }
  1482. // If php input is NULL, lpszNewFolderName ="" but you expect a NULL string
  1483. if(cbNewFolderNameLen == 0)
  1484. lpszNewFolderName = NULL;
  1485. MAPI_G(hr) = lpSrcFolder->CopyFolder(cbEntryID, lpEntryID, NULL, lpDestFolder, lpszNewFolderName, 0, NULL, ulFlags);
  1486. if(MAPI_G(hr) != hrSuccess)
  1487. goto exit;
  1488. RETVAL_TRUE;
  1489. exit:
  1490. LOG_END();
  1491. THROW_ON_ERROR();
  1492. }
  1493. /**
  1494. * mapi_msgstore_createentryid
  1495. * Creates an EntryID to open a store with mapi_openmsgstore.
  1496. * @param Resource IMsgStore
  1497. * String username
  1498. *
  1499. * return value: EntryID or FALSE when there's no permission...?
  1500. */
  1501. ZEND_FUNCTION(mapi_msgstore_createentryid)
  1502. {
  1503. PMEASURE_FUNC;
  1504. LOG_BEGIN();
  1505. // params
  1506. zval *res;
  1507. LPMDB pMDB = NULL;
  1508. LPSTR sMailboxDN = NULL;
  1509. int lMailboxDN = 0;
  1510. // return value
  1511. ULONG cbEntryID = 0;
  1512. memory_ptr<ENTRYID> lpEntryID;
  1513. // local
  1514. object_ptr<IExchangeManageStore> lpEMS;
  1515. RETVAL_FALSE;
  1516. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1517. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &sMailboxDN, &lMailboxDN) == FAILURE) return;
  1518. ZEND_FETCH_RESOURCE_C(pMDB, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  1519. MAPI_G(hr) = pMDB->QueryInterface(IID_IExchangeManageStore, &~lpEMS);
  1520. if(MAPI_G(hr) != hrSuccess) {
  1521. php_error_docref(NULL TSRMLS_CC, E_WARNING, "IExchangeManageStore interface was not supported by given store.");
  1522. goto exit;
  1523. }
  1524. MAPI_G(hr) = lpEMS->CreateStoreEntryID((LPTSTR)"", (LPTSTR)sMailboxDN, 0, &cbEntryID, &~lpEntryID);
  1525. if (MAPI_G(hr) != hrSuccess)
  1526. goto exit;
  1527. RETVAL_STRINGL(reinterpret_cast<const char *>(lpEntryID.get()), cbEntryID, 1);
  1528. exit:
  1529. LOG_END();
  1530. THROW_ON_ERROR();
  1531. }
  1532. /**
  1533. * mapi_msgstore_getearchiveentryid
  1534. * Creates an EntryID to open an archive store with mapi_openmsgstore.
  1535. * @param Resource IMsgStore
  1536. * String username
  1537. * String servername (server containing the archive)
  1538. *
  1539. * return value: EntryID or FALSE when there's no permission...?
  1540. */
  1541. ZEND_FUNCTION(mapi_msgstore_getarchiveentryid)
  1542. {
  1543. PMEASURE_FUNC;
  1544. LOG_BEGIN();
  1545. // params
  1546. zval *res;
  1547. LPMDB pMDB = NULL;
  1548. LPSTR sUser = NULL;
  1549. int lUser = 0;
  1550. LPSTR sServer = NULL;
  1551. int lServer = 0;
  1552. // return value
  1553. ULONG cbEntryID = 0;
  1554. EntryIdPtr ptrEntryID;
  1555. // local
  1556. ECServiceAdminPtr ptrSA;
  1557. RETVAL_FALSE;
  1558. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1559. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &res, &sUser, &lUser, &sServer, &lServer) == FAILURE) return;
  1560. ZEND_FETCH_RESOURCE_C(pMDB, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  1561. MAPI_G(hr) = pMDB->QueryInterface(ptrSA.iid(), &~ptrSA);
  1562. if(MAPI_G(hr) != hrSuccess) {
  1563. php_error_docref(NULL TSRMLS_CC, E_WARNING, "IECServiceAdmin interface was not supported by given store.");
  1564. goto exit;
  1565. }
  1566. MAPI_G(hr) = ptrSA->GetArchiveStoreEntryID((LPTSTR)sUser, (LPTSTR)sServer, 0, &cbEntryID, &~ptrEntryID);
  1567. if (MAPI_G(hr) != hrSuccess)
  1568. goto exit;
  1569. RETVAL_STRINGL((char *)ptrEntryID.get(), cbEntryID, 1);
  1570. exit:
  1571. LOG_END();
  1572. THROW_ON_ERROR();
  1573. }
  1574. /**
  1575. * mapi_openentry
  1576. * Opens the msgstore to get the root folder.
  1577. * @param Resource IMsgStore
  1578. * @param String EntryID
  1579. */
  1580. ZEND_FUNCTION(mapi_msgstore_openentry)
  1581. {
  1582. PMEASURE_FUNC;
  1583. LOG_BEGIN();
  1584. // params
  1585. zval *res;
  1586. LPMDB pMDB = NULL;
  1587. ULONG cbEntryID = 0;
  1588. LPENTRYID lpEntryID = NULL;
  1589. long ulFlags = MAPI_BEST_ACCESS;
  1590. // return value
  1591. LPUNKNOWN lpUnknown; // either folder or message
  1592. // local
  1593. ULONG ulObjType;
  1594. RETVAL_FALSE;
  1595. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1596. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|sl", &res, &lpEntryID, &cbEntryID, &ulFlags) == FAILURE) return;
  1597. ZEND_FETCH_RESOURCE_C(pMDB, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  1598. // returns a folder
  1599. MAPI_G(hr) = pMDB->OpenEntry(cbEntryID, lpEntryID, NULL, ulFlags, &ulObjType, &lpUnknown );
  1600. if (FAILED(MAPI_G(hr)))
  1601. goto exit;
  1602. if (ulObjType == MAPI_FOLDER) {
  1603. UOBJ_REGISTER_RESOURCE(return_value, lpUnknown, le_mapi_folder);
  1604. }
  1605. else if(ulObjType == MAPI_MESSAGE) {
  1606. UOBJ_REGISTER_RESOURCE(return_value, lpUnknown, le_mapi_message);
  1607. } else {
  1608. if (lpUnknown)
  1609. lpUnknown->Release();
  1610. php_error_docref(NULL TSRMLS_CC, E_WARNING, "EntryID is not a folder or a message.");
  1611. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1612. goto exit;
  1613. }
  1614. exit:
  1615. LOG_END();
  1616. THROW_ON_ERROR();
  1617. }
  1618. ZEND_FUNCTION(mapi_msgstore_entryidfromsourcekey)
  1619. {
  1620. PMEASURE_FUNC;
  1621. LOG_BEGIN();
  1622. zval *resStore = NULL;
  1623. BYTE *lpSourceKeyMessage = NULL;
  1624. ULONG cbSourceKeyMessage = 0;
  1625. LPMDB lpMsgStore = NULL;
  1626. BYTE *lpSourceKeyFolder = NULL;
  1627. ULONG cbSourceKeyFolder = 0;
  1628. memory_ptr<ENTRYID> lpEntryId;
  1629. ULONG cbEntryId = 0;
  1630. object_ptr<IExchangeManageStore> lpIEMS;
  1631. RETVAL_FALSE;
  1632. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1633. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|s", &resStore, &lpSourceKeyFolder, &cbSourceKeyFolder, &lpSourceKeyMessage, &cbSourceKeyMessage) == FAILURE) return;
  1634. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &resStore, -1, name_mapi_msgstore, le_mapi_msgstore);
  1635. MAPI_G(hr) = lpMsgStore->QueryInterface(IID_IExchangeManageStore, &~lpIEMS);
  1636. if(MAPI_G(hr) != hrSuccess)
  1637. goto exit;
  1638. MAPI_G(hr) = lpIEMS->EntryIDFromSourceKey(cbSourceKeyFolder, lpSourceKeyFolder, cbSourceKeyMessage, lpSourceKeyMessage, &cbEntryId, &~lpEntryId);
  1639. if(MAPI_G(hr) != hrSuccess)
  1640. goto exit;
  1641. RETVAL_STRINGL(reinterpret_cast<const char *>(lpEntryId.get()), cbEntryId, 1);
  1642. exit:
  1643. LOG_END();
  1644. THROW_ON_ERROR();
  1645. }
  1646. ZEND_FUNCTION(mapi_msgstore_advise)
  1647. {
  1648. PMEASURE_FUNC;
  1649. LOG_BEGIN();
  1650. zval *resStore = NULL;
  1651. zval *resSink = NULL;
  1652. LPMDB lpMsgStore = NULL;
  1653. IMAPIAdviseSink *lpSink = NULL;
  1654. LPENTRYID lpEntryId = NULL;
  1655. ULONG cbEntryId = 0;
  1656. long ulMask = 0;
  1657. ULONG ulConnection = 0;
  1658. RETVAL_FALSE;
  1659. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1660. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rslr", &resStore, &lpEntryId, &cbEntryId, &ulMask, &resSink) == FAILURE) return;
  1661. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &resStore, -1, name_mapi_msgstore, le_mapi_msgstore);
  1662. ZEND_FETCH_RESOURCE_C(lpSink, MAPINotifSink *, &resSink, -1, name_mapi_advisesink, le_mapi_advisesink);
  1663. // Sanitize NULL entryids
  1664. if(cbEntryId == 0) lpEntryId = NULL;
  1665. MAPI_G(hr) = lpMsgStore->Advise(cbEntryId, lpEntryId, ulMask, lpSink, &ulConnection);
  1666. if(MAPI_G(hr) != hrSuccess)
  1667. goto exit;
  1668. RETVAL_LONG(ulConnection);
  1669. exit:
  1670. LOG_END();
  1671. THROW_ON_ERROR();
  1672. }
  1673. ZEND_FUNCTION(mapi_msgstore_unadvise)
  1674. {
  1675. PMEASURE_FUNC;
  1676. LOG_BEGIN();
  1677. zval *resStore = NULL;
  1678. LPMDB lpMsgStore = NULL;
  1679. long ulConnection = 0;
  1680. RETVAL_FALSE;
  1681. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1682. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &resStore, &ulConnection) == FAILURE) return;
  1683. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &resStore, -1, name_mapi_msgstore, le_mapi_msgstore);
  1684. MAPI_G(hr) = lpMsgStore->Unadvise(ulConnection);
  1685. if(MAPI_G(hr) != hrSuccess)
  1686. goto exit;
  1687. RETVAL_TRUE;
  1688. exit:
  1689. LOG_END();
  1690. THROW_ON_ERROR();
  1691. }
  1692. ZEND_FUNCTION(mapi_sink_create)
  1693. {
  1694. PMEASURE_FUNC;
  1695. LOG_BEGIN();
  1696. MAPINotifSink *lpSink = NULL;
  1697. RETVAL_FALSE;
  1698. MAPI_G(hr) = MAPINotifSink::Create(&lpSink);
  1699. UOBJ_REGISTER_RESOURCE(return_value, lpSink, le_mapi_advisesink);
  1700. LOG_END();
  1701. }
  1702. ZEND_FUNCTION(mapi_sink_timedwait)
  1703. {
  1704. PMEASURE_FUNC;
  1705. LOG_BEGIN();
  1706. zval *resSink = NULL;
  1707. zval *notifications = NULL;
  1708. long ulTime = 0;
  1709. MAPINotifSink *lpSink = NULL;
  1710. ULONG cNotifs = 0;
  1711. memory_ptr<NOTIFICATION> lpNotifs;
  1712. RETVAL_FALSE;
  1713. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1714. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &resSink, &ulTime) == FAILURE) return;
  1715. ZEND_FETCH_RESOURCE_C(lpSink, MAPINotifSink *, &resSink, -1, name_mapi_advisesink, le_mapi_advisesink);
  1716. MAPI_G(hr) = lpSink->GetNotifications(&cNotifs, &~lpNotifs, false, ulTime);
  1717. if(MAPI_G(hr) != hrSuccess)
  1718. goto exit;
  1719. MAPI_G(hr) = NotificationstoPHPArray(cNotifs, lpNotifs, &notifications TSRMLS_CC);
  1720. if(MAPI_G(hr) != hrSuccess) {
  1721. php_error_docref(NULL TSRMLS_CC, E_WARNING, "The notifications could not be converted to a PHP array");
  1722. goto exit;
  1723. }
  1724. RETVAL_ZVAL(notifications, 0, 0);
  1725. FREE_ZVAL(notifications);
  1726. exit:
  1727. LOG_END();
  1728. THROW_ON_ERROR();
  1729. }
  1730. /**
  1731. * mapi_table_hrqueryallrows
  1732. * Execute htqueryallrows on a table
  1733. * @param Resource MAPITable
  1734. * @return Array
  1735. */
  1736. ZEND_FUNCTION(mapi_table_queryallrows)
  1737. {
  1738. PMEASURE_FUNC;
  1739. LOG_BEGIN();
  1740. // params
  1741. zval *res = NULL;
  1742. zval *tagArray = NULL;
  1743. zval *restrictionArray = NULL;
  1744. zval *rowset = NULL;
  1745. LPMAPITABLE lpTable = NULL;
  1746. // return value
  1747. // locals
  1748. memory_ptr<SPropTagArray> lpTagArray;
  1749. memory_ptr<SRestriction> lpRestrict;
  1750. rowset_ptr pRowSet;
  1751. RETVAL_FALSE;
  1752. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1753. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|aa", &res, &tagArray, &restrictionArray) == FAILURE) return;
  1754. ZEND_FETCH_RESOURCE_C(lpTable, LPMAPITABLE, &res, -1, name_mapi_table, le_mapi_table);
  1755. if (restrictionArray != NULL) {
  1756. // create restrict array
  1757. MAPI_G(hr) = MAPIAllocateBuffer(sizeof(SRestriction), &~lpRestrict);
  1758. if (MAPI_G(hr) != hrSuccess)
  1759. goto exit;
  1760. MAPI_G(hr) = PHPArraytoSRestriction(restrictionArray, /* result */lpRestrict, /* Base */lpRestrict TSRMLS_CC);
  1761. if (MAPI_G(hr) != hrSuccess) {
  1762. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to convert the PHP srestriction array");
  1763. goto exit;
  1764. }
  1765. }
  1766. if (tagArray != NULL) {
  1767. // create proptag array
  1768. MAPI_G(hr) = PHPArraytoPropTagArray(tagArray, NULL, &~lpTagArray TSRMLS_CC);
  1769. if (MAPI_G(hr) != hrSuccess) {
  1770. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to convert the PHP proptag array");
  1771. goto exit;
  1772. }
  1773. }
  1774. // Execute
  1775. MAPI_G(hr) = HrQueryAllRows(lpTable, lpTagArray, lpRestrict, nullptr, 0, &~pRowSet);
  1776. // return the returncode
  1777. if (FAILED(MAPI_G(hr)))
  1778. goto exit;
  1779. MAPI_G(hr) = RowSettoPHPArray(pRowSet, &rowset TSRMLS_CC);
  1780. if(MAPI_G(hr) != hrSuccess) {
  1781. php_error_docref(NULL TSRMLS_CC, E_WARNING, "The resulting rowset could not be converted to a PHP array");
  1782. goto exit;
  1783. }
  1784. RETVAL_ZVAL(rowset, 0, 0);
  1785. FREE_ZVAL(rowset);
  1786. exit:
  1787. LOG_END();
  1788. THROW_ON_ERROR();
  1789. }
  1790. /**
  1791. * mapi_table_queryrows
  1792. * Execute queryrows on a table
  1793. * @param Resource MAPITable
  1794. * @param long
  1795. * @param array
  1796. * @return array
  1797. */
  1798. ZEND_FUNCTION(mapi_table_queryrows)
  1799. {
  1800. PMEASURE_FUNC;
  1801. LOG_BEGIN();
  1802. // params
  1803. zval *res = NULL;
  1804. LPMAPITABLE lpTable = NULL;
  1805. zval *tagArray = NULL;
  1806. zval *rowset = NULL;
  1807. memory_ptr<SPropTagArray> lpTagArray;
  1808. long lRowCount = 0, start = 0;
  1809. // local
  1810. rowset_ptr pRowSet;
  1811. RETVAL_FALSE;
  1812. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1813. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|a!ll", &res, &tagArray, &start, &lRowCount) == FAILURE) return;
  1814. ZEND_FETCH_RESOURCE_C(lpTable, LPMAPITABLE, &res, -1, name_mapi_table, le_mapi_table);
  1815. if (tagArray != NULL) {
  1816. MAPI_G(hr) = PHPArraytoPropTagArray(tagArray, NULL, &~lpTagArray TSRMLS_CC);
  1817. if (MAPI_G(hr) != hrSuccess) {
  1818. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to convert the PHP Array");
  1819. goto exit;
  1820. }
  1821. MAPI_G(hr) = lpTable->SetColumns(lpTagArray, TBL_BATCH);
  1822. if (FAILED(MAPI_G(hr))) {
  1823. php_error_docref(NULL TSRMLS_CC, E_WARNING, "SetColumns failed. Error code %08X", MAPI_G(hr));
  1824. goto exit;
  1825. }
  1826. }
  1827. // move to the starting row if there is one
  1828. if (start != 0) {
  1829. MAPI_G(hr) = lpTable->SeekRow(BOOKMARK_BEGINNING, start, NULL);
  1830. if (FAILED(MAPI_G(hr))) {
  1831. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Seekrow failed. Error code %08X", MAPI_G(hr));
  1832. goto exit;
  1833. }
  1834. }
  1835. MAPI_G(hr) = lpTable->QueryRows(lRowCount, 0, &~pRowSet);
  1836. if (FAILED(MAPI_G(hr)))
  1837. goto exit;
  1838. MAPI_G(hr) = RowSettoPHPArray(pRowSet, &rowset TSRMLS_CC);
  1839. if(MAPI_G(hr) != hrSuccess) {
  1840. php_error_docref(NULL TSRMLS_CC, E_WARNING, "The resulting rowset could not be converted to a PHP array");
  1841. goto exit;
  1842. }
  1843. RETVAL_ZVAL(rowset, 0, 0);
  1844. FREE_ZVAL(rowset);
  1845. exit:
  1846. LOG_END();
  1847. THROW_ON_ERROR();
  1848. }
  1849. /**
  1850. * mapi_table_setcolumns
  1851. * Execute setcolumns on a table
  1852. * @param Resource MAPITable
  1853. * @param array column set
  1854. * @return true/false
  1855. */
  1856. ZEND_FUNCTION(mapi_table_setcolumns)
  1857. {
  1858. PMEASURE_FUNC;
  1859. LOG_BEGIN();
  1860. // params
  1861. zval *res = NULL;
  1862. LPMAPITABLE lpTable = NULL;
  1863. zval *tagArray = NULL;
  1864. long lFlags = 0;
  1865. // local
  1866. memory_ptr<SPropTagArray> lpTagArray;
  1867. RETVAL_FALSE;
  1868. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1869. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra|l", &res, &tagArray, &lFlags) == FAILURE) return;
  1870. ZEND_FETCH_RESOURCE_C(lpTable, LPMAPITABLE, &res, -1, name_mapi_table, le_mapi_table);
  1871. MAPI_G(hr) = PHPArraytoPropTagArray(tagArray, NULL, &~lpTagArray TSRMLS_CC);
  1872. if (MAPI_G(hr) != hrSuccess) {
  1873. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to convert the PHP Array");
  1874. goto exit;
  1875. }
  1876. MAPI_G(hr) = lpTable->SetColumns(lpTagArray, lFlags);
  1877. if (FAILED(MAPI_G(hr))) {
  1878. php_error_docref(NULL TSRMLS_CC, E_WARNING, "SetColumns failed. Error code %08X", MAPI_G(hr));
  1879. goto exit;
  1880. }
  1881. RETVAL_TRUE;
  1882. exit:
  1883. LOG_END();
  1884. THROW_ON_ERROR();
  1885. }
  1886. /**
  1887. * mapi_table_seekrow
  1888. * Execute seekrow on a table
  1889. * @param Resource MAPITable
  1890. * @param long bookmark
  1891. * @param long Flags
  1892. * @return long RowsSought
  1893. */
  1894. ZEND_FUNCTION(mapi_table_seekrow)
  1895. {
  1896. PMEASURE_FUNC;
  1897. LOG_BEGIN();
  1898. // params
  1899. zval *res = NULL;
  1900. LPMAPITABLE lpTable = NULL;
  1901. long lRowCount = 0, lbookmark = BOOKMARK_BEGINNING;
  1902. // return
  1903. long lRowsSought = 0;
  1904. RETVAL_FALSE;
  1905. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1906. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &res, &lbookmark, &lRowCount) == FAILURE) return;
  1907. ZEND_FETCH_RESOURCE_C(lpTable, LPMAPITABLE, &res, -1, name_mapi_table, le_mapi_table);
  1908. MAPI_G(hr) = lpTable->SeekRow((BOOKMARK)lbookmark, lRowCount, (LONG*)&lRowsSought);
  1909. if (FAILED(MAPI_G(hr))) {
  1910. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Seekrow failed. Error code %08X", MAPI_G(hr));
  1911. goto exit;
  1912. }
  1913. RETVAL_LONG(lRowsSought);
  1914. exit:
  1915. LOG_END();
  1916. THROW_ON_ERROR();
  1917. }
  1918. /**
  1919. *
  1920. *
  1921. *
  1922. */
  1923. ZEND_FUNCTION(mapi_table_sort)
  1924. {
  1925. PMEASURE_FUNC;
  1926. LOG_BEGIN();
  1927. // params
  1928. zval * res;
  1929. zval * sortArray;
  1930. long ulFlags = 0;
  1931. // local
  1932. LPMAPITABLE lpTable = NULL;
  1933. memory_ptr<SSortOrderSet> lpSortCriteria;
  1934. RETVAL_FALSE;
  1935. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1936. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra|l", &res, &sortArray, &ulFlags) == FAILURE) return;
  1937. ZEND_FETCH_RESOURCE_C(lpTable, LPMAPITABLE, &res, -1, name_mapi_table, le_mapi_table);
  1938. MAPI_G(hr) = PHPArraytoSortOrderSet(sortArray, NULL, &~lpSortCriteria TSRMLS_CC);
  1939. if(MAPI_G(hr) != hrSuccess)
  1940. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to convert sort order set from the PHP array");
  1941. MAPI_G(hr) = lpTable->SortTable(lpSortCriteria, ulFlags);
  1942. if (FAILED(MAPI_G(hr)))
  1943. goto exit;
  1944. RETVAL_TRUE;
  1945. exit:
  1946. LOG_END();
  1947. THROW_ON_ERROR();
  1948. }
  1949. /**
  1950. *
  1951. *
  1952. *
  1953. */
  1954. ZEND_FUNCTION(mapi_table_getrowcount)
  1955. {
  1956. PMEASURE_FUNC;
  1957. LOG_BEGIN();
  1958. // params
  1959. zval *res;
  1960. LPMAPITABLE lpTable = NULL;
  1961. // return value
  1962. ULONG count = 0;
  1963. RETVAL_FALSE;
  1964. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1965. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) return;
  1966. ZEND_FETCH_RESOURCE_C(lpTable, LPMAPITABLE, &res, -1, name_mapi_table, le_mapi_table);
  1967. MAPI_G(hr) = lpTable->GetRowCount(0, &count);
  1968. if (FAILED(MAPI_G(hr)))
  1969. goto exit;
  1970. RETVAL_LONG(count);
  1971. exit:
  1972. LOG_END();
  1973. THROW_ON_ERROR();
  1974. }
  1975. /**
  1976. *
  1977. *
  1978. *
  1979. */
  1980. ZEND_FUNCTION(mapi_table_restrict)
  1981. {
  1982. PMEASURE_FUNC;
  1983. LOG_BEGIN();
  1984. // params
  1985. zval *res;
  1986. zval *restrictionArray;
  1987. ulong ulFlags = 0;
  1988. // local
  1989. LPMAPITABLE lpTable = NULL;
  1990. memory_ptr<SRestriction> lpRestrict;
  1991. RETVAL_FALSE;
  1992. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  1993. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra|l", &res, &restrictionArray, &ulFlags) == FAILURE) return;
  1994. ZEND_FETCH_RESOURCE_C(lpTable, LPMAPITABLE, &res, -1, name_mapi_table, le_mapi_table);
  1995. if (!restrictionArray || zend_hash_num_elements(Z_ARRVAL_P(restrictionArray)) == 0) {
  1996. // reset restriction
  1997. lpRestrict.reset();
  1998. } else {
  1999. // create restrict array
  2000. MAPI_G(hr) = PHPArraytoSRestriction(restrictionArray, NULL, &~lpRestrict TSRMLS_CC);
  2001. if (MAPI_G(hr) != hrSuccess) {
  2002. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to convert the PHP srestriction Array");
  2003. goto exit;
  2004. }
  2005. }
  2006. MAPI_G(hr) = lpTable->Restrict(lpRestrict, ulFlags);
  2007. if(MAPI_G(hr) != hrSuccess)
  2008. goto exit;
  2009. RETVAL_TRUE;
  2010. exit:
  2011. LOG_END();
  2012. THROW_ON_ERROR();
  2013. }
  2014. ZEND_FUNCTION(mapi_table_findrow)
  2015. {
  2016. PMEASURE_FUNC;
  2017. LOG_BEGIN();
  2018. // params
  2019. zval *res;
  2020. zval *restrictionArray;
  2021. ulong bkOrigin = BOOKMARK_BEGINNING;
  2022. ulong ulFlags = 0;
  2023. // local
  2024. LPMAPITABLE lpTable = NULL;
  2025. memory_ptr<SRestriction> lpRestrict;
  2026. ULONG ulRow = 0;
  2027. ULONG ulNumerator = 0;
  2028. ULONG ulDenominator = 0;
  2029. RETVAL_FALSE;
  2030. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  2031. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra|ll", &res, &restrictionArray, &bkOrigin, &ulFlags) == FAILURE) return;
  2032. ZEND_FETCH_RESOURCE_C(lpTable, LPMAPITABLE, &res, -1, name_mapi_table, le_mapi_table);
  2033. if (!restrictionArray || zend_hash_num_elements(Z_ARRVAL_P(restrictionArray)) == 0) {
  2034. // reset restriction
  2035. lpRestrict.reset();
  2036. } else {
  2037. // create restrict array
  2038. MAPI_G(hr) = PHPArraytoSRestriction(restrictionArray, NULL, &~lpRestrict TSRMLS_CC);
  2039. if (MAPI_G(hr) != hrSuccess) {
  2040. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to convert the PHP srestriction Array");
  2041. goto exit;
  2042. }
  2043. }
  2044. MAPI_G(hr) = lpTable->FindRow(lpRestrict, bkOrigin, ulFlags);
  2045. if(MAPI_G(hr) != hrSuccess)
  2046. goto exit;
  2047. MAPI_G(hr) = lpTable->QueryPosition(&ulRow, &ulNumerator, &ulDenominator);
  2048. if (FAILED(MAPI_G(hr)))
  2049. goto exit;
  2050. RETVAL_LONG(ulRow);
  2051. exit:
  2052. LOG_END();
  2053. THROW_ON_ERROR();
  2054. }
  2055. /**
  2056. * mapi_table_createbookmark
  2057. * Execute create bookmark on a table
  2058. * @param Resource MAPITable
  2059. * @return long bookmark
  2060. */
  2061. ZEND_FUNCTION(mapi_table_createbookmark)
  2062. {
  2063. PMEASURE_FUNC;
  2064. LOG_BEGIN();
  2065. // params
  2066. zval *res = NULL;
  2067. LPMAPITABLE lpTable = NULL;
  2068. // return
  2069. long lbookmark = 0;
  2070. RETVAL_FALSE;
  2071. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  2072. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) return;
  2073. ZEND_FETCH_RESOURCE_C(lpTable, LPMAPITABLE, &res, -1, name_mapi_table, le_mapi_table);
  2074. MAPI_G(hr) = lpTable->CreateBookmark((BOOKMARK*)&lbookmark);
  2075. if (FAILED(MAPI_G(hr))) {
  2076. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Create bookmark failed. Error code %08X", MAPI_G(hr));
  2077. goto exit;
  2078. }
  2079. RETVAL_LONG(lbookmark);
  2080. exit:
  2081. LOG_END();
  2082. THROW_ON_ERROR();
  2083. }
  2084. /**
  2085. * mapi_table_freebookmark
  2086. * Execute free bookmark on a table
  2087. * @param Resource MAPITable
  2088. * @param long bookmark
  2089. * @return true/false
  2090. */
  2091. ZEND_FUNCTION(mapi_table_freebookmark)
  2092. {
  2093. PMEASURE_FUNC;
  2094. LOG_BEGIN();
  2095. // params
  2096. zval *res = NULL;
  2097. LPMAPITABLE lpTable = NULL;
  2098. long lbookmark = 0;
  2099. RETVAL_FALSE;
  2100. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  2101. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &res, &lbookmark) == FAILURE) return;
  2102. ZEND_FETCH_RESOURCE_C(lpTable, LPMAPITABLE, &res, -1, name_mapi_table, le_mapi_table);
  2103. MAPI_G(hr) = lpTable->FreeBookmark((BOOKMARK)lbookmark);
  2104. if (FAILED(MAPI_G(hr))) {
  2105. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Free bookmark failed. Error code %08X", MAPI_G(hr));
  2106. goto exit;
  2107. }
  2108. RETVAL_TRUE;
  2109. exit:
  2110. LOG_END();
  2111. THROW_ON_ERROR();
  2112. }
  2113. /**
  2114. * mapi_msgstore_getreceivefolder
  2115. *
  2116. * @param Resource MAPIMSGStore
  2117. * @return MAPIFolder
  2118. */
  2119. ZEND_FUNCTION(mapi_msgstore_getreceivefolder)
  2120. {
  2121. PMEASURE_FUNC;
  2122. LOG_BEGIN();
  2123. // params
  2124. zval *res;
  2125. LPMDB pMDB = NULL;
  2126. // return value
  2127. LPUNKNOWN lpFolder = NULL;
  2128. // locals
  2129. ULONG cbEntryID = 0;
  2130. memory_ptr<ENTRYID> lpEntryID;
  2131. ULONG ulObjType = 0;
  2132. RETVAL_FALSE;
  2133. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  2134. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) return;
  2135. ZEND_FETCH_RESOURCE_C(pMDB, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  2136. MAPI_G(hr) = pMDB->GetReceiveFolder(NULL, 0, &cbEntryID, &~lpEntryID, NULL);
  2137. if(FAILED(MAPI_G(hr)))
  2138. goto exit;
  2139. MAPI_G(hr) = pMDB->OpenEntry(cbEntryID, lpEntryID, NULL, MAPI_BEST_ACCESS, &ulObjType, (LPUNKNOWN*)&lpFolder);
  2140. if(MAPI_G(hr) != hrSuccess)
  2141. goto exit;
  2142. UOBJ_REGISTER_RESOURCE(return_value, lpFolder, le_mapi_folder);
  2143. exit:
  2144. LOG_END();
  2145. THROW_ON_ERROR();
  2146. }
  2147. /**
  2148. * mapi_msgstore_openmultistoretable
  2149. *
  2150. * @param Resource MAPIMSGStore
  2151. * @param Array EntryIdList
  2152. * @param Long Flags
  2153. * @return MAPITable
  2154. */
  2155. ZEND_FUNCTION(mapi_msgstore_openmultistoretable)
  2156. {
  2157. PMEASURE_FUNC;
  2158. LOG_BEGIN();
  2159. // params
  2160. zval *res;
  2161. zval *entryid_array = NULL;
  2162. LPMDB lpMDB = NULL;
  2163. long ulFlags = 0;
  2164. // return value
  2165. LPMAPITABLE lpMultiTable = NULL;
  2166. // locals
  2167. object_ptr<IECMultiStoreTable> lpECMST;
  2168. memory_ptr<ENTRYLIST> lpEntryList;
  2169. IECUnknown *lpUnknown = NULL;
  2170. RETVAL_FALSE;
  2171. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  2172. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra|l", &res, &entryid_array, &ulFlags) == FAILURE) return;
  2173. ZEND_FETCH_RESOURCE_C(lpMDB, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  2174. MAPI_G(hr) = PHPArraytoSBinaryArray(entryid_array, NULL, &~lpEntryList TSRMLS_CC);
  2175. if(MAPI_G(hr) != hrSuccess) {
  2176. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad message list");
  2177. goto exit;
  2178. }
  2179. MAPI_G(hr) = GetECObject(lpMDB, &lpUnknown TSRMLS_CC);
  2180. if(MAPI_G(hr) != hrSuccess) {
  2181. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano object");
  2182. goto exit;
  2183. }
  2184. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECMultiStoreTable, &~lpECMST);
  2185. if (FAILED(MAPI_G(hr)))
  2186. goto exit;
  2187. MAPI_G(hr) = lpECMST->OpenMultiStoreTable(lpEntryList, ulFlags, &lpMultiTable);
  2188. if (FAILED(MAPI_G(hr)))
  2189. goto exit;
  2190. UOBJ_REGISTER_RESOURCE(return_value, lpMultiTable, le_mapi_table);
  2191. exit:
  2192. LOG_END();
  2193. THROW_ON_ERROR();
  2194. }
  2195. /**
  2196. * mapi_message_modifyrecipients
  2197. * @param resource
  2198. * @param flags
  2199. * @param array
  2200. */
  2201. ZEND_FUNCTION(mapi_message_modifyrecipients)
  2202. {
  2203. PMEASURE_FUNC;
  2204. LOG_BEGIN();
  2205. // params
  2206. zval *res, *adrlist;
  2207. LPMESSAGE pMessage = NULL;
  2208. long flags = MODRECIP_ADD; // flags to use, default to ADD
  2209. // local
  2210. adrlist_ptr lpListRecipients;
  2211. RETVAL_FALSE;
  2212. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  2213. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rla", &res, &flags, &adrlist) == FAILURE) return;
  2214. ZEND_FETCH_RESOURCE_C(pMessage, LPMESSAGE, &res, -1, name_mapi_message, le_mapi_message);
  2215. MAPI_G(hr) = PHPArraytoAdrList(adrlist, nullptr, &~lpListRecipients TSRMLS_CC);
  2216. if (MAPI_G(hr) != hrSuccess) {
  2217. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to parse recipient list");
  2218. goto exit;
  2219. }
  2220. MAPI_G(hr) = pMessage->ModifyRecipients(flags, lpListRecipients);
  2221. if (FAILED(MAPI_G(hr)))
  2222. goto exit;
  2223. RETVAL_TRUE;
  2224. exit:
  2225. LOG_END();
  2226. THROW_ON_ERROR();
  2227. }
  2228. /**
  2229. * mapi_message_submitmessage
  2230. *
  2231. *
  2232. */
  2233. ZEND_FUNCTION(mapi_message_submitmessage)
  2234. {
  2235. PMEASURE_FUNC;
  2236. LOG_BEGIN();
  2237. // params
  2238. zval * res;
  2239. LPMESSAGE pMessage = NULL;
  2240. RETVAL_FALSE;
  2241. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  2242. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) return;
  2243. ZEND_FETCH_RESOURCE_C(pMessage, LPMESSAGE, &res, -1, name_mapi_message, le_mapi_message);
  2244. MAPI_G(hr) = pMessage->SubmitMessage(0);
  2245. if (FAILED(MAPI_G(hr)))
  2246. goto exit;
  2247. RETVAL_TRUE;
  2248. exit:
  2249. LOG_END();
  2250. THROW_ON_ERROR();
  2251. }
  2252. /**
  2253. * mapi_message_getattachmenttable
  2254. * @return MAPITable
  2255. *
  2256. */
  2257. ZEND_FUNCTION(mapi_message_getattachmenttable)
  2258. {
  2259. PMEASURE_FUNC;
  2260. LOG_BEGIN();
  2261. // params
  2262. zval * res = NULL;
  2263. LPMESSAGE pMessage = NULL;
  2264. // return value
  2265. LPMAPITABLE pTable = NULL;
  2266. RETVAL_FALSE;
  2267. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  2268. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) return;
  2269. ZEND_FETCH_RESOURCE_C(pMessage, LPMESSAGE, &res, -1, name_mapi_message, le_mapi_message);
  2270. MAPI_G(hr) = pMessage->GetAttachmentTable(0, &pTable);
  2271. if (FAILED(MAPI_G(hr)))
  2272. goto exit;
  2273. UOBJ_REGISTER_RESOURCE(return_value, pTable, le_mapi_table);
  2274. exit:
  2275. LOG_END();
  2276. THROW_ON_ERROR();
  2277. }
  2278. /**
  2279. * Opens a attachment
  2280. * @param Message resource
  2281. * @param Attachment number
  2282. * @return Attachment resource
  2283. */
  2284. ZEND_FUNCTION(mapi_message_openattach)
  2285. {
  2286. PMEASURE_FUNC;
  2287. LOG_BEGIN();
  2288. // params
  2289. zval *res = NULL;
  2290. LPMESSAGE pMessage = NULL;
  2291. long attach_num = 0;
  2292. // return value
  2293. LPATTACH pAttach = NULL;
  2294. RETVAL_FALSE;
  2295. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  2296. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &res, &attach_num) == FAILURE) return;
  2297. ZEND_FETCH_RESOURCE_C(pMessage, LPMESSAGE, &res, -1, name_mapi_message, le_mapi_message);
  2298. MAPI_G(hr) = pMessage->OpenAttach(attach_num, NULL, MAPI_BEST_ACCESS, &pAttach);
  2299. if (FAILED(MAPI_G(hr)))
  2300. goto exit;
  2301. UOBJ_REGISTER_RESOURCE(return_value, pAttach, le_mapi_attachment);
  2302. exit:
  2303. LOG_END();
  2304. THROW_ON_ERROR();
  2305. }
  2306. ZEND_FUNCTION(mapi_message_createattach)
  2307. {
  2308. PMEASURE_FUNC;
  2309. LOG_BEGIN();
  2310. // params
  2311. zval *zvalMessage = NULL;
  2312. LPMESSAGE lpMessage = NULL;
  2313. long ulFlags = 0;
  2314. // return value
  2315. LPATTACH lpAttach = NULL;
  2316. // local
  2317. ULONG attachNum = 0;
  2318. RETVAL_FALSE;
  2319. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  2320. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &zvalMessage, &ulFlags) == FAILURE) return;
  2321. ZEND_FETCH_RESOURCE_C(lpMessage, LPMESSAGE, &zvalMessage, -1, name_mapi_message, le_mapi_message);
  2322. MAPI_G(hr) = lpMessage->CreateAttach(NULL, ulFlags, &attachNum, &lpAttach);
  2323. if (FAILED(MAPI_G(hr)))
  2324. goto exit;
  2325. UOBJ_REGISTER_RESOURCE(return_value, lpAttach, le_mapi_attachment);
  2326. exit:
  2327. LOG_END();
  2328. THROW_ON_ERROR();
  2329. }
  2330. ZEND_FUNCTION(mapi_message_deleteattach)
  2331. {
  2332. PMEASURE_FUNC;
  2333. LOG_BEGIN();
  2334. // params
  2335. zval *zvalMessage = NULL;
  2336. LPMESSAGE lpMessage = NULL;
  2337. long ulFlags = 0, attachNum = 0;
  2338. RETVAL_FALSE;
  2339. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  2340. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|l", &zvalMessage, &attachNum, &ulFlags) == FAILURE) return;
  2341. ZEND_FETCH_RESOURCE_C(lpMessage, LPMESSAGE, &zvalMessage, -1, name_mapi_message, le_mapi_message);
  2342. MAPI_G(hr) = lpMessage->DeleteAttach(attachNum, 0, NULL, ulFlags);
  2343. if (FAILED(MAPI_G(hr)))
  2344. goto exit;
  2345. RETVAL_TRUE;
  2346. exit:
  2347. LOG_END();
  2348. THROW_ON_ERROR();
  2349. }
  2350. ZEND_FUNCTION(mapi_stream_read)
  2351. {
  2352. PMEASURE_FUNC;
  2353. LOG_BEGIN();
  2354. // params
  2355. zval *res = NULL;
  2356. LPSTREAM pStream = NULL;
  2357. unsigned long lgetBytes = 0;
  2358. // return value
  2359. std::unique_ptr<char[]> buf;
  2360. ULONG actualRead = 0;
  2361. RETVAL_FALSE;
  2362. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  2363. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &res, &lgetBytes) == FAILURE) return;
  2364. ZEND_FETCH_RESOURCE_C(pStream, LPSTREAM, &res, -1, name_istream, le_istream);
  2365. buf.reset(new char[lgetBytes]);
  2366. MAPI_G(hr) = pStream->Read(buf.get(), lgetBytes, &actualRead);
  2367. if (MAPI_G(hr) != hrSuccess)
  2368. goto exit;
  2369. RETVAL_STRINGL(buf.get(), actualRead, 1);
  2370. exit:
  2371. LOG_END();
  2372. THROW_ON_ERROR();
  2373. }
  2374. ZEND_FUNCTION(mapi_stream_seek)
  2375. {
  2376. PMEASURE_FUNC;
  2377. LOG_BEGIN();
  2378. // params
  2379. zval *res = NULL;
  2380. LPSTREAM pStream = NULL;
  2381. long moveBytes = 0, seekFlag = STREAM_SEEK_CUR;
  2382. // local
  2383. LARGE_INTEGER move;
  2384. ULARGE_INTEGER newPos;
  2385. RETVAL_FALSE;
  2386. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  2387. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|l", &res, &moveBytes, &seekFlag) == FAILURE) return;
  2388. ZEND_FETCH_RESOURCE_C(pStream, LPSTREAM, &res, -1, name_istream, le_istream);
  2389. move.QuadPart = moveBytes;
  2390. MAPI_G(hr) = pStream->Seek(move, seekFlag, &newPos);
  2391. if (FAILED(MAPI_G(hr)))
  2392. goto exit;
  2393. RETVAL_TRUE;
  2394. exit:
  2395. LOG_END();
  2396. THROW_ON_ERROR();
  2397. }
  2398. ZEND_FUNCTION(mapi_stream_setsize)
  2399. {
  2400. PMEASURE_FUNC;
  2401. LOG_BEGIN();
  2402. // params
  2403. zval *res = NULL;
  2404. LPSTREAM pStream = NULL;
  2405. long newSize = 0;
  2406. // local
  2407. ULARGE_INTEGER libNewSize = { { 0 } };
  2408. RETVAL_FALSE;
  2409. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  2410. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &res, &newSize) == FAILURE) return;
  2411. ZEND_FETCH_RESOURCE_C(pStream, LPSTREAM, &res, -1, name_istream, le_istream);
  2412. libNewSize.QuadPart = newSize;
  2413. MAPI_G(hr) = pStream->SetSize(libNewSize);
  2414. if (FAILED(MAPI_G(hr)))
  2415. goto exit;
  2416. RETVAL_TRUE;
  2417. exit:
  2418. LOG_END();
  2419. THROW_ON_ERROR();
  2420. }
  2421. ZEND_FUNCTION(mapi_stream_commit)
  2422. {
  2423. PMEASURE_FUNC;
  2424. LOG_BEGIN();
  2425. // params
  2426. zval *res = NULL;
  2427. LPSTREAM pStream = NULL;
  2428. RETVAL_FALSE;
  2429. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  2430. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) return;
  2431. ZEND_FETCH_RESOURCE_C(pStream, LPSTREAM, &res, -1, name_istream, le_istream);
  2432. MAPI_G(hr) = pStream->Commit(0);
  2433. if (FAILED(MAPI_G(hr)))
  2434. goto exit;
  2435. RETVAL_TRUE;
  2436. exit:
  2437. LOG_END();
  2438. THROW_ON_ERROR();
  2439. }
  2440. ZEND_FUNCTION(mapi_stream_write)
  2441. {
  2442. PMEASURE_FUNC;
  2443. LOG_BEGIN();
  2444. // params
  2445. zval *res = NULL;
  2446. LPSTREAM pStream = NULL;
  2447. char *pv = NULL;
  2448. ULONG cb = 0;
  2449. // return value
  2450. ULONG pcbWritten = 0;
  2451. RETVAL_FALSE;
  2452. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  2453. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &pv, &cb) == FAILURE) return;
  2454. ZEND_FETCH_RESOURCE_C(pStream, LPSTREAM, &res, -1, name_istream, le_istream);
  2455. MAPI_G(hr) = pStream->Write(pv, cb, &pcbWritten);
  2456. if (MAPI_G(hr) != hrSuccess)
  2457. goto exit;
  2458. RETVAL_LONG(pcbWritten);
  2459. exit:
  2460. LOG_END();
  2461. THROW_ON_ERROR();
  2462. }
  2463. // FIXME: Add more output in the array
  2464. ZEND_FUNCTION(mapi_stream_stat)
  2465. {
  2466. PMEASURE_FUNC;
  2467. LOG_BEGIN();
  2468. // params
  2469. zval *res = NULL;
  2470. LPSTREAM pStream = NULL;
  2471. // return value
  2472. ULONG cb = 0;
  2473. // local
  2474. STATSTG stg = { 0 };
  2475. RETVAL_FALSE;
  2476. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  2477. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) return;
  2478. ZEND_FETCH_RESOURCE_C(pStream, LPSTREAM, &res, -1, name_istream, le_istream);
  2479. MAPI_G(hr) = pStream->Stat(&stg,STATFLAG_NONAME);
  2480. if(MAPI_G(hr) != hrSuccess)
  2481. goto exit;
  2482. cb = stg.cbSize.LowPart;
  2483. array_init(return_value);
  2484. add_assoc_long(return_value, "cb", cb);
  2485. exit:
  2486. LOG_END();
  2487. THROW_ON_ERROR();
  2488. }
  2489. /* Create a new in-memory IStream interface. Useful only to write stuff to and then
  2490. * read it back again. Kind of defeats the purpose of the memory usage limits in PHP though ..
  2491. */
  2492. ZEND_FUNCTION(mapi_stream_create)
  2493. {
  2494. PMEASURE_FUNC;
  2495. LOG_BEGIN();
  2496. object_ptr<ECMemStream> lpStream;
  2497. IStream *lpIStream = NULL;
  2498. RETVAL_FALSE;
  2499. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  2500. MAPI_G(hr) = ECMemStream::Create(nullptr, 0, STGM_WRITE | STGM_SHARE_EXCLUSIVE, nullptr, nullptr, nullptr, &~lpStream);
  2501. if(MAPI_G(hr) != hrSuccess) {
  2502. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to instantiate new stream object");
  2503. goto exit;
  2504. }
  2505. MAPI_G(hr) = lpStream->QueryInterface(IID_IStream, (void**)&lpIStream);
  2506. if(MAPI_G(hr) != hrSuccess)
  2507. goto exit;
  2508. ZEND_REGISTER_RESOURCE(return_value, lpIStream, le_istream);
  2509. exit:
  2510. LOG_END();
  2511. THROW_ON_ERROR();
  2512. }
  2513. /*
  2514. Opens property to a stream
  2515. THIS FUNCTION IS DEPRECATED. USE mapi_openproperty() INSTEAD
  2516. */
  2517. ZEND_FUNCTION(mapi_openpropertytostream)
  2518. {
  2519. PMEASURE_FUNC;
  2520. LOG_BEGIN();
  2521. // params
  2522. zval *res = NULL;
  2523. LPMAPIPROP lpMapiProp = NULL;
  2524. long proptag = 0, flags = 0; // open default readable
  2525. char *guidStr = NULL; // guid is given as a char array
  2526. ULONG guidLen = 0;
  2527. // return value
  2528. LPSTREAM pStream = NULL;
  2529. // local
  2530. LPGUID lpGuid; // pointer to string param or static guid
  2531. int type = -1;
  2532. RETVAL_FALSE;
  2533. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  2534. php_error_docref("mapi_openpropertytostream" TSRMLS_CC, E_DEPRECATED, "Use of mapi_openpropertytostream is deprecated, use mapi_openproperty");
  2535. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|ls", &res, &proptag, &flags, &guidStr, &guidLen) == FAILURE) return;
  2536. zend_list_find(res->value.lval, &type);
  2537. if(type == le_mapi_message) {
  2538. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPMESSAGE, &res, -1, name_mapi_message, le_mapi_message);
  2539. } else if (type == le_mapi_folder) {
  2540. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPMAPIFOLDER, &res, -1, name_mapi_folder, le_mapi_folder);
  2541. } else if (type == le_mapi_attachment) {
  2542. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPATTACH, &res, -1, name_mapi_attachment, le_mapi_attachment);
  2543. } else if (type == le_mapi_msgstore) {
  2544. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  2545. } else {
  2546. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown resource type");
  2547. goto exit;
  2548. }
  2549. if (guidStr == NULL) {
  2550. // when no guidstring is provided default to IStream
  2551. lpGuid = (LPGUID)&IID_IStream;
  2552. } else if (guidLen == sizeof(GUID)) { // assume we have a guid if the length is right
  2553. lpGuid = (LPGUID)guidStr;
  2554. } else {
  2555. php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Using the default GUID because the given GUIDs length is not right");
  2556. lpGuid = (LPGUID)&IID_IStream;
  2557. }
  2558. MAPI_G(hr) = lpMapiProp->OpenProperty(proptag, lpGuid, 0, flags, (LPUNKNOWN *) &pStream);
  2559. if (MAPI_G(hr) != hrSuccess)
  2560. goto exit;
  2561. ZEND_REGISTER_RESOURCE(return_value, pStream, le_istream);
  2562. exit:
  2563. LOG_END();
  2564. THROW_ON_ERROR();
  2565. }
  2566. /**
  2567. * mapi_message_getreceipenttable
  2568. * @return MAPI Table
  2569. *
  2570. */
  2571. ZEND_FUNCTION(mapi_message_getrecipienttable)
  2572. {
  2573. PMEASURE_FUNC;
  2574. LOG_BEGIN();
  2575. // params
  2576. zval *res;
  2577. LPMESSAGE pMessage = NULL;
  2578. // return value
  2579. LPMAPITABLE pTable = 0;
  2580. RETVAL_FALSE;
  2581. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  2582. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) return;
  2583. ZEND_FETCH_RESOURCE_C(pMessage, LPMESSAGE, &res, -1, name_mapi_message, le_mapi_message);
  2584. MAPI_G(hr) = pMessage->GetRecipientTable(0, &pTable);
  2585. if (FAILED(MAPI_G(hr)))
  2586. goto exit;
  2587. UOBJ_REGISTER_RESOURCE(return_value, pTable, le_mapi_table);
  2588. exit:
  2589. LOG_END();
  2590. THROW_ON_ERROR();
  2591. }
  2592. ZEND_FUNCTION(mapi_message_setreadflag)
  2593. {
  2594. PMEASURE_FUNC;
  2595. LOG_BEGIN();
  2596. // params
  2597. zval *res = NULL;
  2598. LPMESSAGE pMessage = NULL;
  2599. long flag = 0;
  2600. RETVAL_FALSE;
  2601. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  2602. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &res, &flag) == FAILURE) return;
  2603. ZEND_FETCH_RESOURCE_C(pMessage, LPMESSAGE, &res, -1, name_mapi_message, le_mapi_message);
  2604. MAPI_G(hr) = pMessage->SetReadFlag(flag);
  2605. if (FAILED(MAPI_G(hr)))
  2606. goto exit;
  2607. RETVAL_TRUE;
  2608. exit:
  2609. LOG_END();
  2610. THROW_ON_ERROR();
  2611. }
  2612. /**
  2613. * Read the data from an attachment.
  2614. * @param Attachment resource
  2615. * @return Message
  2616. */
  2617. ZEND_FUNCTION(mapi_attach_openobj)
  2618. {
  2619. PMEASURE_FUNC;
  2620. LOG_BEGIN();
  2621. // params
  2622. zval *res = NULL;
  2623. LPATTACH pAttach = NULL;
  2624. long ulFlags = 0;
  2625. // return value
  2626. LPMESSAGE lpMessage = NULL;
  2627. RETVAL_FALSE;
  2628. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  2629. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &res, &ulFlags) == FAILURE) return;
  2630. ZEND_FETCH_RESOURCE_C(pAttach, LPATTACH, &res, -1, name_mapi_attachment, le_mapi_attachment);
  2631. MAPI_G(hr) = pAttach->OpenProperty(PR_ATTACH_DATA_OBJ, &IID_IMessage, 0, ulFlags, (LPUNKNOWN *) &lpMessage);
  2632. if (FAILED(MAPI_G(hr)))
  2633. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Fetching attachmentdata as object failed");
  2634. else
  2635. UOBJ_REGISTER_RESOURCE(return_value, lpMessage, le_mapi_message);
  2636. LOG_END();
  2637. THROW_ON_ERROR();
  2638. }
  2639. /**
  2640. * Function to get a Property ID from the name. The function expects an array
  2641. * with the property names or IDs.
  2642. *
  2643. *
  2644. */
  2645. ZEND_FUNCTION(mapi_getidsfromnames)
  2646. {
  2647. PMEASURE_FUNC;
  2648. LOG_BEGIN();
  2649. // params
  2650. zval *messageStore = NULL;
  2651. LPMDB lpMessageStore = NULL;
  2652. zval *propNameArray = NULL;
  2653. zval *guidArray = NULL;
  2654. // return value
  2655. memory_ptr<SPropTagArray> lpPropTagArray;
  2656. // local
  2657. int hashTotal = 0, i = 0;
  2658. memory_ptr<MAPINAMEID *> lppNamePropId;
  2659. zval **entry = NULL, **guidEntry = NULL;
  2660. HashTable *targetHash = NULL, *guidHash = NULL;
  2661. GUID guidOutlook = { 0x00062002, 0x0000, 0x0000, { 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}};
  2662. int multibytebufferlen = 0;
  2663. RETVAL_FALSE;
  2664. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  2665. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra|a", &messageStore, &propNameArray, &guidArray) == FAILURE) return;
  2666. ZEND_FETCH_RESOURCE_C(lpMessageStore, LPMDB, &messageStore, -1, name_mapi_msgstore, le_mapi_msgstore);
  2667. targetHash = Z_ARRVAL_P(propNameArray);
  2668. if(guidArray)
  2669. guidHash = Z_ARRVAL_P(guidArray);
  2670. // get the number of items in the array
  2671. hashTotal = zend_hash_num_elements(targetHash);
  2672. if (guidHash && hashTotal != zend_hash_num_elements(guidHash))
  2673. php_error_docref(NULL TSRMLS_CC, E_WARNING, "The array with the guids is not of the same size as the array with the ids");
  2674. // allocate memory to use
  2675. MAPI_G(hr) = MAPIAllocateBuffer(sizeof(LPMAPINAMEID) * hashTotal, &~lppNamePropId);
  2676. if (MAPI_G(hr) != hrSuccess)
  2677. goto exit;
  2678. // first reset the hash, so the pointer points to the first element.
  2679. zend_hash_internal_pointer_reset(targetHash);
  2680. if(guidHash)
  2681. zend_hash_internal_pointer_reset(guidHash);
  2682. for (i = 0; i < hashTotal; ++i) {
  2683. // Gets the element that exist at the current pointer.
  2684. zend_hash_get_current_data(targetHash,(void **) &entry);
  2685. if(guidHash)
  2686. zend_hash_get_current_data(guidHash, (void **) &guidEntry);
  2687. MAPI_G(hr) = MAPIAllocateMore(sizeof(MAPINAMEID),lppNamePropId,(void **) &lppNamePropId[i]);
  2688. if (MAPI_G(hr) != hrSuccess)
  2689. goto exit;
  2690. // fall back to a default GUID if the passed one is not good ..
  2691. lppNamePropId[i]->lpguid = &guidOutlook;
  2692. if(guidHash) {
  2693. if (guidEntry[0]->type != IS_STRING || sizeof(GUID) != guidEntry[0]->value.str.len) {
  2694. php_error_docref(NULL TSRMLS_CC, E_WARNING, "The GUID with index number %d that is passed is not of the right length, cannot convert to GUID", i);
  2695. } else {
  2696. MAPI_G(hr) = MAPIAllocateMore(sizeof(GUID),lppNamePropId,(void **) &lppNamePropId[i]->lpguid);
  2697. if (MAPI_G(hr) != hrSuccess)
  2698. goto exit;
  2699. memcpy(lppNamePropId[i]->lpguid, guidEntry[0]->value.str.val, sizeof(GUID));
  2700. }
  2701. }
  2702. switch(entry[0]->type)
  2703. {
  2704. case IS_LONG:
  2705. lppNamePropId[i]->ulKind = MNID_ID;
  2706. lppNamePropId[i]->Kind.lID = entry[0]->value.lval;
  2707. break;
  2708. case IS_STRING:
  2709. multibytebufferlen = mbstowcs(NULL, entry[0]->value.str.val, 0);
  2710. MAPI_G(hr) = MAPIAllocateMore((multibytebufferlen + 1) * sizeof(WCHAR), lppNamePropId,
  2711. (void **)&lppNamePropId[i]->Kind.lpwstrName);
  2712. if (MAPI_G(hr) != hrSuccess)
  2713. goto exit;
  2714. mbstowcs(lppNamePropId[i]->Kind.lpwstrName, entry[0]->value.str.val, multibytebufferlen + 1);
  2715. lppNamePropId[i]->ulKind = MNID_STRING;
  2716. break;
  2717. case IS_DOUBLE:
  2718. lppNamePropId[i]->ulKind = MNID_ID;
  2719. lppNamePropId[i]->Kind.lID = (LONG) entry[0]->value.dval;
  2720. break;
  2721. default:
  2722. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Entry is of an unknown type: %08X", entry[0]->type);
  2723. break;
  2724. }
  2725. // move the pointers of the hashtables forward.
  2726. zend_hash_move_forward(targetHash);
  2727. if(guidHash)
  2728. zend_hash_move_forward(guidHash);
  2729. }
  2730. MAPI_G(hr) = lpMessageStore->GetIDsFromNames(hashTotal, lppNamePropId, MAPI_CREATE, &~lpPropTagArray);
  2731. if (FAILED(MAPI_G(hr))) {
  2732. php_error_docref(NULL TSRMLS_CC, E_WARNING, "GetIDsFromNames failed with error code %08X", MAPI_G(hr));
  2733. goto exit;
  2734. } else {
  2735. array_init(return_value);
  2736. for (unsigned int i = 0; i < lpPropTagArray->cValues; ++i)
  2737. add_next_index_long(return_value, (LONG)lpPropTagArray->aulPropTag[i]);
  2738. }
  2739. exit:
  2740. LOG_END();
  2741. THROW_ON_ERROR();
  2742. }
  2743. ZEND_FUNCTION(mapi_setprops)
  2744. {
  2745. PMEASURE_FUNC;
  2746. LOG_BEGIN();
  2747. // params
  2748. zval *res = NULL, *propValueArray = NULL;
  2749. LPMAPIPROP lpMapiProp = NULL;
  2750. // local
  2751. int type = -1;
  2752. ULONG cValues = 0;
  2753. memory_ptr<SPropValue> pPropValueArray;
  2754. RETVAL_FALSE;
  2755. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  2756. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra", &res, &propValueArray) == FAILURE) return;
  2757. zend_list_find(res->value.lval, &type);
  2758. if(type == le_mapi_message) {
  2759. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPMESSAGE, &res, -1, name_mapi_message, le_mapi_message);
  2760. } else if (type == le_mapi_folder) {
  2761. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPMAPIFOLDER, &res, -1, name_mapi_folder, le_mapi_folder);
  2762. } else if (type == le_mapi_attachment) {
  2763. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPATTACH, &res, -1, name_mapi_attachment, le_mapi_attachment);
  2764. } else if (type == le_mapi_msgstore) {
  2765. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  2766. } else if (type == le_mapi_property) {
  2767. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPMAPIPROP, &res, -1, name_mapi_property, le_mapi_property);
  2768. } else {
  2769. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown resource type");
  2770. goto exit;
  2771. }
  2772. MAPI_G(hr) = PHPArraytoPropValueArray(propValueArray, NULL, &cValues, &~pPropValueArray TSRMLS_CC);
  2773. if (MAPI_G(hr) != hrSuccess) {
  2774. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to convert PHP property to MAPI");
  2775. goto exit;
  2776. }
  2777. MAPI_G(hr) = lpMapiProp->SetProps(cValues, pPropValueArray, NULL);
  2778. if (FAILED(MAPI_G(hr)))
  2779. goto exit;
  2780. RETVAL_TRUE;
  2781. exit:
  2782. LOG_END();
  2783. THROW_ON_ERROR();
  2784. }
  2785. ZEND_FUNCTION(mapi_copyto)
  2786. {
  2787. PMEASURE_FUNC;
  2788. LOG_BEGIN();
  2789. memory_ptr<SPropTagArray> lpExcludeProps;
  2790. LPMAPIPROP lpSrcObj = NULL;
  2791. LPVOID lpDstObj = NULL;
  2792. LPCIID lpInterface = NULL;
  2793. memory_ptr<IID> lpExcludeIIDs;
  2794. ULONG cExcludeIIDs = 0;
  2795. // params
  2796. zval *srcres = NULL;
  2797. zval *dstres = NULL;
  2798. zval *excludeprops = NULL;
  2799. zval *excludeiid = NULL;
  2800. long flags = 0;
  2801. // local
  2802. int type = -1;
  2803. RETVAL_FALSE;
  2804. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  2805. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "raar|l", &srcres, &excludeiid, &excludeprops, &dstres, &flags) == FAILURE) return;
  2806. zend_list_find(srcres->value.lval, &type);
  2807. if(type == le_mapi_message) {
  2808. ZEND_FETCH_RESOURCE_C(lpSrcObj, LPMESSAGE, &srcres, -1, name_mapi_message, le_mapi_message);
  2809. } else if (type == le_mapi_folder) {
  2810. ZEND_FETCH_RESOURCE_C(lpSrcObj, LPMAPIFOLDER, &srcres, -1, name_mapi_folder, le_mapi_folder);
  2811. } else if (type == le_mapi_attachment) {
  2812. ZEND_FETCH_RESOURCE_C(lpSrcObj, LPATTACH, &srcres, -1, name_mapi_attachment, le_mapi_attachment);
  2813. } else if (type == le_mapi_msgstore) {
  2814. ZEND_FETCH_RESOURCE_C(lpSrcObj, LPMDB, &srcres, -1, name_mapi_msgstore, le_mapi_msgstore);
  2815. } else {
  2816. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown resource type");
  2817. goto exit;
  2818. }
  2819. MAPI_G(hr) = PHPArraytoGUIDArray(excludeiid, NULL, &cExcludeIIDs, &~lpExcludeIIDs TSRMLS_CC);
  2820. if (MAPI_G(hr) != hrSuccess) {
  2821. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to parse IIDs");
  2822. goto exit;
  2823. }
  2824. MAPI_G(hr) = PHPArraytoPropTagArray(excludeprops, NULL, &~lpExcludeProps TSRMLS_CC);
  2825. if (MAPI_G(hr) != hrSuccess) {
  2826. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to parse property tag array");
  2827. goto exit;
  2828. }
  2829. zend_list_find(dstres->value.lval, &type);
  2830. if(type == le_mapi_message) {
  2831. ZEND_FETCH_RESOURCE_C(lpDstObj, LPMESSAGE, &dstres, -1, name_mapi_message, le_mapi_message);
  2832. lpInterface = &IID_IMessage;
  2833. } else if (type == le_mapi_folder) {
  2834. ZEND_FETCH_RESOURCE_C(lpDstObj, LPMAPIFOLDER, &dstres, -1, name_mapi_folder, le_mapi_folder);
  2835. lpInterface = &IID_IMAPIFolder;
  2836. } else if (type == le_mapi_attachment) {
  2837. ZEND_FETCH_RESOURCE_C(lpDstObj, LPATTACH, &dstres, -1, name_mapi_attachment, le_mapi_attachment);
  2838. lpInterface = &IID_IAttachment;
  2839. } else if (type == le_mapi_msgstore) {
  2840. ZEND_FETCH_RESOURCE_C(lpDstObj, LPMDB, &dstres, -1, name_mapi_msgstore, le_mapi_msgstore);
  2841. lpInterface = &IID_IMsgStore;
  2842. } else {
  2843. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown resource type");
  2844. goto exit;
  2845. }
  2846. MAPI_G(hr) = lpSrcObj->CopyTo(cExcludeIIDs, lpExcludeIIDs, lpExcludeProps, 0, NULL, lpInterface, lpDstObj, flags, NULL);
  2847. if (FAILED(MAPI_G(hr)))
  2848. goto exit;
  2849. RETVAL_TRUE;
  2850. exit:
  2851. LOG_END();
  2852. THROW_ON_ERROR();
  2853. }
  2854. ZEND_FUNCTION(mapi_savechanges)
  2855. {
  2856. PMEASURE_FUNC;
  2857. LOG_BEGIN();
  2858. // params
  2859. zval *res = NULL;
  2860. LPMAPIPROP lpMapiProp = NULL;
  2861. long flags = KEEP_OPEN_READWRITE;
  2862. // local
  2863. int type = -1;
  2864. RETVAL_FALSE;
  2865. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  2866. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &res, &flags) == FAILURE) return;
  2867. if (res->type != IS_RESOURCE) {
  2868. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unsupported case !IS_RESOURCE.");
  2869. goto exit;
  2870. }
  2871. zend_list_find(res->value.lval, &type);
  2872. if (type == le_mapi_message) {
  2873. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPMESSAGE, &res, -1, name_mapi_message, le_mapi_message);
  2874. } else if (type == le_mapi_folder) {
  2875. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPMAPIFOLDER, &res, -1, name_mapi_folder, le_mapi_folder);
  2876. } else if (type == le_mapi_attachment) {
  2877. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPATTACH, &res, -1, name_mapi_attachment, le_mapi_attachment);
  2878. } else if (type == le_mapi_msgstore) {
  2879. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  2880. } else if (type == le_mapi_property) {
  2881. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPMAPIPROP, &res, -1, name_mapi_property, le_mapi_property);
  2882. } else {
  2883. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Resource does not exist...");
  2884. goto exit;
  2885. }
  2886. MAPI_G(hr) = lpMapiProp->SaveChanges(flags);
  2887. if (FAILED(MAPI_G(hr)))
  2888. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to save the object %08X", MAPI_G(hr));
  2889. else
  2890. RETVAL_TRUE;
  2891. exit:
  2892. LOG_END();
  2893. THROW_ON_ERROR();
  2894. }
  2895. ZEND_FUNCTION(mapi_deleteprops)
  2896. {
  2897. PMEASURE_FUNC;
  2898. LOG_BEGIN();
  2899. // params
  2900. zval *res = NULL, *propTagArray = NULL;
  2901. LPMAPIPROP lpMapiProp = NULL;
  2902. memory_ptr<SPropTagArray> lpTagArray;
  2903. // local
  2904. int type = -1;
  2905. RETVAL_FALSE;
  2906. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  2907. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra", &res, &propTagArray) == FAILURE) return;
  2908. zend_list_find(res->value.lval, &type);
  2909. if(type == le_mapi_message) {
  2910. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPMESSAGE, &res, -1, name_mapi_message, le_mapi_message);
  2911. } else if (type == le_mapi_folder) {
  2912. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPMAPIFOLDER, &res, -1, name_mapi_folder, le_mapi_folder);
  2913. } else if (type == le_mapi_attachment) {
  2914. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPATTACH, &res, -1, name_mapi_attachment, le_mapi_attachment);
  2915. } else if (type == le_mapi_msgstore) {
  2916. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  2917. } else {
  2918. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Resource does not exist...");
  2919. goto exit;
  2920. }
  2921. MAPI_G(hr) = PHPArraytoPropTagArray(propTagArray, NULL, &~lpTagArray TSRMLS_CC);
  2922. if (MAPI_G(hr) != hrSuccess) {
  2923. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to convert the PHP Array");
  2924. goto exit;
  2925. }
  2926. MAPI_G(hr) = lpMapiProp->DeleteProps(lpTagArray, NULL);
  2927. if(MAPI_G(hr) != hrSuccess)
  2928. goto exit;
  2929. RETVAL_TRUE;
  2930. exit:
  2931. LOG_END();
  2932. THROW_ON_ERROR();
  2933. }
  2934. ZEND_FUNCTION(mapi_openproperty)
  2935. {
  2936. PMEASURE_FUNC;
  2937. LOG_BEGIN();
  2938. // params
  2939. zval *res = NULL;
  2940. LPMAPIPROP lpMapiProp = NULL;
  2941. long proptag = 0, flags = 0, interfaceflags = 0; // open default readable
  2942. char *guidStr = NULL; // guid is given as a char array
  2943. ULONG guidLen = 0;
  2944. // return value
  2945. IUnknown* lpUnk = NULL;
  2946. // local
  2947. LPGUID lpGUID = NULL; // pointer to string param or static guid
  2948. int type = -1;
  2949. bool bBackwardCompatible = false;
  2950. object_ptr<IStream> lpStream;
  2951. RETVAL_FALSE;
  2952. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  2953. if(ZEND_NUM_ARGS() == 2) {
  2954. // BACKWARD COMPATIBILITY MODE.. this means that we just read the entire stream and return it as a string
  2955. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &res, &proptag) == FAILURE) return;
  2956. bBackwardCompatible = true;
  2957. guidStr = (char *)&IID_IStream;
  2958. guidLen = sizeof(GUID);
  2959. interfaceflags = 0;
  2960. flags = 0;
  2961. } else if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlsll", &res, &proptag, &guidStr, &guidLen, &interfaceflags, &flags) == FAILURE) {
  2962. return;
  2963. }
  2964. zend_list_find(res->value.lval, &type);
  2965. if(type == le_mapi_message) {
  2966. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPMESSAGE, &res, -1, name_mapi_message, le_mapi_message);
  2967. } else if (type == le_mapi_folder) {
  2968. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPMAPIFOLDER, &res, -1, name_mapi_folder, le_mapi_folder);
  2969. } else if (type == le_mapi_attachment) {
  2970. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPATTACH, &res, -1, name_mapi_attachment, le_mapi_attachment);
  2971. } else if (type == le_mapi_msgstore) {
  2972. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  2973. } else {
  2974. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  2975. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Resource is not a valid MAPI resource");
  2976. goto exit;
  2977. }
  2978. if (guidLen != sizeof(GUID)) {
  2979. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  2980. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified interface is not a valid interface identifier (wrong size)");
  2981. goto exit;
  2982. }
  2983. lpGUID = (LPGUID) guidStr;
  2984. MAPI_G(hr) = lpMapiProp->OpenProperty(proptag, lpGUID, interfaceflags, flags, (LPUNKNOWN *) &lpUnk);
  2985. if (MAPI_G(hr) != hrSuccess)
  2986. goto exit;
  2987. if (*lpGUID == IID_IStream) {
  2988. if(bBackwardCompatible) {
  2989. STATSTG stat;
  2990. char *data = NULL;
  2991. ULONG cRead;
  2992. // do not use queryinterface, since we don't return the stream, but the contents
  2993. lpStream.reset((IStream *)lpUnk, false);
  2994. MAPI_G(hr) = lpStream->Stat(&stat, STATFLAG_NONAME);
  2995. if(MAPI_G(hr) != hrSuccess)
  2996. goto exit;
  2997. // Use emalloc so that it can be returned directly to PHP without copying
  2998. data = (char *)emalloc(stat.cbSize.LowPart);
  2999. if (data == NULL) {
  3000. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to allocate memory");
  3001. MAPI_G(hr) = MAPI_E_NOT_ENOUGH_MEMORY;
  3002. goto exit;
  3003. }
  3004. MAPI_G(hr) = lpStream->Read(data, (ULONG)stat.cbSize.LowPart, &cRead);
  3005. if(MAPI_G(hr)) {
  3006. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to read the data");
  3007. goto exit;
  3008. }
  3009. RETVAL_STRINGL(data, cRead, 0);
  3010. } else {
  3011. ZEND_REGISTER_RESOURCE(return_value, lpUnk, le_istream);
  3012. }
  3013. } else if(*lpGUID == IID_IMAPITable) {
  3014. UOBJ_REGISTER_RESOURCE(return_value, lpUnk, le_mapi_table);
  3015. } else if(*lpGUID == IID_IMessage) {
  3016. UOBJ_REGISTER_RESOURCE(return_value, lpUnk, le_mapi_message);
  3017. } else if(*lpGUID == IID_IMAPIFolder) {
  3018. UOBJ_REGISTER_RESOURCE(return_value, lpUnk, le_mapi_folder);
  3019. } else if(*lpGUID == IID_IMsgStore) {
  3020. UOBJ_REGISTER_RESOURCE(return_value, lpUnk, le_mapi_msgstore);
  3021. } else if(*lpGUID == IID_IExchangeModifyTable) {
  3022. UOBJ_REGISTER_RESOURCE(return_value, lpUnk, le_mapi_modifytable);
  3023. } else if(*lpGUID == IID_IExchangeExportChanges) {
  3024. UOBJ_REGISTER_RESOURCE(return_value, lpUnk, le_mapi_exportchanges);
  3025. } else if(*lpGUID == IID_IExchangeImportHierarchyChanges) {
  3026. UOBJ_REGISTER_RESOURCE(return_value, lpUnk, le_mapi_importhierarchychanges);
  3027. } else if(*lpGUID == IID_IExchangeImportContentsChanges) {
  3028. UOBJ_REGISTER_RESOURCE(return_value, lpUnk, le_mapi_importcontentschanges);
  3029. } else {
  3030. php_error_docref(NULL TSRMLS_CC, E_WARNING, "The openproperty call succeeded, but the PHP extension is unable to handle the requested interface");
  3031. lpUnk->Release();
  3032. MAPI_G(hr) = MAPI_E_NO_SUPPORT;
  3033. goto exit;
  3034. }
  3035. exit:
  3036. LOG_END();
  3037. THROW_ON_ERROR();
  3038. }
  3039. /*
  3040. Function that get a resource and check what type it is, when the type is a subclass from IMAPIProp
  3041. it will use it to do a getProps.
  3042. */
  3043. ZEND_FUNCTION(mapi_getprops)
  3044. {
  3045. PMEASURE_FUNC;
  3046. LOG_BEGIN();
  3047. // params
  3048. LPMAPIPROP lpMapiProp = NULL;
  3049. zval *res = NULL, *tagArray = NULL;
  3050. ULONG cValues = 0;
  3051. memory_ptr<SPropValue> lpPropValues;
  3052. memory_ptr<SPropTagArray> lpTagArray;
  3053. // return value
  3054. zval *zval_prop_value = NULL;
  3055. // local
  3056. int type = -1; // list entry number of the resource.
  3057. RETVAL_FALSE;
  3058. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  3059. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|a", &res, &tagArray) == FAILURE) return;
  3060. zend_list_find(res->value.lval, &type);
  3061. if(type == le_mapi_message) {
  3062. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPMESSAGE, &res, -1, name_mapi_message, le_mapi_message);
  3063. } else if (type == le_mapi_folder) {
  3064. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPMAPIFOLDER, &res, -1, name_mapi_folder, le_mapi_folder);
  3065. } else if (type == le_mapi_attachment) {
  3066. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPATTACH, &res, -1, name_mapi_attachment, le_mapi_attachment);
  3067. } else if (type == le_mapi_msgstore) {
  3068. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  3069. } else if( type == le_mapi_mailuser) {
  3070. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPMAILUSER, &res, -1, name_mapi_mailuser, le_mapi_mailuser);
  3071. } else if( type == le_mapi_distlist) {
  3072. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPDISTLIST, &res, -1, name_mapi_distlist, le_mapi_distlist);
  3073. } else if( type == le_mapi_abcont) {
  3074. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPABCONT, &res, -1, name_mapi_abcont, le_mapi_abcont);
  3075. } else if( type == le_mapi_property) {
  3076. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPMAPIPROP, &res, -1, name_mapi_property, le_mapi_property);
  3077. } else {
  3078. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Resource is not a valid MAPI resource");
  3079. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  3080. goto exit;
  3081. }
  3082. if(tagArray) {
  3083. MAPI_G(hr) = PHPArraytoPropTagArray(tagArray, NULL, &~lpTagArray TSRMLS_CC);
  3084. if (MAPI_G(hr) != hrSuccess) {
  3085. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to parse property tag array");
  3086. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  3087. goto exit;
  3088. }
  3089. } else {
  3090. lpTagArray = NULL;
  3091. }
  3092. MAPI_G(hr) = lpMapiProp->GetProps(lpTagArray, 0, &cValues, &~lpPropValues);
  3093. if (FAILED(MAPI_G(hr)))
  3094. goto exit;
  3095. MAPI_G(hr) = PropValueArraytoPHPArray(cValues, lpPropValues, &zval_prop_value TSRMLS_CC);
  3096. if (MAPI_G(hr) != hrSuccess) {
  3097. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to convert properties to PHP values");
  3098. goto exit;
  3099. }
  3100. RETVAL_ZVAL(zval_prop_value, 0, 0);
  3101. FREE_ZVAL(zval_prop_value);
  3102. exit:
  3103. LOG_END();
  3104. THROW_ON_ERROR();
  3105. }
  3106. ZEND_FUNCTION(mapi_getnamesfromids)
  3107. {
  3108. PMEASURE_FUNC;
  3109. LOG_BEGIN();
  3110. // params
  3111. zval *res, *array;
  3112. LPMDB pMDB = NULL;
  3113. memory_ptr<SPropTagArray> lpPropTags;
  3114. // return value
  3115. // local
  3116. ULONG cPropNames = 0;
  3117. memory_ptr<MAPINAMEID *> pPropNames;
  3118. ULONG count = 0;
  3119. zval *prop;
  3120. RETVAL_FALSE;
  3121. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  3122. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra", &res, &array) == FAILURE) return;
  3123. ZEND_FETCH_RESOURCE_C(pMDB, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  3124. MAPI_G(hr) = PHPArraytoPropTagArray(array, NULL, &~lpPropTags TSRMLS_CC);
  3125. if (MAPI_G(hr) != hrSuccess) {
  3126. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to convert proptag array from PHP array");
  3127. goto exit;
  3128. }
  3129. MAPI_G(hr) = pMDB->GetNamesFromIDs(&+lpPropTags, NULL, 0, &cPropNames, &~pPropNames);
  3130. if(FAILED(MAPI_G(hr)))
  3131. goto exit;
  3132. // This code should be moved to typeconversions.cpp
  3133. array_init(return_value);
  3134. for (count = 0; count < lpPropTags->cValues; ++count) {
  3135. if (pPropNames[count] == NULL)
  3136. continue; // FIXME: the returned array is smaller than the passed array!
  3137. char buffer[20];
  3138. snprintf(buffer, 20, "%i", lpPropTags->aulPropTag[count]);
  3139. MAKE_STD_ZVAL(prop);
  3140. array_init(prop);
  3141. add_assoc_stringl(prop, "guid", (char*)pPropNames[count]->lpguid, sizeof(GUID), 1);
  3142. if (pPropNames[count]->ulKind == MNID_ID) {
  3143. add_assoc_long(prop, "id", pPropNames[count]->Kind.lID);
  3144. } else {
  3145. int slen;
  3146. char *buffer;
  3147. slen = wcstombs(NULL, pPropNames[count]->Kind.lpwstrName, 0); // find string size
  3148. ++slen; // add terminator
  3149. buffer = new char[slen]; // alloc
  3150. wcstombs(buffer, pPropNames[count]->Kind.lpwstrName, slen); // convert & terminate
  3151. add_assoc_string(prop, "name", buffer, 1);
  3152. delete [] buffer;
  3153. }
  3154. add_assoc_zval(return_value, buffer, prop);
  3155. }
  3156. exit:
  3157. LOG_END();
  3158. THROW_ON_ERROR();
  3159. }
  3160. /**
  3161. * Receives a string of compressed RTF. First turn this string into a Stream and than
  3162. * decompres.
  3163. *
  3164. */
  3165. ZEND_FUNCTION(mapi_decompressrtf)
  3166. {
  3167. PMEASURE_FUNC;
  3168. LOG_BEGIN();
  3169. // params
  3170. char * rtfBuffer = NULL;
  3171. unsigned int rtfBufferLen = 0;
  3172. // return value
  3173. std::unique_ptr<char[]> htmlbuf;
  3174. // local
  3175. ULONG actualWritten = 0;
  3176. ULONG cbRead = 0;
  3177. object_ptr<IStream> pStream, deCompressedStream;
  3178. LARGE_INTEGER begin = { { 0, 0 } };
  3179. unsigned int bufsize = 10240;
  3180. std::string strUncompressed;
  3181. RETVAL_FALSE;
  3182. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  3183. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &rtfBuffer, &rtfBufferLen) == FAILURE) return;
  3184. // make and fill the stream
  3185. MAPI_G(hr) = CreateStreamOnHGlobal(nullptr, true, &~pStream);
  3186. if (MAPI_G(hr) != hrSuccess || pStream == NULL) {
  3187. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to CreateStreamOnHGlobal %x", MAPI_G(hr));
  3188. goto exit;
  3189. }
  3190. pStream->Write(rtfBuffer, rtfBufferLen, &actualWritten);
  3191. pStream->Commit(0);
  3192. pStream->Seek(begin, SEEK_SET, NULL);
  3193. MAPI_G(hr) = WrapCompressedRTFStream(pStream, 0, &~deCompressedStream);
  3194. if (MAPI_G(hr) != hrSuccess) {
  3195. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to wrap uncompressed stream %x", MAPI_G(hr));
  3196. goto exit;
  3197. }
  3198. // bufsize is the size of the buffer we've allocated, and htmlsize is the
  3199. // amount of text we've read in so far. If our buffer wasn't big enough,
  3200. // we enlarge it and continue. We have to do this, instead of allocating
  3201. // it up front, because Stream::Stat() doesn't work for the unc.stream
  3202. bufsize = max(rtfBufferLen * 2, bufsize);
  3203. htmlbuf.reset(new char[bufsize]);
  3204. while(1) {
  3205. MAPI_G(hr) = deCompressedStream->Read(htmlbuf.get(), bufsize, &cbRead);
  3206. if (MAPI_G(hr) != hrSuccess) {
  3207. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Read from uncompressed stream failed %x", MAPI_G(hr));
  3208. goto exit;
  3209. }
  3210. if (cbRead == 0)
  3211. break;
  3212. strUncompressed.append(htmlbuf.get(), cbRead);
  3213. }
  3214. RETVAL_STRINGL((char *)strUncompressed.c_str(), strUncompressed.size(), 1);
  3215. exit:
  3216. LOG_END();
  3217. THROW_ON_ERROR();
  3218. }
  3219. /**
  3220. *
  3221. * Opens the rules table from the default INBOX of the given store
  3222. *
  3223. */
  3224. ZEND_FUNCTION(mapi_folder_openmodifytable) {
  3225. PMEASURE_FUNC;
  3226. LOG_BEGIN();
  3227. // params
  3228. zval *res;
  3229. LPMAPIFOLDER lpInbox = NULL;
  3230. // return value
  3231. LPEXCHANGEMODIFYTABLE lpRulesTable = NULL;
  3232. // locals
  3233. RETVAL_FALSE;
  3234. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  3235. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) return;
  3236. ZEND_FETCH_RESOURCE_C(lpInbox, LPMAPIFOLDER, &res, -1, name_mapi_folder, le_mapi_folder);
  3237. MAPI_G(hr) = lpInbox->OpenProperty(PR_RULES_TABLE, &IID_IExchangeModifyTable, 0, 0, (LPUNKNOWN *)&lpRulesTable);
  3238. if (MAPI_G(hr) != hrSuccess)
  3239. goto exit;
  3240. UOBJ_REGISTER_RESOURCE(return_value, lpRulesTable, le_mapi_modifytable);
  3241. exit:
  3242. LOG_END();
  3243. THROW_ON_ERROR();
  3244. }
  3245. ZEND_FUNCTION(mapi_folder_getsearchcriteria) {
  3246. PMEASURE_FUNC;
  3247. LOG_BEGIN();
  3248. // params
  3249. zval *res = NULL;
  3250. zval *restriction = NULL;
  3251. zval *folderlist = NULL;
  3252. LPMAPIFOLDER lpFolder = NULL;
  3253. long ulFlags = 0;
  3254. // local
  3255. memory_ptr<SRestriction> lpRestriction;
  3256. memory_ptr<ENTRYLIST> lpFolderList;
  3257. ULONG ulSearchState = 0;
  3258. RETVAL_FALSE;
  3259. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  3260. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &res, &ulFlags) == FAILURE) return;
  3261. ZEND_FETCH_RESOURCE_C(lpFolder, LPMAPIFOLDER, &res, -1, name_mapi_folder, le_mapi_folder);
  3262. MAPI_G(hr) = lpFolder->GetSearchCriteria(ulFlags, &~lpRestriction, &~lpFolderList, &ulSearchState);
  3263. if (MAPI_G(hr) != hrSuccess)
  3264. goto exit;
  3265. MAPI_G(hr) = SRestrictiontoPHPArray(lpRestriction, 0, &restriction TSRMLS_CC);
  3266. if (MAPI_G(hr) != hrSuccess)
  3267. goto exit;
  3268. MAPI_G(hr) = SBinaryArraytoPHPArray(lpFolderList, &folderlist TSRMLS_CC);
  3269. if (MAPI_G(hr) != hrSuccess)
  3270. goto exit;
  3271. array_init(return_value);
  3272. add_assoc_zval(return_value, "restriction", restriction);
  3273. add_assoc_zval(return_value, "folderlist", folderlist);
  3274. add_assoc_long(return_value, "searchstate", ulSearchState);
  3275. exit:
  3276. LOG_END();
  3277. THROW_ON_ERROR();
  3278. }
  3279. ZEND_FUNCTION(mapi_folder_setsearchcriteria) {
  3280. PMEASURE_FUNC;
  3281. LOG_BEGIN();
  3282. // param
  3283. zval *res = NULL;
  3284. zval *restriction = NULL;
  3285. zval *folderlist = NULL;
  3286. long ulFlags = 0;
  3287. // local
  3288. LPMAPIFOLDER lpFolder = NULL;
  3289. memory_ptr<ENTRYLIST> lpFolderList;
  3290. memory_ptr<SRestriction> lpRestriction;
  3291. RETVAL_FALSE;
  3292. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  3293. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "raal", &res, &restriction, &folderlist, &ulFlags) == FAILURE) return;
  3294. ZEND_FETCH_RESOURCE_C(lpFolder, LPMAPIFOLDER, &res, -1, name_mapi_folder, le_mapi_folder);
  3295. MAPI_G(hr) = PHPArraytoSRestriction(restriction, NULL, &~lpRestriction TSRMLS_CC);
  3296. if (MAPI_G(hr) != hrSuccess)
  3297. goto exit;
  3298. MAPI_G(hr) = PHPArraytoSBinaryArray(folderlist, NULL, &~lpFolderList TSRMLS_CC);
  3299. if (MAPI_G(hr) != hrSuccess)
  3300. goto exit;
  3301. MAPI_G(hr) = lpFolder->SetSearchCriteria(lpRestriction, lpFolderList, ulFlags);
  3302. if (MAPI_G(hr) != hrSuccess)
  3303. goto exit;
  3304. RETVAL_TRUE;
  3305. exit:
  3306. LOG_END();
  3307. THROW_ON_ERROR();
  3308. }
  3309. /**
  3310. *
  3311. * returns a read-only view on the rules table
  3312. *
  3313. */
  3314. ZEND_FUNCTION(mapi_rules_gettable) {
  3315. PMEASURE_FUNC;
  3316. LOG_BEGIN();
  3317. // params
  3318. zval *res;
  3319. LPEXCHANGEMODIFYTABLE lpRulesTable = NULL;
  3320. // return value
  3321. object_ptr<IMAPITable> lpRulesView;
  3322. // locals
  3323. static constexpr const SizedSPropTagArray(11, sptaRules) =
  3324. {11, {PR_RULE_ID, PR_RULE_IDS, PR_RULE_SEQUENCE, PR_RULE_STATE,
  3325. PR_RULE_USER_FLAGS, PR_RULE_CONDITION, PR_RULE_ACTIONS,
  3326. PR_RULE_PROVIDER, PR_RULE_NAME, PR_RULE_LEVEL,
  3327. PR_RULE_PROVIDER_DATA}};
  3328. static constexpr const SizedSSortOrderSet(1, sosRules) =
  3329. {1, 0, 0, {{PR_RULE_SEQUENCE, TABLE_SORT_ASCEND}}};
  3330. ECRulesTableProxy *lpRulesTableProxy = NULL;
  3331. RETVAL_FALSE;
  3332. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  3333. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) return;
  3334. ZEND_FETCH_RESOURCE_C(lpRulesTable, LPEXCHANGEMODIFYTABLE, &res, -1, name_mapi_modifytable, le_mapi_modifytable);
  3335. MAPI_G(hr) = lpRulesTable->GetTable(0, &~lpRulesView);
  3336. if (MAPI_G(hr) != hrSuccess)
  3337. goto exit;
  3338. MAPI_G(hr) = lpRulesView->SetColumns(sptaRules, 0);
  3339. if (MAPI_G(hr) != hrSuccess)
  3340. goto exit;
  3341. MAPI_G(hr) = lpRulesView->SortTable(sosRules, 0);
  3342. if (MAPI_G(hr) != hrSuccess)
  3343. goto exit;
  3344. MAPI_G(hr) = ECRulesTableProxy::Create(lpRulesView, &lpRulesTableProxy);
  3345. if (MAPI_G(hr) != hrSuccess)
  3346. goto exit;
  3347. MAPI_G(hr) = lpRulesTableProxy->QueryInterface(IID_IMAPITable, &~lpRulesView);
  3348. if (MAPI_G(hr) != hrSuccess)
  3349. goto exit;
  3350. UOBJ_REGISTER_RESOURCE(return_value, lpRulesView.release(), le_mapi_table);
  3351. exit:
  3352. LOG_END();
  3353. THROW_ON_ERROR();
  3354. }
  3355. /**
  3356. *
  3357. * Add's, modifies or deletes rows from the rules table
  3358. *
  3359. */
  3360. ZEND_FUNCTION(mapi_rules_modifytable) {
  3361. PMEASURE_FUNC;
  3362. LOG_BEGIN();
  3363. // params
  3364. zval *res;
  3365. LPEXCHANGEMODIFYTABLE lpRulesTable = NULL;
  3366. zval *rows;
  3367. LPROWLIST lpRowList = NULL;
  3368. long ulFlags = 0;
  3369. // return value
  3370. // locals
  3371. RETVAL_FALSE;
  3372. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  3373. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra|l", &res, &rows, &ulFlags) == FAILURE) return;
  3374. ZEND_FETCH_RESOURCE_C(lpRulesTable, LPEXCHANGEMODIFYTABLE, &res, -1, name_mapi_modifytable, le_mapi_modifytable);
  3375. MAPI_G(hr) = PHPArraytoRowList(rows, NULL, &lpRowList TSRMLS_CC);
  3376. if (MAPI_G(hr) != hrSuccess) {
  3377. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to parse rowlist");
  3378. goto exit;
  3379. }
  3380. MAPI_G(hr) = lpRulesTable->ModifyTable(ulFlags, lpRowList);
  3381. if (MAPI_G(hr) != hrSuccess)
  3382. goto exit;
  3383. RETVAL_TRUE;
  3384. exit:
  3385. if (lpRowList)
  3386. FreeProws((LPSRowSet)lpRowList);
  3387. LOG_END();
  3388. THROW_ON_ERROR();
  3389. }
  3390. ZEND_FUNCTION(mapi_zarafa_createuser)
  3391. {
  3392. PMEASURE_FUNC;
  3393. LOG_BEGIN();
  3394. // params
  3395. zval *res = NULL;
  3396. LPMDB lpMsgStore = NULL;
  3397. char *lpszUsername = NULL;
  3398. unsigned int ulUsernameLen = 0;
  3399. char *lpszFullname = NULL;
  3400. unsigned int ulFullname = 0;
  3401. char *lpszEmail = NULL;
  3402. unsigned int ulEmail = 0;
  3403. char *lpszPassword = NULL;
  3404. unsigned int ulPassword = 0;
  3405. long ulIsNonactive = false;
  3406. long ulIsAdmin = false;
  3407. // return value
  3408. ULONG cbUserId = 0;
  3409. memory_ptr<ENTRYID> lpUserId;
  3410. // local
  3411. IECUnknown *lpUnknown = NULL;
  3412. object_ptr<IECServiceAdmin> lpServiceAdmin;
  3413. ECUSER sUser = { 0 };
  3414. RETVAL_FALSE;
  3415. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  3416. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rssss|ll", &res,
  3417. &lpszUsername, &ulUsernameLen,
  3418. &lpszPassword, &ulPassword,
  3419. &lpszFullname, &ulFullname,
  3420. &lpszEmail, &ulEmail,
  3421. &ulIsNonactive, &ulIsAdmin) == FAILURE) return;
  3422. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  3423. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  3424. if(MAPI_G(hr) != hrSuccess) {
  3425. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano store");
  3426. goto exit;
  3427. }
  3428. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECServiceAdmin, &~lpServiceAdmin);
  3429. if(MAPI_G(hr) != hrSuccess) {
  3430. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object does not support the IECServiceAdmin interface");
  3431. goto exit;
  3432. }
  3433. //FIXME: Check the values
  3434. sUser.lpszUsername = (TCHAR*)lpszUsername;
  3435. sUser.lpszMailAddress = (TCHAR*)lpszEmail;
  3436. sUser.lpszPassword = (TCHAR*)lpszPassword;
  3437. sUser.ulObjClass = (ulIsNonactive ? NONACTIVE_USER : ACTIVE_USER);
  3438. sUser.lpszFullName = (TCHAR*)lpszFullname;
  3439. sUser.ulIsAdmin = ulIsAdmin;
  3440. MAPI_G(hr) = lpServiceAdmin->CreateUser(&sUser, 0, &cbUserId, &~lpUserId);
  3441. if(MAPI_G(hr) != hrSuccess)
  3442. goto exit;
  3443. RETVAL_TRUE;
  3444. exit:
  3445. LOG_END();
  3446. THROW_ON_ERROR();
  3447. }
  3448. ZEND_FUNCTION(mapi_zarafa_setuser)
  3449. {
  3450. PMEASURE_FUNC;
  3451. LOG_BEGIN();
  3452. // params
  3453. zval *res = NULL;
  3454. LPMDB lpMsgStore = NULL;
  3455. LPENTRYID lpUserId = NULL;
  3456. unsigned int cbUserId = 0;
  3457. char *lpszUsername = NULL;
  3458. unsigned int ulUsername = 0;
  3459. char *lpszFullname = NULL;
  3460. unsigned int ulFullname = 0;
  3461. char *lpszEmail = NULL;
  3462. unsigned int ulEmail = 0;
  3463. char *lpszPassword = NULL;
  3464. unsigned int ulPassword = 0;
  3465. long ulIsNonactive = 0;
  3466. long ulIsAdmin = 0;
  3467. // local
  3468. IECUnknown *lpUnknown = NULL;
  3469. object_ptr<IECServiceAdmin> lpServiceAdmin;
  3470. ECUSER sUser;
  3471. RETVAL_FALSE;
  3472. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  3473. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsssssll", &res, &lpUserId, &cbUserId, &lpszUsername, &ulUsername, &lpszFullname, &ulFullname, &lpszEmail, &ulEmail, &lpszPassword, &ulPassword, &ulIsNonactive, &ulIsAdmin) == FAILURE) return;
  3474. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  3475. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  3476. if(MAPI_G(hr) != hrSuccess) {
  3477. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano store");
  3478. goto exit;
  3479. }
  3480. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECServiceAdmin, &~lpServiceAdmin);
  3481. if(MAPI_G(hr) != hrSuccess) {
  3482. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object does not support the IECServiceAdmin interface");
  3483. goto exit;
  3484. }
  3485. //FIXME: Check the values
  3486. memset(&sUser, 0, sizeof(ECUSER));
  3487. sUser.lpszUsername = (TCHAR*)lpszUsername;
  3488. sUser.lpszPassword = (TCHAR*)lpszPassword;
  3489. sUser.lpszMailAddress = (TCHAR*)lpszEmail;
  3490. sUser.lpszFullName = (TCHAR*)lpszFullname;
  3491. sUser.sUserId.lpb = (unsigned char*)lpUserId;
  3492. sUser.sUserId.cb = cbUserId;
  3493. sUser.ulObjClass = (ulIsNonactive ? NONACTIVE_USER : ACTIVE_USER);
  3494. sUser.ulIsAdmin = ulIsAdmin;
  3495. // no support for hidden, capacity and propmaps
  3496. MAPI_G(hr) = lpServiceAdmin->SetUser(&sUser, 0);
  3497. if(MAPI_G(hr) != hrSuccess)
  3498. goto exit;
  3499. RETVAL_TRUE;
  3500. exit:
  3501. LOG_END();
  3502. THROW_ON_ERROR();
  3503. }
  3504. ZEND_FUNCTION(mapi_zarafa_deleteuser)
  3505. {
  3506. PMEASURE_FUNC;
  3507. LOG_BEGIN();
  3508. // params
  3509. zval *res = NULL;
  3510. LPMDB lpMsgStore = NULL;
  3511. ULONG cbUserId = 0;
  3512. memory_ptr<ENTRYID> lpUserId;
  3513. char* lpszUserName = NULL;
  3514. ULONG ulUserName;
  3515. // local
  3516. IECUnknown *lpUnknown = NULL;
  3517. object_ptr<IECServiceAdmin> lpServiceAdmin;
  3518. RETVAL_FALSE;
  3519. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  3520. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &lpszUserName, &ulUserName) == FAILURE) return;
  3521. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  3522. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  3523. if(MAPI_G(hr) != hrSuccess) {
  3524. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano store");
  3525. goto exit;
  3526. }
  3527. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECServiceAdmin, &~lpServiceAdmin);
  3528. if(MAPI_G(hr) != hrSuccess) {
  3529. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object does not support the IECServiceAdmin interface");
  3530. goto exit;
  3531. }
  3532. MAPI_G(hr) = lpServiceAdmin->ResolveUserName((TCHAR*)lpszUserName, 0, &cbUserId, &~lpUserId);
  3533. if(MAPI_G(hr) != hrSuccess) {
  3534. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to delete user, Can't resolve user: %08X", MAPI_G(hr));
  3535. goto exit;
  3536. }
  3537. MAPI_G(hr) = lpServiceAdmin->DeleteUser(cbUserId, lpUserId);
  3538. if(MAPI_G(hr) != hrSuccess) {
  3539. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to delete user: %08X", MAPI_G(hr));
  3540. goto exit;
  3541. }
  3542. RETVAL_TRUE;
  3543. exit:
  3544. LOG_END();
  3545. THROW_ON_ERROR();
  3546. }
  3547. ZEND_FUNCTION(mapi_zarafa_createstore)
  3548. {
  3549. PMEASURE_FUNC;
  3550. LOG_BEGIN();
  3551. // params
  3552. zval *res = NULL;
  3553. LPMDB lpMsgStore = NULL;
  3554. long ulStoreType;
  3555. LPENTRYID lpUserId = NULL;
  3556. unsigned int cbUserId = 0;
  3557. // local
  3558. IECUnknown *lpUnknown = NULL;
  3559. object_ptr<IECServiceAdmin> lpServiceAdmin;
  3560. memory_ptr<ENTRYID> lpStoreID, lpRootID;
  3561. ULONG cbStoreID = 0;
  3562. ULONG cbRootID = 0;
  3563. RETVAL_FALSE;
  3564. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  3565. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rls", &res, &ulStoreType, &lpUserId, &cbUserId) == FAILURE) return;
  3566. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  3567. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  3568. if(MAPI_G(hr) != hrSuccess) {
  3569. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano store");
  3570. goto exit;
  3571. }
  3572. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECServiceAdmin, &~lpServiceAdmin);
  3573. if(MAPI_G(hr) != hrSuccess) {
  3574. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object does not support the IECServiceAdmin interface");
  3575. goto exit;
  3576. }
  3577. MAPI_G(hr) = lpServiceAdmin->CreateStore(ulStoreType, cbUserId, lpUserId, &cbStoreID, &~lpStoreID, &cbRootID, &~lpRootID);
  3578. if(MAPI_G(hr) != hrSuccess) {
  3579. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to modify user: %08X", MAPI_G(hr));
  3580. goto exit;
  3581. }
  3582. RETVAL_TRUE;
  3583. exit:
  3584. LOG_END();
  3585. THROW_ON_ERROR();
  3586. }
  3587. /**
  3588. * Retrieve a list of users
  3589. * @param logged on msgstore
  3590. * @param company entryid
  3591. * @return array(username => array(fullname, emaladdress, userid, admin));
  3592. */
  3593. ZEND_FUNCTION(mapi_zarafa_getuserlist)
  3594. {
  3595. PMEASURE_FUNC;
  3596. LOG_BEGIN();
  3597. // params
  3598. zval *res = NULL;
  3599. zval* zval_data_value = NULL;
  3600. LPMDB lpMsgStore = NULL;
  3601. LPENTRYID lpCompanyId = NULL;
  3602. unsigned int cbCompanyId = 0;
  3603. // return value
  3604. // local
  3605. ULONG nUsers, i;
  3606. memory_ptr<ECUSER> lpUsers;
  3607. IECUnknown *lpUnknown = NULL;
  3608. object_ptr<IECSecurity> lpSecurity;
  3609. RETVAL_FALSE;
  3610. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  3611. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|s", &res, &lpCompanyId, &cbCompanyId) == FAILURE) return;
  3612. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  3613. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  3614. if(MAPI_G(hr) != hrSuccess) {
  3615. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano store");
  3616. goto exit;
  3617. }
  3618. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECSecurity, &~lpSecurity);
  3619. if(MAPI_G(hr) != hrSuccess)
  3620. goto exit;
  3621. MAPI_G(hr) = lpSecurity->GetUserList(cbCompanyId, lpCompanyId, 0, &nUsers, &~lpUsers);
  3622. if (MAPI_G(hr) != hrSuccess)
  3623. goto exit;
  3624. array_init(return_value);
  3625. for (i = 0; i < nUsers; ++i) {
  3626. MAKE_STD_ZVAL(zval_data_value);
  3627. array_init(zval_data_value);
  3628. add_assoc_stringl(zval_data_value, "userid", (char*)lpUsers[i].sUserId.lpb, lpUsers[i].sUserId.cb, 1);
  3629. add_assoc_string(zval_data_value, "username", (char*)lpUsers[i].lpszUsername, 1);
  3630. add_assoc_string(zval_data_value, "fullname", (char*)lpUsers[i].lpszFullName, 1);
  3631. add_assoc_string(zval_data_value, "emailaddress", (char*)lpUsers[i].lpszMailAddress, 1);
  3632. add_assoc_long(zval_data_value, "admin", lpUsers[i].ulIsAdmin);
  3633. add_assoc_long(zval_data_value, "nonactive", (lpUsers[i].ulObjClass == ACTIVE_USER ? 0 : 1));
  3634. add_assoc_zval(return_value, (char*)lpUsers[i].lpszUsername, zval_data_value);
  3635. }
  3636. exit:
  3637. LOG_END();
  3638. THROW_ON_ERROR();
  3639. }
  3640. /**
  3641. * Retrieve quota values of a users
  3642. * @param logged on msgstore
  3643. * @param user entryid to get quota information from
  3644. * @return array(usedefault, isuserdefault, warnsize, softsize, hardsize);
  3645. */
  3646. ZEND_FUNCTION(mapi_zarafa_getquota)
  3647. {
  3648. PMEASURE_FUNC;
  3649. LOG_BEGIN();
  3650. // params
  3651. zval *res = NULL;
  3652. LPMDB lpMsgStore = NULL;
  3653. LPENTRYID lpUserId = NULL;
  3654. unsigned int cbUserId = 0;
  3655. // return value
  3656. // local
  3657. IECUnknown *lpUnknown = NULL;
  3658. object_ptr<IECServiceAdmin> lpServiceAdmin;
  3659. memory_ptr<ECQUOTA> lpQuota;
  3660. RETVAL_FALSE;
  3661. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  3662. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &lpUserId, &cbUserId) == FAILURE) return;
  3663. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  3664. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  3665. if(MAPI_G(hr) != hrSuccess) {
  3666. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano store");
  3667. goto exit;
  3668. }
  3669. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECServiceAdmin, &~lpServiceAdmin);
  3670. if(MAPI_G(hr) != hrSuccess)
  3671. goto exit;
  3672. MAPI_G(hr) = lpServiceAdmin->GetQuota(cbUserId, lpUserId, false, &~lpQuota);
  3673. if (MAPI_G(hr) != hrSuccess)
  3674. goto exit;
  3675. array_init(return_value);
  3676. add_assoc_bool(return_value, "usedefault", lpQuota->bUseDefaultQuota);
  3677. add_assoc_bool(return_value, "isuserdefault", lpQuota->bIsUserDefaultQuota);
  3678. add_assoc_long(return_value, "warnsize", lpQuota->llWarnSize);
  3679. add_assoc_long(return_value, "softsize", lpQuota->llSoftSize);
  3680. add_assoc_long(return_value, "hardsize", lpQuota->llHardSize);
  3681. exit:
  3682. LOG_END();
  3683. THROW_ON_ERROR();
  3684. }
  3685. /**
  3686. * Update quota values for a users
  3687. * @param logged on msgstore
  3688. * @param userid to get quota information from
  3689. * @param array(usedefault, isuserdefault, warnsize, softsize, hardsize)
  3690. * @return true/false
  3691. */
  3692. ZEND_FUNCTION(mapi_zarafa_setquota)
  3693. {
  3694. PMEASURE_FUNC;
  3695. LOG_BEGIN();
  3696. // params
  3697. zval *res = NULL;
  3698. LPMDB lpMsgStore = NULL;
  3699. LPENTRYID lpUserId = NULL;
  3700. unsigned int cbUserId = 0;
  3701. zval *array = NULL;
  3702. // return value
  3703. // local
  3704. IECUnknown *lpUnknown = NULL;
  3705. object_ptr<IECServiceAdmin> lpServiceAdmin;
  3706. memory_ptr<ECQUOTA> lpQuota;
  3707. HashTable *data = NULL;
  3708. zval **value = NULL;
  3709. RETVAL_FALSE;
  3710. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  3711. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsa", &res, &lpUserId, &cbUserId, &array) == FAILURE) return;
  3712. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  3713. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  3714. if(MAPI_G(hr) != hrSuccess) {
  3715. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano store");
  3716. goto exit;
  3717. }
  3718. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECServiceAdmin, &~lpServiceAdmin);
  3719. if(MAPI_G(hr) != hrSuccess)
  3720. goto exit;
  3721. MAPI_G(hr) = lpServiceAdmin->GetQuota(cbUserId, lpUserId, false, &~lpQuota);
  3722. if (MAPI_G(hr) != hrSuccess)
  3723. goto exit;
  3724. data = HASH_OF(array);
  3725. zend_hash_internal_pointer_reset(data);
  3726. if (zend_hash_find(data, "usedefault", sizeof("usedefault"), (void**)&value) == SUCCESS) {
  3727. convert_to_boolean_ex(value);
  3728. lpQuota->bUseDefaultQuota = Z_BVAL_PP(value);
  3729. }
  3730. if (zend_hash_find(data, "isuserdefault", sizeof("isuserdefault"), (void**)&value) == SUCCESS) {
  3731. convert_to_boolean_ex(value);
  3732. lpQuota->bIsUserDefaultQuota = Z_BVAL_PP(value);
  3733. }
  3734. if (zend_hash_find(data, "warnsize", sizeof("warnsize"), (void**)&value) == SUCCESS) {
  3735. convert_to_long_ex(value);
  3736. lpQuota->llWarnSize = Z_LVAL_PP(value);
  3737. }
  3738. if (zend_hash_find(data, "softsize", sizeof("softsize"), (void**)&value) == SUCCESS) {
  3739. convert_to_long_ex(value);
  3740. lpQuota->llSoftSize = Z_LVAL_PP(value);
  3741. }
  3742. if (zend_hash_find(data, "hardsize", sizeof("hardsize"), (void**)&value) == SUCCESS) {
  3743. convert_to_long_ex(value);
  3744. lpQuota->llHardSize = Z_LVAL_PP(value);
  3745. }
  3746. MAPI_G(hr) = lpServiceAdmin->SetQuota(cbUserId, lpUserId, lpQuota);
  3747. if (MAPI_G(hr) != hrSuccess)
  3748. goto exit;
  3749. RETVAL_TRUE;
  3750. exit:
  3751. LOG_END();
  3752. THROW_ON_ERROR();
  3753. }
  3754. /**
  3755. * Retrieve user information
  3756. * @param logged on msgstore
  3757. * @param username
  3758. * @return array(fullname, emailaddress, userid, admin);
  3759. */
  3760. ZEND_FUNCTION(mapi_zarafa_getuser_by_name)
  3761. {
  3762. PMEASURE_FUNC;
  3763. LOG_BEGIN();
  3764. // params
  3765. zval *res = NULL;
  3766. LPMDB lpMsgStore = NULL;
  3767. char *lpszUsername;
  3768. unsigned int ulUsername;
  3769. // return value
  3770. // local
  3771. memory_ptr<ECUSER> lpUsers;
  3772. IECUnknown *lpUnknown = NULL;
  3773. object_ptr<IECServiceAdmin> lpServiceAdmin;
  3774. memory_ptr<ENTRYID> lpUserId;
  3775. unsigned int cbUserId = 0;
  3776. RETVAL_FALSE;
  3777. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  3778. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &lpszUsername, &ulUsername) == FAILURE) return;
  3779. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  3780. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  3781. if(MAPI_G(hr) != hrSuccess) {
  3782. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano store");
  3783. goto exit;
  3784. }
  3785. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECServiceAdmin, &~lpServiceAdmin);
  3786. if(MAPI_G(hr) != hrSuccess)
  3787. goto exit;
  3788. MAPI_G(hr) = lpServiceAdmin->ResolveUserName((TCHAR*)lpszUsername, 0, (ULONG*)&cbUserId, &~lpUserId);
  3789. if(MAPI_G(hr) != hrSuccess) {
  3790. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to resolve the user: %08X", MAPI_G(hr));
  3791. goto exit;
  3792. }
  3793. MAPI_G(hr) = lpServiceAdmin->GetUser(cbUserId, lpUserId, 0, &~lpUsers);
  3794. if (MAPI_G(hr) != hrSuccess) {
  3795. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to get the user: %08X", MAPI_G(hr));
  3796. goto exit;
  3797. }
  3798. array_init(return_value);
  3799. add_assoc_stringl(return_value, "userid", (char*)lpUsers->sUserId.lpb, lpUsers->sUserId.cb, 1);
  3800. add_assoc_string(return_value, "username", (char*)lpUsers->lpszUsername, 1);
  3801. add_assoc_string(return_value, "fullname", (char*)lpUsers->lpszFullName, 1);
  3802. add_assoc_string(return_value, "emailaddress", (char*)lpUsers->lpszMailAddress, 1);
  3803. add_assoc_long(return_value, "admin", lpUsers->ulIsAdmin);
  3804. exit:
  3805. LOG_END();
  3806. THROW_ON_ERROR();
  3807. }
  3808. /**
  3809. * Retrieve user information
  3810. * @param logged on msgstore
  3811. * @param userid
  3812. * @return array(fullname, emailaddress, userid, admin);
  3813. */
  3814. ZEND_FUNCTION(mapi_zarafa_getuser_by_id)
  3815. {
  3816. PMEASURE_FUNC;
  3817. LOG_BEGIN();
  3818. // params
  3819. zval *res = NULL;
  3820. LPMDB lpMsgStore = NULL;
  3821. LPENTRYID lpUserId = NULL;
  3822. unsigned int cbUserId = 0;
  3823. // return value
  3824. // local
  3825. memory_ptr<ECUSER> lpUsers;
  3826. IECUnknown *lpUnknown = NULL;
  3827. object_ptr<IECServiceAdmin> lpServiceAdmin;
  3828. RETVAL_FALSE;
  3829. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  3830. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &lpUserId, &cbUserId) == FAILURE) return;
  3831. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  3832. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  3833. if(MAPI_G(hr) != hrSuccess) {
  3834. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano store");
  3835. goto exit;
  3836. }
  3837. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECServiceAdmin, &~lpServiceAdmin);
  3838. if(MAPI_G(hr) != hrSuccess)
  3839. goto exit;
  3840. MAPI_G(hr) = lpServiceAdmin->GetUser(cbUserId, lpUserId, 0, &~lpUsers);
  3841. if (MAPI_G(hr) != hrSuccess) {
  3842. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to get the user: %08X", MAPI_G(hr));
  3843. goto exit;
  3844. }
  3845. array_init(return_value);
  3846. add_assoc_stringl(return_value, "userid", (char*)lpUsers->sUserId.lpb, lpUsers->sUserId.cb, 1);
  3847. add_assoc_string(return_value, "username", (char*)lpUsers->lpszUsername, 1);
  3848. add_assoc_string(return_value, "fullname", (char*)lpUsers->lpszFullName, 1);
  3849. add_assoc_string(return_value, "emailaddress", (char*)lpUsers->lpszMailAddress, 1);
  3850. add_assoc_long(return_value, "admin", lpUsers->ulIsAdmin);
  3851. exit:
  3852. LOG_END();
  3853. THROW_ON_ERROR();
  3854. }
  3855. ZEND_FUNCTION(mapi_zarafa_creategroup)
  3856. {
  3857. PMEASURE_FUNC;
  3858. LOG_BEGIN();
  3859. // params
  3860. zval *res = NULL;
  3861. LPMDB lpMsgStore = NULL;
  3862. ECGROUP sGroup;
  3863. unsigned int cbGroupname;
  3864. // return value
  3865. memory_ptr<ENTRYID> lpGroupId;
  3866. unsigned int cbGroupId = 0;
  3867. // locals
  3868. IECUnknown *lpUnknown = NULL;
  3869. object_ptr<IECServiceAdmin> lpServiceAdmin;
  3870. RETVAL_FALSE;
  3871. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  3872. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &sGroup.lpszGroupname, &cbGroupname) == FAILURE) return;
  3873. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  3874. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  3875. if(MAPI_G(hr) != hrSuccess) {
  3876. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano store");
  3877. goto exit;
  3878. }
  3879. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECServiceAdmin, &~lpServiceAdmin);
  3880. if(MAPI_G(hr) != hrSuccess)
  3881. goto exit;
  3882. sGroup.lpszFullname = sGroup.lpszGroupname;
  3883. MAPI_G(hr) = lpServiceAdmin->CreateGroup(&sGroup, 0, (ULONG*)&cbGroupId, &~lpGroupId);
  3884. if (MAPI_G(hr) != hrSuccess) {
  3885. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to create group: %08X", MAPI_G(hr));
  3886. goto exit;
  3887. }
  3888. RETVAL_STRINGL(reinterpret_cast<const char *>(lpGroupId.get()), cbGroupId, 1);
  3889. exit:
  3890. LOG_END();
  3891. THROW_ON_ERROR();
  3892. }
  3893. ZEND_FUNCTION(mapi_zarafa_deletegroup)
  3894. {
  3895. PMEASURE_FUNC;
  3896. LOG_BEGIN();
  3897. // params
  3898. zval *res = NULL;
  3899. LPMDB lpMsgStore = NULL;
  3900. char *lpszGroupname;
  3901. unsigned int cbGroupname;
  3902. // return value
  3903. // locals
  3904. IECUnknown *lpUnknown = NULL;
  3905. object_ptr<IECServiceAdmin> lpServiceAdmin;
  3906. memory_ptr<ENTRYID> lpGroupId;
  3907. unsigned int cbGroupId = 0;
  3908. RETVAL_FALSE;
  3909. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  3910. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &lpszGroupname, &cbGroupname) == FAILURE) return;
  3911. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  3912. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  3913. if(MAPI_G(hr) != hrSuccess) {
  3914. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano store");
  3915. goto exit;
  3916. }
  3917. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECServiceAdmin, &~lpServiceAdmin);
  3918. if(MAPI_G(hr) != hrSuccess)
  3919. goto exit;
  3920. MAPI_G(hr) = lpServiceAdmin->ResolveGroupName((TCHAR*)lpszGroupname, 0, (ULONG*)&cbGroupId, &~lpGroupId);
  3921. if (MAPI_G(hr) != hrSuccess) {
  3922. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Group not found: %08X", MAPI_G(hr));
  3923. goto exit;
  3924. }
  3925. MAPI_G(hr) = lpServiceAdmin->DeleteGroup(cbGroupId, lpGroupId);
  3926. if(MAPI_G(hr) != hrSuccess)
  3927. goto exit;
  3928. RETVAL_TRUE;
  3929. exit:
  3930. LOG_END();
  3931. THROW_ON_ERROR();
  3932. }
  3933. ZEND_FUNCTION(mapi_zarafa_addgroupmember)
  3934. {
  3935. PMEASURE_FUNC;
  3936. LOG_BEGIN();
  3937. // params
  3938. zval *res = NULL;
  3939. LPENTRYID lpGroupId = NULL;
  3940. unsigned int cbGroupId = 0;
  3941. LPENTRYID lpUserId = NULL;
  3942. unsigned int cbUserId = 0;
  3943. // return value
  3944. // locals
  3945. IECUnknown *lpUnknown = NULL;
  3946. object_ptr<IECServiceAdmin> lpServiceAdmin;
  3947. IMsgStore *lpMsgStore = NULL;
  3948. RETVAL_FALSE;
  3949. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  3950. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &res, &lpGroupId, &cbGroupId, &lpUserId, &cbUserId) == FAILURE) return;
  3951. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  3952. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  3953. if(MAPI_G(hr) != hrSuccess) {
  3954. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano store");
  3955. goto exit;
  3956. }
  3957. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECServiceAdmin, &~lpServiceAdmin);
  3958. if(MAPI_G(hr) != hrSuccess)
  3959. goto exit;
  3960. MAPI_G(hr) = lpServiceAdmin->AddGroupUser(cbGroupId, lpGroupId, cbUserId, lpUserId);
  3961. if(MAPI_G(hr) != hrSuccess)
  3962. goto exit;
  3963. RETVAL_TRUE;
  3964. exit:
  3965. LOG_END();
  3966. THROW_ON_ERROR();
  3967. }
  3968. ZEND_FUNCTION(mapi_zarafa_deletegroupmember)
  3969. {
  3970. PMEASURE_FUNC;
  3971. LOG_BEGIN();
  3972. // params
  3973. zval *res = NULL;
  3974. LPENTRYID lpGroupId = NULL;
  3975. unsigned int cbGroupId = 0;
  3976. LPENTRYID lpUserId = NULL;
  3977. unsigned int cbUserId = 0;
  3978. // return value
  3979. // locals
  3980. IECUnknown *lpUnknown = NULL;
  3981. object_ptr<IECServiceAdmin> lpServiceAdmin;
  3982. IMsgStore *lpMsgStore = NULL;
  3983. RETVAL_FALSE;
  3984. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  3985. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &res, &lpGroupId, &cbGroupId, &lpUserId, &cbUserId) == FAILURE) return;
  3986. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  3987. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  3988. if(MAPI_G(hr) != hrSuccess) {
  3989. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano store");
  3990. goto exit;
  3991. }
  3992. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECServiceAdmin, &~lpServiceAdmin);
  3993. if(MAPI_G(hr) != hrSuccess)
  3994. goto exit;
  3995. MAPI_G(hr) = lpServiceAdmin->DeleteGroupUser(cbGroupId, lpGroupId, cbUserId, lpUserId);
  3996. if(MAPI_G(hr) != hrSuccess)
  3997. goto exit;
  3998. RETVAL_TRUE;
  3999. exit:
  4000. LOG_END();
  4001. THROW_ON_ERROR();
  4002. }
  4003. ZEND_FUNCTION(mapi_zarafa_setgroup)
  4004. {
  4005. PMEASURE_FUNC;
  4006. LOG_BEGIN();
  4007. // params
  4008. zval *res = NULL;
  4009. LPMDB lpMsgStore = NULL;
  4010. char *lpszGroupname;
  4011. unsigned int cbGroupname;
  4012. LPENTRYID *lpGroupId = NULL;
  4013. unsigned int cbGroupId = 0;
  4014. // return value
  4015. // locals
  4016. IECUnknown *lpUnknown = NULL;
  4017. object_ptr<IECServiceAdmin> lpServiceAdmin;
  4018. ECGROUP sGroup;
  4019. RETVAL_FALSE;
  4020. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  4021. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &res, &lpGroupId, &cbGroupId, &lpszGroupname, &cbGroupname) == FAILURE) return;
  4022. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  4023. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  4024. if(MAPI_G(hr) != hrSuccess) {
  4025. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano store");
  4026. goto exit;
  4027. }
  4028. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECServiceAdmin, &~lpServiceAdmin);
  4029. if(MAPI_G(hr) != hrSuccess)
  4030. goto exit;
  4031. sGroup.sGroupId.cb = cbGroupId;
  4032. sGroup.sGroupId.lpb = (unsigned char*)lpGroupId;
  4033. sGroup.lpszGroupname = (TCHAR*)lpszGroupname;
  4034. MAPI_G(hr) = lpServiceAdmin->SetGroup(&sGroup, 0);
  4035. if(MAPI_G(hr) != hrSuccess)
  4036. goto exit;
  4037. RETVAL_TRUE;
  4038. exit:
  4039. LOG_END();
  4040. THROW_ON_ERROR();
  4041. }
  4042. ZEND_FUNCTION(mapi_zarafa_getgroup_by_id)
  4043. {
  4044. PMEASURE_FUNC;
  4045. LOG_BEGIN();
  4046. // params
  4047. zval *res = NULL;
  4048. LPMDB lpMsgStore = NULL;
  4049. LPENTRYID lpGroupId = NULL;
  4050. unsigned int cbGroupId = 0;
  4051. // return value
  4052. // locals
  4053. IECUnknown *lpUnknown = NULL;
  4054. object_ptr<IECServiceAdmin> lpServiceAdmin;
  4055. memory_ptr<ECGROUP> lpsGroup;
  4056. RETVAL_FALSE;
  4057. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  4058. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &lpGroupId, &cbGroupId) == FAILURE) return;
  4059. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  4060. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  4061. if(MAPI_G(hr) != hrSuccess) {
  4062. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano store");
  4063. goto exit;
  4064. }
  4065. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECServiceAdmin, &~lpServiceAdmin);
  4066. if(MAPI_G(hr) != hrSuccess)
  4067. goto exit;
  4068. MAPI_G(hr) = lpServiceAdmin->GetGroup(cbGroupId, lpGroupId, 0, &~lpsGroup);
  4069. if(MAPI_G(hr) != hrSuccess)
  4070. goto exit;
  4071. array_init(return_value);
  4072. add_assoc_stringl(return_value, "groupid", (char*)lpGroupId, cbGroupId, 1);
  4073. add_assoc_string(return_value, "groupname", (char*)lpsGroup->lpszGroupname, 1);
  4074. exit:
  4075. LOG_END();
  4076. THROW_ON_ERROR();
  4077. }
  4078. ZEND_FUNCTION(mapi_zarafa_getgroup_by_name)
  4079. {
  4080. PMEASURE_FUNC;
  4081. LOG_BEGIN();
  4082. // params
  4083. zval *res = NULL;
  4084. LPMDB lpMsgStore = NULL;
  4085. char *lpszGroupname = NULL;
  4086. unsigned int ulGroupname;
  4087. memory_ptr<ENTRYID> lpGroupId;
  4088. unsigned int cbGroupId = 0;
  4089. // return value
  4090. // locals
  4091. IECUnknown *lpUnknown = NULL;
  4092. object_ptr<IECServiceAdmin> lpServiceAdmin;
  4093. memory_ptr<ECGROUP> lpsGroup;
  4094. RETVAL_FALSE;
  4095. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  4096. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &lpszGroupname, &ulGroupname) == FAILURE) return;
  4097. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  4098. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  4099. if(MAPI_G(hr) != hrSuccess) {
  4100. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano store");
  4101. goto exit;
  4102. }
  4103. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECServiceAdmin, &~lpServiceAdmin);
  4104. if(MAPI_G(hr) != hrSuccess)
  4105. goto exit;
  4106. MAPI_G(hr) = lpServiceAdmin->ResolveGroupName((TCHAR*)lpszGroupname, 0, (ULONG*)&cbGroupId, &~lpGroupId);
  4107. if(MAPI_G(hr) != hrSuccess) {
  4108. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to resolve the group: %08X", MAPI_G(hr));
  4109. goto exit;
  4110. }
  4111. MAPI_G(hr) = lpServiceAdmin->GetGroup(cbGroupId, lpGroupId, 0, &~lpsGroup);
  4112. if(MAPI_G(hr) != hrSuccess)
  4113. goto exit;
  4114. array_init(return_value);
  4115. add_assoc_stringl(return_value, "groupid", reinterpret_cast<char *>(lpGroupId.get()), cbGroupId, 1);
  4116. add_assoc_string(return_value, "groupname", (char*)lpsGroup->lpszGroupname, 1);
  4117. exit:
  4118. LOG_END();
  4119. THROW_ON_ERROR();
  4120. }
  4121. ZEND_FUNCTION(mapi_zarafa_getgrouplist)
  4122. {
  4123. PMEASURE_FUNC;
  4124. LOG_BEGIN();
  4125. // params
  4126. zval *res = NULL;
  4127. LPENTRYID lpCompanyId = NULL;
  4128. unsigned int cbCompanyId = 0;
  4129. // return value
  4130. // locals
  4131. zval *zval_data_value = NULL;
  4132. LPMDB lpMsgStore = NULL;
  4133. IECUnknown *lpUnknown = NULL;
  4134. object_ptr<IECServiceAdmin> lpServiceAdmin;
  4135. ULONG ulGroups;
  4136. memory_ptr<ECGROUP> lpsGroups;
  4137. unsigned int i;
  4138. RETVAL_FALSE;
  4139. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  4140. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|s", &res, &lpCompanyId, &cbCompanyId) == FAILURE) return;
  4141. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  4142. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  4143. if(MAPI_G(hr) != hrSuccess) {
  4144. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano store");
  4145. goto exit;
  4146. }
  4147. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECServiceAdmin, &~lpServiceAdmin);
  4148. if(MAPI_G(hr) != hrSuccess)
  4149. goto exit;
  4150. MAPI_G(hr) = lpServiceAdmin->GetGroupList(cbCompanyId, lpCompanyId, 0, &ulGroups, &~lpsGroups);
  4151. if(MAPI_G(hr) != hrSuccess)
  4152. goto exit;
  4153. array_init(return_value);
  4154. for (i = 0; i < ulGroups; ++i) {
  4155. MAKE_STD_ZVAL(zval_data_value);
  4156. array_init(zval_data_value);
  4157. add_assoc_stringl(zval_data_value, "groupid", (char*)lpsGroups[i].sGroupId.lpb, lpsGroups[i].sGroupId.cb, 1);
  4158. add_assoc_string(zval_data_value, "groupname", (char*)lpsGroups[i].lpszGroupname, 1);
  4159. add_assoc_zval(return_value, (char*)lpsGroups[i].lpszGroupname, zval_data_value);
  4160. }
  4161. exit:
  4162. LOG_END();
  4163. THROW_ON_ERROR();
  4164. }
  4165. ZEND_FUNCTION(mapi_zarafa_getgrouplistofuser)
  4166. {
  4167. PMEASURE_FUNC;
  4168. LOG_BEGIN();
  4169. // params
  4170. zval *res = NULL;
  4171. LPENTRYID lpUserId = NULL;
  4172. unsigned int cbUserId = 0;
  4173. // return value
  4174. // locals
  4175. zval *zval_data_value = NULL;
  4176. LPMDB lpMsgStore = NULL;
  4177. IECUnknown *lpUnknown = NULL;
  4178. object_ptr<IECServiceAdmin> lpServiceAdmin;
  4179. ULONG ulGroups;
  4180. memory_ptr<ECGROUP> lpsGroups;
  4181. unsigned int i;
  4182. RETVAL_FALSE;
  4183. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  4184. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &lpUserId, &cbUserId) == FAILURE) return;
  4185. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  4186. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  4187. if(MAPI_G(hr) != hrSuccess) {
  4188. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano store");
  4189. goto exit;
  4190. }
  4191. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECServiceAdmin, &~lpServiceAdmin);
  4192. if(MAPI_G(hr) != hrSuccess)
  4193. goto exit;
  4194. MAPI_G(hr) = lpServiceAdmin->GetGroupListOfUser(cbUserId, lpUserId, 0, &ulGroups, &~lpsGroups);
  4195. if(MAPI_G(hr) != hrSuccess)
  4196. goto exit;
  4197. array_init(return_value);
  4198. for (i = 0; i < ulGroups; ++i) {
  4199. MAKE_STD_ZVAL(zval_data_value);
  4200. array_init(zval_data_value);
  4201. add_assoc_stringl(zval_data_value, "groupid", (char*)lpsGroups[i].sGroupId.lpb, lpsGroups[i].sGroupId.cb, 1);
  4202. add_assoc_string(zval_data_value, "groupname", (char*)lpsGroups[i].lpszGroupname, 1);
  4203. add_assoc_zval(return_value, (char*)lpsGroups[i].lpszGroupname, zval_data_value);
  4204. }
  4205. exit:
  4206. LOG_END();
  4207. THROW_ON_ERROR();
  4208. }
  4209. ZEND_FUNCTION(mapi_zarafa_getuserlistofgroup)
  4210. {
  4211. PMEASURE_FUNC;
  4212. LOG_BEGIN();
  4213. // params
  4214. zval *res = NULL;
  4215. LPENTRYID lpGroupId = NULL;
  4216. unsigned int cbGroupId = 0;
  4217. // return value
  4218. // locals
  4219. zval *zval_data_value = NULL;
  4220. LPMDB lpMsgStore = NULL;
  4221. IECUnknown *lpUnknown = NULL;
  4222. object_ptr<IECServiceAdmin> lpServiceAdmin;
  4223. ULONG ulUsers;
  4224. memory_ptr<ECUSER> lpsUsers;
  4225. unsigned int i;
  4226. RETVAL_FALSE;
  4227. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  4228. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &lpGroupId, &cbGroupId) == FAILURE) return;
  4229. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  4230. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  4231. if(MAPI_G(hr) != hrSuccess) {
  4232. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano store");
  4233. goto exit;
  4234. }
  4235. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECServiceAdmin, &~lpServiceAdmin);
  4236. if(MAPI_G(hr) != hrSuccess)
  4237. goto exit;
  4238. MAPI_G(hr) = lpServiceAdmin->GetUserListOfGroup(cbGroupId, lpGroupId, 0, &ulUsers, &~lpsUsers);
  4239. if(MAPI_G(hr) != hrSuccess)
  4240. goto exit;
  4241. array_init(return_value);
  4242. for (i = 0; i < ulUsers; ++i) {
  4243. MAKE_STD_ZVAL(zval_data_value);
  4244. array_init(zval_data_value);
  4245. add_assoc_stringl(zval_data_value, "userid", (char*)lpsUsers[i].sUserId.lpb, lpsUsers[i].sUserId.cb, 1);
  4246. add_assoc_string(zval_data_value, "username", (char*)lpsUsers[i].lpszUsername, 1);
  4247. add_assoc_string(zval_data_value, "fullname", (char*)lpsUsers[i].lpszFullName, 1);
  4248. add_assoc_string(zval_data_value, "emailaddress", (char*)lpsUsers[i].lpszMailAddress, 1);
  4249. add_assoc_long(zval_data_value, "admin", lpsUsers[i].ulIsAdmin);
  4250. add_assoc_zval(return_value, (char*)lpsUsers[i].lpszUsername, zval_data_value);
  4251. }
  4252. exit:
  4253. LOG_END();
  4254. THROW_ON_ERROR();
  4255. }
  4256. ZEND_FUNCTION(mapi_zarafa_createcompany)
  4257. {
  4258. PMEASURE_FUNC;
  4259. LOG_BEGIN();
  4260. // params
  4261. zval *res = NULL;
  4262. LPMDB lpMsgStore = NULL;
  4263. ECCOMPANY sCompany;
  4264. unsigned int cbCompanyname;
  4265. // return value
  4266. memory_ptr<ENTRYID> lpCompanyId;
  4267. unsigned int cbCompanyId = 0;
  4268. // locals
  4269. IECUnknown *lpUnknown = NULL;
  4270. object_ptr<IECServiceAdmin> lpServiceAdmin;
  4271. RETVAL_FALSE;
  4272. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  4273. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &sCompany.lpszCompanyname, &cbCompanyname) == FAILURE)
  4274. return;
  4275. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  4276. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  4277. if(MAPI_G(hr) != hrSuccess) {
  4278. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano store");
  4279. goto exit;
  4280. }
  4281. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECServiceAdmin, &~lpServiceAdmin);
  4282. if(MAPI_G(hr) != hrSuccess)
  4283. goto exit;
  4284. MAPI_G(hr) = lpServiceAdmin->CreateCompany(&sCompany, 0, (ULONG*)&cbCompanyId, &~lpCompanyId);
  4285. if (MAPI_G(hr) != hrSuccess) {
  4286. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to create company: %08X", MAPI_G(hr));
  4287. goto exit;
  4288. }
  4289. RETVAL_STRINGL(reinterpret_cast<const char *>(lpCompanyId.get()), cbCompanyId, 1);
  4290. exit:
  4291. LOG_END();
  4292. THROW_ON_ERROR();
  4293. }
  4294. ZEND_FUNCTION(mapi_zarafa_deletecompany)
  4295. {
  4296. PMEASURE_FUNC;
  4297. LOG_BEGIN();
  4298. // params
  4299. zval *res = NULL;
  4300. LPMDB lpMsgStore = NULL;
  4301. char *lpszCompanyname;
  4302. unsigned int cbCompanyname;
  4303. // return value
  4304. // locals
  4305. IECUnknown *lpUnknown = NULL;
  4306. object_ptr<IECServiceAdmin> lpServiceAdmin;
  4307. memory_ptr<ENTRYID> lpCompanyId;
  4308. unsigned int cbCompanyId = 0;
  4309. RETVAL_FALSE;
  4310. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  4311. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &lpszCompanyname, &cbCompanyname) == FAILURE)
  4312. return;
  4313. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  4314. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  4315. if(MAPI_G(hr) != hrSuccess) {
  4316. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano store");
  4317. goto exit;
  4318. }
  4319. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECServiceAdmin, &~lpServiceAdmin);
  4320. if(MAPI_G(hr) != hrSuccess)
  4321. goto exit;
  4322. MAPI_G(hr) = lpServiceAdmin->ResolveCompanyName((TCHAR*)lpszCompanyname, 0, (ULONG*)&cbCompanyId, &~lpCompanyId);
  4323. if (MAPI_G(hr) != hrSuccess) {
  4324. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Company not found: %08X", MAPI_G(hr));
  4325. goto exit;
  4326. }
  4327. MAPI_G(hr) = lpServiceAdmin->DeleteCompany(cbCompanyId, lpCompanyId);
  4328. if(MAPI_G(hr) != hrSuccess)
  4329. goto exit;
  4330. RETVAL_TRUE;
  4331. exit:
  4332. LOG_END();
  4333. THROW_ON_ERROR();
  4334. }
  4335. ZEND_FUNCTION(mapi_zarafa_getcompany_by_id)
  4336. {
  4337. PMEASURE_FUNC;
  4338. LOG_BEGIN();
  4339. // params
  4340. zval *res = NULL;
  4341. LPMDB lpMsgStore = NULL;
  4342. LPENTRYID lpCompanyId = NULL;
  4343. unsigned int cbCompanyId = 0;
  4344. // return value
  4345. // locals
  4346. IECUnknown *lpUnknown = NULL;
  4347. object_ptr<IECServiceAdmin> lpServiceAdmin;
  4348. memory_ptr<ECCOMPANY> lpsCompany;
  4349. RETVAL_FALSE;
  4350. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  4351. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &lpCompanyId, &cbCompanyId) == FAILURE)
  4352. return;
  4353. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  4354. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  4355. if(MAPI_G(hr) != hrSuccess) {
  4356. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano store");
  4357. goto exit;
  4358. }
  4359. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECServiceAdmin, &~lpServiceAdmin);
  4360. if(MAPI_G(hr) != hrSuccess)
  4361. goto exit;
  4362. MAPI_G(hr) = lpServiceAdmin->GetCompany(cbCompanyId, lpCompanyId, 0, &~lpsCompany);
  4363. if(MAPI_G(hr) != hrSuccess)
  4364. goto exit;
  4365. array_init(return_value);
  4366. add_assoc_stringl(return_value, "companyid", (char*)lpCompanyId, cbCompanyId, 1);
  4367. add_assoc_string(return_value, "companyname", (char*)lpsCompany->lpszCompanyname, 1);
  4368. exit:
  4369. LOG_END();
  4370. THROW_ON_ERROR();
  4371. }
  4372. ZEND_FUNCTION(mapi_zarafa_getcompany_by_name)
  4373. {
  4374. PMEASURE_FUNC;
  4375. LOG_BEGIN();
  4376. // params
  4377. zval *res = NULL;
  4378. LPMDB lpMsgStore = NULL;
  4379. char *lpszCompanyname = NULL;
  4380. unsigned int ulCompanyname;
  4381. memory_ptr<ENTRYID> lpCompanyId;
  4382. unsigned int cbCompanyId = 0;
  4383. // return value
  4384. // locals
  4385. IECUnknown *lpUnknown = NULL;
  4386. object_ptr<IECServiceAdmin> lpServiceAdmin;
  4387. memory_ptr<ECCOMPANY> lpsCompany;
  4388. RETVAL_FALSE;
  4389. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  4390. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &lpszCompanyname, &ulCompanyname) == FAILURE)
  4391. return;
  4392. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  4393. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  4394. if(MAPI_G(hr) != hrSuccess) {
  4395. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano store");
  4396. goto exit;
  4397. }
  4398. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECServiceAdmin, &~lpServiceAdmin);
  4399. if(MAPI_G(hr) != hrSuccess)
  4400. goto exit;
  4401. MAPI_G(hr) = lpServiceAdmin->ResolveCompanyName((TCHAR*)lpszCompanyname, 0, (ULONG*)&cbCompanyId, &~lpCompanyId);
  4402. if(MAPI_G(hr) != hrSuccess) {
  4403. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to resolve the company: %08X", MAPI_G(hr));
  4404. goto exit;
  4405. }
  4406. MAPI_G(hr) = lpServiceAdmin->GetCompany(cbCompanyId, lpCompanyId, 0, &~lpsCompany);
  4407. if(MAPI_G(hr) != hrSuccess)
  4408. goto exit;
  4409. array_init(return_value);
  4410. add_assoc_stringl(return_value, "companyid", reinterpret_cast<char *>(lpCompanyId.get()), cbCompanyId, 1);
  4411. add_assoc_string(return_value, "companyname", (char*)lpsCompany->lpszCompanyname, 1);
  4412. exit:
  4413. LOG_END();
  4414. THROW_ON_ERROR();
  4415. }
  4416. ZEND_FUNCTION(mapi_zarafa_getcompanylist)
  4417. {
  4418. PMEASURE_FUNC;
  4419. LOG_BEGIN();
  4420. // params
  4421. zval *res = NULL;
  4422. zval *zval_data_value = NULL;
  4423. LPMDB lpMsgStore = NULL;
  4424. // return value
  4425. // local
  4426. ULONG nCompanies, i;
  4427. memory_ptr<ECCOMPANY> lpCompanies;
  4428. IECUnknown *lpUnknown = NULL;;
  4429. object_ptr<IECSecurity> lpSecurity;
  4430. RETVAL_FALSE;
  4431. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  4432. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE)
  4433. return;
  4434. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  4435. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  4436. if(MAPI_G(hr) != hrSuccess) {
  4437. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano store");
  4438. goto exit;
  4439. }
  4440. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECSecurity, &~lpSecurity);
  4441. if(MAPI_G(hr) != hrSuccess)
  4442. goto exit;
  4443. MAPI_G(hr) = lpSecurity->GetCompanyList(0, &nCompanies, &~lpCompanies);
  4444. if (MAPI_G(hr) != hrSuccess)
  4445. goto exit;
  4446. array_init(return_value);
  4447. for (i = 0; i < nCompanies; ++i) {
  4448. MAKE_STD_ZVAL(zval_data_value);
  4449. array_init(zval_data_value);
  4450. add_assoc_stringl(zval_data_value, "companyid", (char*)lpCompanies[i].sCompanyId.lpb, lpCompanies[i].sCompanyId.cb, 1);
  4451. add_assoc_string(zval_data_value, "companyname", (char*)lpCompanies[i].lpszCompanyname, 1);
  4452. add_assoc_zval(return_value, (char*)lpCompanies[i].lpszCompanyname, zval_data_value);
  4453. }
  4454. exit:
  4455. LOG_END();
  4456. THROW_ON_ERROR();
  4457. }
  4458. ZEND_FUNCTION(mapi_zarafa_add_company_remote_viewlist)
  4459. {
  4460. PMEASURE_FUNC;
  4461. LOG_BEGIN();
  4462. zval *res = NULL;
  4463. LPENTRYID lpSetCompanyId = NULL;
  4464. unsigned int cbSetCompanyId = 0;
  4465. LPENTRYID lpCompanyId = NULL;
  4466. unsigned int cbCompanyId = 0;
  4467. /* Locals */
  4468. IECUnknown *lpUnknown = NULL;
  4469. object_ptr<IECServiceAdmin> lpServiceAdmin;
  4470. IMsgStore *lpMsgStore = NULL;
  4471. RETVAL_FALSE;
  4472. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  4473. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &res, &lpSetCompanyId, &cbSetCompanyId, &lpCompanyId, &cbCompanyId) == FAILURE)
  4474. return;
  4475. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  4476. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  4477. if (MAPI_G(hr) != hrSuccess) {
  4478. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano store");
  4479. goto exit;
  4480. }
  4481. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECServiceAdmin, &~lpServiceAdmin);
  4482. if (MAPI_G(hr) != hrSuccess)
  4483. goto exit;
  4484. MAPI_G(hr) = lpServiceAdmin->AddCompanyToRemoteViewList(cbSetCompanyId, lpSetCompanyId, cbCompanyId, lpCompanyId);
  4485. if (MAPI_G(hr) != hrSuccess)
  4486. goto exit;
  4487. RETVAL_TRUE;
  4488. exit:
  4489. LOG_END();
  4490. THROW_ON_ERROR();
  4491. }
  4492. ZEND_FUNCTION(mapi_zarafa_del_company_remote_viewlist)
  4493. {
  4494. PMEASURE_FUNC;
  4495. LOG_BEGIN();
  4496. zval *res = NULL;
  4497. LPENTRYID lpSetCompanyId = NULL;
  4498. unsigned int cbSetCompanyId = 0;
  4499. LPENTRYID lpCompanyId = NULL;
  4500. unsigned int cbCompanyId = 0;
  4501. /* Locals */
  4502. IECUnknown *lpUnknown = NULL;
  4503. object_ptr<IECServiceAdmin> lpServiceAdmin;
  4504. IMsgStore *lpMsgStore = NULL;
  4505. RETVAL_FALSE;
  4506. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  4507. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &res, &lpSetCompanyId, &cbSetCompanyId, &lpCompanyId, &cbCompanyId) == FAILURE)
  4508. return;
  4509. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  4510. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  4511. if (MAPI_G(hr) != hrSuccess) {
  4512. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano store");
  4513. goto exit;
  4514. }
  4515. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECServiceAdmin, &~lpServiceAdmin);
  4516. if (MAPI_G(hr) != hrSuccess)
  4517. goto exit;
  4518. MAPI_G(hr) = lpServiceAdmin->DelCompanyFromRemoteViewList(cbSetCompanyId, lpSetCompanyId, cbCompanyId, lpCompanyId);
  4519. if (MAPI_G(hr) != hrSuccess)
  4520. goto exit;
  4521. RETVAL_TRUE;
  4522. exit:
  4523. LOG_END();
  4524. THROW_ON_ERROR();
  4525. }
  4526. ZEND_FUNCTION(mapi_zarafa_get_remote_viewlist)
  4527. {
  4528. PMEASURE_FUNC;
  4529. LOG_BEGIN();
  4530. zval *res = NULL;
  4531. LPENTRYID lpCompanyId = NULL;
  4532. unsigned int cbCompanyId = 0;
  4533. /* Locals */
  4534. zval *zval_data_value = NULL;
  4535. IECUnknown *lpUnknown = NULL;
  4536. object_ptr<IECServiceAdmin> lpServiceAdmin;
  4537. IMsgStore *lpMsgStore = NULL;
  4538. ULONG ulCompanies = 0;
  4539. memory_ptr<ECCOMPANY> lpsCompanies;
  4540. RETVAL_FALSE;
  4541. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  4542. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &lpCompanyId, &cbCompanyId) == FAILURE)
  4543. return;
  4544. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  4545. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  4546. if (MAPI_G(hr) != hrSuccess) {
  4547. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano store");
  4548. goto exit;
  4549. }
  4550. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECServiceAdmin, &~lpServiceAdmin);
  4551. if (MAPI_G(hr) != hrSuccess)
  4552. goto exit;
  4553. MAPI_G(hr) = lpServiceAdmin->GetRemoteViewList(cbCompanyId, lpCompanyId, 0, &ulCompanies, &~lpsCompanies);
  4554. if (MAPI_G(hr) != hrSuccess)
  4555. goto exit;
  4556. array_init(return_value);
  4557. for (unsigned int i = 0; i < ulCompanies; ++i) {
  4558. MAKE_STD_ZVAL(zval_data_value);
  4559. array_init(zval_data_value);
  4560. add_assoc_stringl(zval_data_value, "companyid", (char*)lpsCompanies[i].sCompanyId.lpb, lpsCompanies[i].sCompanyId.cb, 1);
  4561. add_assoc_string(zval_data_value, "companyname", (char*)lpsCompanies[i].lpszCompanyname, 1);
  4562. add_assoc_zval(return_value, (char*)lpsCompanies[i].lpszCompanyname, zval_data_value);
  4563. }
  4564. exit:
  4565. LOG_END();
  4566. THROW_ON_ERROR();
  4567. }
  4568. ZEND_FUNCTION(mapi_zarafa_add_user_remote_adminlist)
  4569. {
  4570. PMEASURE_FUNC;
  4571. LOG_BEGIN();
  4572. zval *res = NULL;
  4573. LPENTRYID lpUserId = NULL;
  4574. unsigned int cbUserId = 0;
  4575. LPENTRYID lpCompanyId = NULL;
  4576. unsigned int cbCompanyId = 0;
  4577. /* Locals */
  4578. IECUnknown *lpUnknown = NULL;
  4579. object_ptr<IECServiceAdmin> lpServiceAdmin;
  4580. IMsgStore *lpMsgStore = NULL;
  4581. RETVAL_FALSE;
  4582. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  4583. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &res, &lpUserId, &cbUserId, &lpCompanyId, &cbCompanyId) == FAILURE)
  4584. return;
  4585. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  4586. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  4587. if (MAPI_G(hr) != hrSuccess) {
  4588. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano store");
  4589. goto exit;
  4590. }
  4591. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECServiceAdmin, &~lpServiceAdmin);
  4592. if (MAPI_G(hr) != hrSuccess)
  4593. goto exit;
  4594. MAPI_G(hr) = lpServiceAdmin->AddUserToRemoteAdminList(cbUserId, lpUserId, cbCompanyId, lpCompanyId);
  4595. if (MAPI_G(hr) != hrSuccess)
  4596. goto exit;
  4597. RETVAL_TRUE;
  4598. exit:
  4599. LOG_END();
  4600. THROW_ON_ERROR();
  4601. }
  4602. ZEND_FUNCTION(mapi_zarafa_del_user_remote_adminlist)
  4603. {
  4604. PMEASURE_FUNC;
  4605. LOG_BEGIN();
  4606. zval *res = NULL;
  4607. LPENTRYID lpUserId = NULL;
  4608. unsigned int cbUserId = 0;
  4609. LPENTRYID lpCompanyId = NULL;
  4610. unsigned int cbCompanyId = 0;
  4611. /* Locals */
  4612. IECUnknown *lpUnknown = NULL;
  4613. object_ptr<IECServiceAdmin> lpServiceAdmin;
  4614. IMsgStore *lpMsgStore = NULL;
  4615. RETVAL_FALSE;
  4616. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  4617. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &res, &lpUserId, &cbUserId, &lpCompanyId, &cbCompanyId) == FAILURE)
  4618. return;
  4619. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  4620. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  4621. if (MAPI_G(hr) != hrSuccess) {
  4622. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano store");
  4623. goto exit;
  4624. }
  4625. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECServiceAdmin, &~lpServiceAdmin);
  4626. if (MAPI_G(hr) != hrSuccess)
  4627. goto exit;
  4628. MAPI_G(hr) = lpServiceAdmin->DelUserFromRemoteAdminList(cbUserId, lpUserId, cbCompanyId, lpCompanyId);
  4629. if (MAPI_G(hr) != hrSuccess)
  4630. goto exit;
  4631. RETVAL_TRUE;
  4632. exit:
  4633. LOG_END();
  4634. THROW_ON_ERROR();
  4635. }
  4636. ZEND_FUNCTION(mapi_zarafa_get_remote_adminlist)
  4637. {
  4638. PMEASURE_FUNC;
  4639. LOG_BEGIN();
  4640. zval *res = NULL;
  4641. LPENTRYID lpCompanyId = NULL;
  4642. unsigned int cbCompanyId = 0;
  4643. /* Locals */
  4644. zval *zval_data_value = NULL;
  4645. IECUnknown *lpUnknown = NULL;
  4646. object_ptr<IECServiceAdmin> lpServiceAdmin;
  4647. IMsgStore *lpMsgStore = NULL;
  4648. ULONG ulUsers = 0;
  4649. memory_ptr<ECUSER> lpsUsers;
  4650. RETVAL_FALSE;
  4651. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  4652. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &lpCompanyId, &cbCompanyId) == FAILURE)
  4653. return;
  4654. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  4655. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  4656. if (MAPI_G(hr) != hrSuccess) {
  4657. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano store");
  4658. goto exit;
  4659. }
  4660. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECServiceAdmin, &~lpServiceAdmin);
  4661. if (MAPI_G(hr) != hrSuccess)
  4662. goto exit;
  4663. MAPI_G(hr) = lpServiceAdmin->GetRemoteAdminList(cbCompanyId, lpCompanyId, 0, &ulUsers, &~lpsUsers);
  4664. if (MAPI_G(hr) != hrSuccess)
  4665. goto exit;
  4666. array_init(return_value);
  4667. for (unsigned int i = 0; i < ulUsers; ++i) {
  4668. MAKE_STD_ZVAL(zval_data_value);
  4669. array_init(zval_data_value);
  4670. add_assoc_stringl(zval_data_value, "userid", (char*)lpsUsers[i].sUserId.lpb, lpsUsers[i].sUserId.cb, 1);
  4671. add_assoc_string(zval_data_value, "username", (char*)lpsUsers[i].lpszUsername, 1);
  4672. add_assoc_zval(return_value, (char*)lpsUsers[i].lpszUsername, zval_data_value);
  4673. }
  4674. exit:
  4675. LOG_END();
  4676. THROW_ON_ERROR();
  4677. }
  4678. ZEND_FUNCTION(mapi_zarafa_add_quota_recipient)
  4679. {
  4680. PMEASURE_FUNC;
  4681. LOG_BEGIN();
  4682. zval *res = NULL;
  4683. LPENTRYID lpRecipientId = NULL;
  4684. unsigned int cbRecipientId = 0;
  4685. LPENTRYID lpCompanyId = NULL;
  4686. unsigned int cbCompanyId = 0;
  4687. long ulType = 0;
  4688. /* Locals */
  4689. IECUnknown *lpUnknown = NULL;
  4690. object_ptr<IECServiceAdmin> lpServiceAdmin;
  4691. IMsgStore *lpMsgStore = NULL;
  4692. RETVAL_FALSE;
  4693. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  4694. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rssl", &res, &lpCompanyId, &cbCompanyId, &lpRecipientId, &cbRecipientId, &ulType) == FAILURE)
  4695. return;
  4696. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  4697. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  4698. if (MAPI_G(hr) != hrSuccess) {
  4699. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano store");
  4700. goto exit;
  4701. }
  4702. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECServiceAdmin, &~lpServiceAdmin);
  4703. if (MAPI_G(hr) != hrSuccess)
  4704. goto exit;
  4705. MAPI_G(hr) = lpServiceAdmin->AddQuotaRecipient(cbCompanyId, lpCompanyId, cbRecipientId, lpRecipientId, ulType);
  4706. if (MAPI_G(hr) != hrSuccess)
  4707. goto exit;
  4708. RETVAL_TRUE;
  4709. exit:
  4710. LOG_END();
  4711. THROW_ON_ERROR();
  4712. }
  4713. ZEND_FUNCTION(mapi_zarafa_del_quota_recipient)
  4714. {
  4715. PMEASURE_FUNC;
  4716. LOG_BEGIN();
  4717. zval *res = NULL;
  4718. LPENTRYID lpRecipientId = NULL;
  4719. unsigned int cbRecipientId = 0;
  4720. LPENTRYID lpCompanyId = NULL;
  4721. unsigned int cbCompanyId = 0;
  4722. long ulType = 0;
  4723. /* Locals */
  4724. IECUnknown *lpUnknown = NULL;
  4725. object_ptr<IECServiceAdmin> lpServiceAdmin;
  4726. IMsgStore *lpMsgStore = NULL;
  4727. RETVAL_FALSE;
  4728. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  4729. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rssl", &res, &lpCompanyId, &cbCompanyId, &lpRecipientId, &cbRecipientId, &ulType) == FAILURE)
  4730. return;
  4731. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  4732. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  4733. if (MAPI_G(hr) != hrSuccess) {
  4734. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano store");
  4735. goto exit;
  4736. }
  4737. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECServiceAdmin, &~lpServiceAdmin);
  4738. if (MAPI_G(hr) != hrSuccess)
  4739. goto exit;
  4740. MAPI_G(hr) = lpServiceAdmin->DeleteQuotaRecipient(cbCompanyId, lpCompanyId, cbRecipientId, lpRecipientId, ulType);
  4741. if (MAPI_G(hr) != hrSuccess)
  4742. goto exit;
  4743. RETVAL_TRUE;
  4744. exit:
  4745. LOG_END();
  4746. THROW_ON_ERROR();
  4747. }
  4748. ZEND_FUNCTION(mapi_zarafa_get_quota_recipientlist)
  4749. {
  4750. PMEASURE_FUNC;
  4751. LOG_BEGIN();
  4752. zval *res = NULL;
  4753. LPENTRYID lpObjectId = NULL;
  4754. unsigned int cbObjectId = 0;
  4755. /* Locals */
  4756. zval *zval_data_value = NULL;
  4757. IECUnknown *lpUnknown = NULL;
  4758. object_ptr<IECServiceAdmin> lpServiceAdmin;
  4759. IMsgStore *lpMsgStore = NULL;
  4760. ULONG ulUsers = 0;
  4761. memory_ptr<ECUSER> lpsUsers;
  4762. RETVAL_FALSE;
  4763. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  4764. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &lpObjectId, &cbObjectId) == FAILURE)
  4765. return;
  4766. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  4767. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  4768. if (MAPI_G(hr) != hrSuccess) {
  4769. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano store");
  4770. goto exit;
  4771. }
  4772. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECServiceAdmin, &~lpServiceAdmin);
  4773. if (MAPI_G(hr) != hrSuccess)
  4774. goto exit;
  4775. MAPI_G(hr) = lpServiceAdmin->GetQuotaRecipients(cbObjectId, lpObjectId, 0, &ulUsers, &~lpsUsers);
  4776. if (MAPI_G(hr) != hrSuccess)
  4777. goto exit;
  4778. array_init(return_value);
  4779. for (unsigned int i = 0; i < ulUsers; ++i) {
  4780. MAKE_STD_ZVAL(zval_data_value);
  4781. array_init(zval_data_value);
  4782. add_assoc_stringl(zval_data_value, "userid", (char*)lpsUsers[i].sUserId.lpb, lpsUsers[i].sUserId.cb, 1);
  4783. add_assoc_string(zval_data_value, "username", (char*)lpsUsers[i].lpszUsername, 1);
  4784. add_assoc_zval(return_value, (char*)lpsUsers[i].lpszUsername, zval_data_value);
  4785. }
  4786. exit:
  4787. LOG_END();
  4788. THROW_ON_ERROR();
  4789. }
  4790. ZEND_FUNCTION(mapi_zarafa_check_license)
  4791. {
  4792. PMEASURE_FUNC;
  4793. LOG_BEGIN();
  4794. zval *res = NULL;
  4795. IMsgStore *lpMsgStore = NULL;
  4796. char *szFeature = NULL;
  4797. unsigned int cbFeature = 0;
  4798. IECUnknown *lpUnknown = NULL;
  4799. object_ptr<IECLicense> lpLicense;
  4800. memory_ptr<char *> lpszCapas;
  4801. unsigned int ulCapas = 0;
  4802. RETVAL_FALSE;
  4803. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  4804. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &szFeature, &cbFeature) == FAILURE)
  4805. return;
  4806. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  4807. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  4808. if(MAPI_G(hr) != hrSuccess)
  4809. goto exit;
  4810. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECLicense, &~lpLicense);
  4811. if(MAPI_G(hr) != hrSuccess)
  4812. goto exit;
  4813. MAPI_G(hr) = lpLicense->LicenseCapa(0/*SERVICE_TYPE_ZCP*/, &~lpszCapas, &ulCapas);
  4814. if(MAPI_G(hr) != hrSuccess)
  4815. goto exit;
  4816. for (ULONG i = 0; i < ulCapas; ++i)
  4817. if(strcasecmp(lpszCapas[i], szFeature) == 0) {
  4818. RETVAL_TRUE;
  4819. break;
  4820. }
  4821. exit:
  4822. LOG_END();
  4823. THROW_ON_ERROR();
  4824. }
  4825. ZEND_FUNCTION(mapi_zarafa_getcapabilities)
  4826. {
  4827. PMEASURE_FUNC;
  4828. LOG_BEGIN();
  4829. zval *res = NULL;
  4830. IMsgStore *lpMsgStore = NULL;
  4831. IECUnknown *lpUnknown = NULL;
  4832. object_ptr<IECLicense> lpLicense;
  4833. memory_ptr<char *> lpszCapas;
  4834. unsigned int ulCapas = 0;
  4835. RETVAL_FALSE;
  4836. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  4837. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE)
  4838. return;
  4839. ZEND_FETCH_RESOURCE_C(lpMsgStore, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  4840. MAPI_G(hr) = GetECObject(lpMsgStore, &lpUnknown TSRMLS_CC);
  4841. if(MAPI_G(hr) != hrSuccess)
  4842. goto exit;
  4843. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECLicense, &~lpLicense);
  4844. if(MAPI_G(hr) != hrSuccess)
  4845. goto exit;
  4846. MAPI_G(hr) = lpLicense->LicenseCapa(0/*SERVICE_TYPE_ZCP*/, &~lpszCapas, &ulCapas);
  4847. if(MAPI_G(hr) != hrSuccess)
  4848. goto exit;
  4849. array_init(return_value);
  4850. for (ULONG i = 0; i < ulCapas; ++i)
  4851. add_index_string(return_value, i, lpszCapas[i], 1);
  4852. exit:
  4853. LOG_END();
  4854. THROW_ON_ERROR();
  4855. }
  4856. ZEND_FUNCTION(mapi_zarafa_getpermissionrules)
  4857. {
  4858. PMEASURE_FUNC;
  4859. LOG_BEGIN();
  4860. // params
  4861. zval *res = NULL;
  4862. LPMAPIPROP lpMapiProp = NULL;
  4863. long ulType;
  4864. // return value
  4865. zval *zval_data_value = NULL;
  4866. ULONG cPerms = 0;
  4867. memory_ptr<ECPERMISSION> lpECPerms;
  4868. // local
  4869. int type = -1;
  4870. IECUnknown *lpUnknown = NULL;
  4871. object_ptr<IECSecurity> lpSecurity;
  4872. ULONG i;
  4873. RETVAL_FALSE;
  4874. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  4875. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &res, &ulType) == FAILURE) return;
  4876. zend_list_find(res->value.lval, &type);
  4877. if(type == le_mapi_message) {
  4878. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPMESSAGE, &res, -1, name_mapi_message, le_mapi_message);
  4879. } else if (type == le_mapi_folder) {
  4880. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPMAPIFOLDER, &res, -1, name_mapi_folder, le_mapi_folder);
  4881. } else if (type == le_mapi_attachment) {
  4882. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPATTACH, &res, -1, name_mapi_attachment, le_mapi_attachment);
  4883. } else if (type == le_mapi_msgstore) {
  4884. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  4885. } else {
  4886. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Resource is not a valid MAPI resource");
  4887. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  4888. goto exit;
  4889. }
  4890. MAPI_G(hr) = GetECObject(lpMapiProp, &lpUnknown TSRMLS_CC);
  4891. if(MAPI_G(hr) != hrSuccess) {
  4892. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano object");
  4893. goto exit;
  4894. }
  4895. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECSecurity, &~lpSecurity);
  4896. if (MAPI_G(hr) != hrSuccess)
  4897. goto exit;
  4898. MAPI_G(hr) = lpSecurity->GetPermissionRules(ulType, &cPerms, &~lpECPerms);
  4899. if (MAPI_G(hr) != hrSuccess)
  4900. goto exit;
  4901. array_init(return_value);
  4902. for (i = 0; i < cPerms; ++i) {
  4903. MAKE_STD_ZVAL(zval_data_value);
  4904. array_init(zval_data_value);
  4905. add_assoc_stringl(zval_data_value, "userid", (char*)lpECPerms[i].sUserId.lpb, lpECPerms[i].sUserId.cb, 1);
  4906. add_assoc_long(zval_data_value, "type", lpECPerms[i].ulType);
  4907. add_assoc_long(zval_data_value, "rights", lpECPerms[i].ulRights);
  4908. add_assoc_long(zval_data_value, "state", lpECPerms[i].ulState);
  4909. add_index_zval(return_value, i, zval_data_value);
  4910. }
  4911. exit:
  4912. LOG_END();
  4913. THROW_ON_ERROR();
  4914. }
  4915. ZEND_FUNCTION(mapi_zarafa_setpermissionrules)
  4916. {
  4917. PMEASURE_FUNC;
  4918. LOG_BEGIN();
  4919. // params
  4920. zval *res = NULL;
  4921. zval *perms = NULL;
  4922. LPMAPIPROP lpMapiProp = NULL;
  4923. // local
  4924. int type = -1;
  4925. IECUnknown *lpUnknown = NULL;
  4926. object_ptr<IECSecurity> lpSecurity;
  4927. ULONG cPerms = 0;
  4928. memory_ptr<ECPERMISSION> lpECPerms;
  4929. HashTable *target_hash = NULL;
  4930. ULONG i, j;
  4931. zval **entry = NULL, **value = NULL;
  4932. HashTable *data = NULL;
  4933. RETVAL_FALSE;
  4934. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  4935. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra", &res, &perms) == FAILURE) return;
  4936. zend_list_find(res->value.lval, &type);
  4937. if(type == le_mapi_message) {
  4938. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPMESSAGE, &res, -1, name_mapi_message, le_mapi_message);
  4939. } else if (type == le_mapi_folder) {
  4940. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPMAPIFOLDER, &res, -1, name_mapi_folder, le_mapi_folder);
  4941. } else if (type == le_mapi_attachment) {
  4942. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPATTACH, &res, -1, name_mapi_attachment, le_mapi_attachment);
  4943. } else if (type == le_mapi_msgstore) {
  4944. ZEND_FETCH_RESOURCE_C(lpMapiProp, LPMDB, &res, -1, name_mapi_msgstore, le_mapi_msgstore);
  4945. } else {
  4946. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Resource is not a valid MAPI resource");
  4947. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  4948. goto exit;
  4949. }
  4950. MAPI_G(hr) = GetECObject(lpMapiProp, &lpUnknown TSRMLS_CC);
  4951. if(MAPI_G(hr) != hrSuccess) {
  4952. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified object is not a kopano object");
  4953. goto exit;
  4954. }
  4955. MAPI_G(hr) = lpUnknown->QueryInterface(IID_IECSecurity, &~lpSecurity);
  4956. if (MAPI_G(hr) != hrSuccess)
  4957. goto exit;
  4958. target_hash = HASH_OF(perms);
  4959. if (!target_hash) {
  4960. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  4961. goto exit;
  4962. }
  4963. // The following code should be in typeconversion.cpp
  4964. zend_hash_internal_pointer_reset(target_hash);
  4965. cPerms = zend_hash_num_elements(target_hash);
  4966. MAPI_G(hr) = MAPIAllocateBuffer(sizeof(ECPERMISSION)*cPerms, &~lpECPerms);
  4967. if (MAPI_G(hr) != hrSuccess)
  4968. goto exit;
  4969. memset(lpECPerms, 0, sizeof(ECPERMISSION)*cPerms);
  4970. for (j = 0, i = 0; i < cPerms; ++i) {
  4971. zend_hash_get_current_data(target_hash, (void **) &entry);
  4972. // null pointer returned if perms was not array(array()).
  4973. data = HASH_OF(entry[0]);
  4974. zend_hash_internal_pointer_reset(data);
  4975. if (zend_hash_find(data, "userid", sizeof("userid"), (void **)&value) != SUCCESS)
  4976. continue;
  4977. convert_to_string_ex(value);
  4978. lpECPerms[j].sUserId.cb = Z_STRLEN_PP(value);
  4979. lpECPerms[j].sUserId.lpb = (unsigned char*)Z_STRVAL_PP(value);
  4980. if (zend_hash_find(data, "type", sizeof("type"), (void **)&value) != SUCCESS)
  4981. continue;
  4982. convert_to_long_ex(value);
  4983. lpECPerms[j].ulType = Z_LVAL_PP(value);
  4984. if (zend_hash_find(data, "rights", sizeof("rights"), (void **)&value) != SUCCESS)
  4985. continue;
  4986. convert_to_long_ex(value);
  4987. lpECPerms[j].ulRights = Z_LVAL_PP(value);
  4988. if (zend_hash_find(data, "state", sizeof("state"), (void **)&value) != SUCCESS) {
  4989. convert_to_long_ex(value);
  4990. lpECPerms[j].ulState = Z_LVAL_PP(value);
  4991. } else {
  4992. lpECPerms[j].ulState = RIGHT_NEW|RIGHT_AUTOUPDATE_DENIED;
  4993. }
  4994. ++j;
  4995. zend_hash_move_forward(target_hash);
  4996. }
  4997. MAPI_G(hr) = lpSecurity->SetPermissionRules(j, lpECPerms);
  4998. if (MAPI_G(hr) != hrSuccess)
  4999. goto exit;
  5000. RETVAL_TRUE;
  5001. exit:
  5002. LOG_END();
  5003. THROW_ON_ERROR();
  5004. }
  5005. ZEND_FUNCTION(mapi_freebusysupport_open)
  5006. {
  5007. PMEASURE_FUNC;
  5008. LOG_BEGIN();
  5009. // local
  5010. object_ptr<ECFreeBusySupport> lpecFBSupport;
  5011. // extern
  5012. zval* resSession = NULL;
  5013. zval* resStore = NULL;
  5014. IMAPISession* lpSession = NULL;
  5015. IMsgStore* lpUserStore = NULL;
  5016. // return
  5017. object_ptr<IFreeBusySupport> lpFBSupport;
  5018. RETVAL_FALSE;
  5019. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5020. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|r", &resSession, &resStore) == FAILURE) return;
  5021. ZEND_FETCH_RESOURCE_C(lpSession, IMAPISession*, &resSession, -1, name_mapi_session, le_mapi_session);
  5022. if(resStore != NULL) {
  5023. ZEND_FETCH_RESOURCE_C(lpUserStore, LPMDB, &resStore, -1, name_mapi_msgstore, le_mapi_msgstore);
  5024. }
  5025. // Create the freebusy support object
  5026. MAPI_G(hr) = ECFreeBusySupport::Create(&~lpecFBSupport);
  5027. if( MAPI_G(hr) != hrSuccess)
  5028. goto exit;
  5029. MAPI_G(hr) = lpecFBSupport->QueryInterface(IID_IFreeBusySupport, &~lpFBSupport);
  5030. if( MAPI_G(hr) != hrSuccess)
  5031. goto exit;
  5032. MAPI_G(hr) = lpFBSupport->Open(lpSession, lpUserStore, (lpUserStore)?TRUE:FALSE);
  5033. if( MAPI_G(hr) != hrSuccess)
  5034. goto exit;
  5035. UOBJ_REGISTER_RESOURCE(return_value, lpFBSupport.release(), le_freebusy_support);
  5036. exit:
  5037. LOG_END();
  5038. THROW_ON_ERROR();
  5039. }
  5040. ZEND_FUNCTION(mapi_freebusysupport_close)
  5041. {
  5042. PMEASURE_FUNC;
  5043. LOG_BEGIN();
  5044. // Extern
  5045. IFreeBusySupport* lpFBSupport = NULL;
  5046. zval* resFBSupport = NULL;
  5047. RETVAL_FALSE;
  5048. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5049. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &resFBSupport) == FAILURE) return;
  5050. ZEND_FETCH_RESOURCE_C(lpFBSupport, IFreeBusySupport*, &resFBSupport, -1, name_fb_support, le_freebusy_support);
  5051. MAPI_G(hr) = lpFBSupport->Close();
  5052. if(MAPI_G(hr) != hrSuccess)
  5053. goto exit;
  5054. RETVAL_TRUE;
  5055. exit:
  5056. LOG_END();
  5057. THROW_ON_ERROR();
  5058. }
  5059. ZEND_FUNCTION(mapi_freebusysupport_loaddata)
  5060. {
  5061. PMEASURE_FUNC;
  5062. LOG_BEGIN();
  5063. HashTable* target_hash = NULL;
  5064. ULONG i, j;
  5065. zval** entry = NULL;
  5066. int rid = 0;
  5067. memory_ptr<FBUser> lpUsers;
  5068. IFreeBusySupport* lpFBSupport = NULL;
  5069. zval* resFBSupport = NULL;
  5070. zval* resUsers = NULL;
  5071. ULONG cUsers = 0;
  5072. IFreeBusyData** lppFBData = NULL;
  5073. ULONG cFBData = 0;
  5074. RETVAL_FALSE;
  5075. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5076. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra", &resFBSupport,&resUsers) == FAILURE) return;
  5077. ZEND_FETCH_RESOURCE_C(lpFBSupport, IFreeBusySupport*, &resFBSupport, -1, name_fb_support, le_freebusy_support);
  5078. target_hash = HASH_OF(resUsers);
  5079. if (!target_hash) {
  5080. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5081. goto exit;
  5082. }
  5083. zend_hash_internal_pointer_reset(target_hash);
  5084. cUsers = zend_hash_num_elements(target_hash);
  5085. MAPI_G(hr) = MAPIAllocateBuffer(sizeof(FBUser)*cUsers, &~lpUsers);
  5086. if(MAPI_G(hr) != hrSuccess)
  5087. goto exit;
  5088. // Get the user entryids
  5089. for (j = 0, i = 0; i < cUsers; ++i) {
  5090. if(zend_hash_get_current_data(target_hash, (void **) &entry) == FAILURE)
  5091. {
  5092. MAPI_G(hr) = MAPI_E_INVALID_ENTRYID;
  5093. goto exit;
  5094. }
  5095. lpUsers[j].m_cbEid = Z_STRLEN_PP(entry);
  5096. lpUsers[j].m_lpEid = (LPENTRYID)Z_STRVAL_PP(entry);
  5097. ++j;
  5098. zend_hash_move_forward(target_hash);
  5099. }
  5100. MAPI_G(hr) = MAPIAllocateBuffer(sizeof(IFreeBusyData*)*cUsers, (void**)&lppFBData);
  5101. if(MAPI_G(hr) != hrSuccess)
  5102. goto exit;
  5103. MAPI_G(hr) = lpFBSupport->LoadFreeBusyData(cUsers, lpUsers, lppFBData, NULL, &cFBData);
  5104. if(MAPI_G(hr) != hrSuccess)
  5105. goto exit;
  5106. //Return an array of IFreeBusyData interfaces
  5107. array_init(return_value);
  5108. for (i = 0; i < cUsers; ++i) {
  5109. if(lppFBData[i])
  5110. {
  5111. // Set resource relation
  5112. rid = UOBJ_REGISTER_RESOURCE(NULL, lppFBData[i], le_freebusy_data);
  5113. // Add item to return list
  5114. add_next_index_resource(return_value, rid);
  5115. }else {
  5116. // Add empty item to return list
  5117. add_next_index_null(return_value);
  5118. }
  5119. }
  5120. exit:
  5121. // do not release fbdata, it's registered in the return_value array, but not addref'd
  5122. MAPIFreeBuffer(lppFBData);
  5123. LOG_END();
  5124. THROW_ON_ERROR();
  5125. }
  5126. ZEND_FUNCTION(mapi_freebusysupport_loadupdate)
  5127. {
  5128. PMEASURE_FUNC;
  5129. LOG_BEGIN();
  5130. HashTable* target_hash = NULL;
  5131. ULONG i, j;
  5132. zval** entry = NULL;
  5133. int rid = 0;
  5134. memory_ptr<FBUser> lpUsers;
  5135. IFreeBusySupport* lpFBSupport = NULL;
  5136. zval* resFBSupport = NULL;
  5137. zval* resUsers = NULL;
  5138. ULONG cUsers = 0;
  5139. memory_ptr<IFreeBusyUpdate *> lppFBUpdate;
  5140. ULONG cFBUpdate = 0;
  5141. RETVAL_FALSE;
  5142. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5143. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra", &resFBSupport,&resUsers) == FAILURE) return;
  5144. ZEND_FETCH_RESOURCE_C(lpFBSupport, IFreeBusySupport*, &resFBSupport, -1, name_fb_support, le_freebusy_support);
  5145. target_hash = HASH_OF(resUsers);
  5146. if (!target_hash) {
  5147. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5148. goto exit;
  5149. }
  5150. zend_hash_internal_pointer_reset(target_hash);
  5151. cUsers = zend_hash_num_elements(target_hash);
  5152. MAPI_G(hr) = MAPIAllocateBuffer(sizeof(FBUser)*cUsers, &~lpUsers);
  5153. if(MAPI_G(hr) != hrSuccess)
  5154. goto exit;
  5155. // Get the user entryids
  5156. for (j = 0, i = 0; i < cUsers; ++i) {
  5157. if(zend_hash_get_current_data(target_hash, (void **) &entry) == FAILURE)
  5158. {
  5159. MAPI_G(hr) = MAPI_E_INVALID_ENTRYID;
  5160. goto exit;
  5161. }
  5162. lpUsers[j].m_cbEid = Z_STRLEN_PP(entry);
  5163. lpUsers[j].m_lpEid = (LPENTRYID)Z_STRVAL_PP(entry);
  5164. ++j;
  5165. zend_hash_move_forward(target_hash);
  5166. }
  5167. MAPI_G(hr) = MAPIAllocateBuffer(sizeof(IFreeBusyUpdate*)*cUsers, &~lppFBUpdate);
  5168. if(MAPI_G(hr) != hrSuccess)
  5169. goto exit;
  5170. MAPI_G(hr) = lpFBSupport->LoadFreeBusyUpdate(cUsers, lpUsers, lppFBUpdate, &cFBUpdate, NULL);
  5171. if(MAPI_G(hr) != hrSuccess)
  5172. goto exit;
  5173. //Return an array of IFreeBusyUpdate interfaces
  5174. array_init(return_value);
  5175. for (i = 0; i < cUsers; ++i) {
  5176. if(lppFBUpdate[i])
  5177. {
  5178. // Set resource relation
  5179. rid = UOBJ_REGISTER_RESOURCE(NULL, lppFBUpdate[i], le_freebusy_update);
  5180. // Add item to return list
  5181. add_next_index_resource(return_value, rid);
  5182. }else {
  5183. // Add empty item to return list
  5184. add_next_index_null(return_value);
  5185. }
  5186. }
  5187. exit:
  5188. LOG_END();
  5189. THROW_ON_ERROR();
  5190. }
  5191. ZEND_FUNCTION(mapi_freebusydata_enumblocks)
  5192. {
  5193. PMEASURE_FUNC;
  5194. LOG_BEGIN();
  5195. IFreeBusyData* lpFBData = NULL;
  5196. zval* resFBData = NULL;
  5197. FILETIME ftmStart;
  5198. FILETIME ftmEnd;
  5199. time_t ulUnixStart = 0;
  5200. time_t ulUnixEnd = 0;
  5201. IEnumFBBlock* lpEnumBlock = NULL;
  5202. RETVAL_FALSE;
  5203. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5204. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &resFBData, &ulUnixStart, &ulUnixEnd) == FAILURE) return;
  5205. ZEND_FETCH_RESOURCE_C(lpFBData, IFreeBusyData*, &resFBData, -1, name_fb_data, le_freebusy_data);
  5206. UnixTimeToFileTime(ulUnixStart, &ftmStart);
  5207. UnixTimeToFileTime(ulUnixEnd, &ftmEnd);
  5208. MAPI_G(hr) = lpFBData->EnumBlocks(&lpEnumBlock, ftmStart, ftmEnd);
  5209. if(MAPI_G(hr) != hrSuccess)
  5210. goto exit;
  5211. UOBJ_REGISTER_RESOURCE(return_value, lpEnumBlock, le_freebusy_enumblock);
  5212. exit:
  5213. LOG_END();
  5214. THROW_ON_ERROR();
  5215. }
  5216. ZEND_FUNCTION(mapi_freebusydata_getpublishrange)
  5217. {
  5218. PMEASURE_FUNC;
  5219. LOG_BEGIN();
  5220. IFreeBusyData* lpFBData = NULL;
  5221. zval* resFBData = NULL;
  5222. LONG rtmStart;
  5223. LONG rtmEnd;
  5224. time_t ulUnixStart = 0;
  5225. time_t ulUnixEnd = 0;
  5226. RETVAL_FALSE;
  5227. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5228. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &resFBData) == FAILURE) return;
  5229. ZEND_FETCH_RESOURCE_C(lpFBData, IFreeBusyData*, &resFBData, -1, name_fb_data, le_freebusy_data);
  5230. MAPI_G(hr) = lpFBData->GetFBPublishRange(&rtmStart, &rtmEnd);
  5231. if(MAPI_G(hr) != hrSuccess)
  5232. goto exit;
  5233. RTimeToUnixTime(rtmStart, &ulUnixStart);
  5234. RTimeToUnixTime(rtmEnd, &ulUnixEnd);
  5235. array_init(return_value);
  5236. add_assoc_long(return_value, "start", ulUnixStart);
  5237. add_assoc_long(return_value, "end", ulUnixEnd);
  5238. exit:
  5239. LOG_END();
  5240. THROW_ON_ERROR();
  5241. }
  5242. ZEND_FUNCTION(mapi_freebusydata_setrange)
  5243. {
  5244. PMEASURE_FUNC;
  5245. LOG_BEGIN();
  5246. IFreeBusyData* lpFBData = NULL;
  5247. zval* resFBData = NULL;
  5248. LONG rtmStart;
  5249. LONG rtmEnd;
  5250. time_t ulUnixStart = 0;
  5251. time_t ulUnixEnd = 0;
  5252. RETVAL_FALSE;
  5253. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5254. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &resFBData, &ulUnixStart, &ulUnixEnd) == FAILURE) return;
  5255. ZEND_FETCH_RESOURCE_C(lpFBData, IFreeBusyData*, &resFBData, -1, name_fb_data, le_freebusy_data);
  5256. UnixTimeToRTime(ulUnixStart, &rtmStart);
  5257. UnixTimeToRTime(ulUnixEnd, &rtmEnd);
  5258. MAPI_G(hr) = lpFBData->SetFBRange(rtmStart, rtmEnd);
  5259. if(MAPI_G(hr) != hrSuccess)
  5260. goto exit;
  5261. RETVAL_TRUE;
  5262. exit:
  5263. LOG_END();
  5264. THROW_ON_ERROR();
  5265. }
  5266. ZEND_FUNCTION(mapi_freebusyenumblock_reset)
  5267. {
  5268. PMEASURE_FUNC;
  5269. LOG_BEGIN();
  5270. IEnumFBBlock* lpEnumBlock = NULL;
  5271. zval* resEnumBlock = NULL;
  5272. RETVAL_FALSE;
  5273. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5274. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &resEnumBlock) == FAILURE) return;
  5275. ZEND_FETCH_RESOURCE_C(lpEnumBlock, IEnumFBBlock*, &resEnumBlock, -1, name_fb_enumblock, le_freebusy_enumblock);
  5276. MAPI_G(hr) = lpEnumBlock->Reset();
  5277. if(MAPI_G(hr) != hrSuccess)
  5278. goto exit;
  5279. RETVAL_TRUE;
  5280. exit:
  5281. LOG_END();
  5282. THROW_ON_ERROR();
  5283. }
  5284. ZEND_FUNCTION(mapi_freebusyenumblock_next)
  5285. {
  5286. PMEASURE_FUNC;
  5287. LOG_BEGIN();
  5288. IEnumFBBlock* lpEnumBlock = NULL;
  5289. zval* resEnumBlock = NULL;
  5290. long cElt = 0;
  5291. LONG cFetch = 0;
  5292. LONG i;
  5293. memory_ptr<FBBlock_1> lpBlk;
  5294. time_t ulUnixStart = 0;
  5295. time_t ulUnixEnd = 0;
  5296. zval *zval_data_value = NULL;
  5297. RETVAL_FALSE;
  5298. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5299. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &resEnumBlock, &cElt) == FAILURE) return;
  5300. ZEND_FETCH_RESOURCE_C(lpEnumBlock, IEnumFBBlock*, &resEnumBlock, -1, name_fb_enumblock, le_freebusy_enumblock);
  5301. MAPI_G(hr) = MAPIAllocateBuffer(sizeof(FBBlock_1)*cElt, &~lpBlk);
  5302. if(MAPI_G(hr) != hrSuccess)
  5303. goto exit;
  5304. MAPI_G(hr) = lpEnumBlock->Next(cElt, lpBlk, &cFetch);
  5305. if(MAPI_G(hr) != hrSuccess)
  5306. goto exit;
  5307. array_init(return_value);
  5308. for (i = 0; i < cFetch; ++i) {
  5309. MAKE_STD_ZVAL(zval_data_value);
  5310. array_init(zval_data_value);
  5311. RTimeToUnixTime(lpBlk[i].m_tmStart, &ulUnixStart);
  5312. RTimeToUnixTime(lpBlk[i].m_tmEnd, &ulUnixEnd);
  5313. add_assoc_long(zval_data_value, "start", ulUnixStart);
  5314. add_assoc_long(zval_data_value, "end", ulUnixEnd);
  5315. add_assoc_long(zval_data_value, "status", (LONG)lpBlk[i].m_fbstatus);
  5316. add_next_index_zval(return_value, zval_data_value);
  5317. }
  5318. exit:
  5319. LOG_END();
  5320. THROW_ON_ERROR();
  5321. }
  5322. ZEND_FUNCTION(mapi_freebusyenumblock_skip)
  5323. {
  5324. PMEASURE_FUNC;
  5325. LOG_BEGIN();
  5326. IEnumFBBlock* lpEnumBlock = NULL;
  5327. zval* resEnumBlock = NULL;
  5328. long ulSkip = 0;
  5329. RETVAL_FALSE;
  5330. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5331. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &resEnumBlock, &ulSkip) == FAILURE) return;
  5332. ZEND_FETCH_RESOURCE_C(lpEnumBlock, IEnumFBBlock*, &resEnumBlock, -1, name_fb_enumblock, le_freebusy_enumblock);
  5333. MAPI_G(hr) = lpEnumBlock->Skip(ulSkip);
  5334. if(MAPI_G(hr) != hrSuccess)
  5335. goto exit;
  5336. RETVAL_TRUE;
  5337. exit:
  5338. LOG_END();
  5339. THROW_ON_ERROR();
  5340. }
  5341. ZEND_FUNCTION(mapi_freebusyenumblock_restrict)
  5342. {
  5343. PMEASURE_FUNC;
  5344. LOG_BEGIN();
  5345. IEnumFBBlock* lpEnumBlock = NULL;
  5346. zval* resEnumBlock = NULL;
  5347. FILETIME ftmStart;
  5348. FILETIME ftmEnd;
  5349. time_t ulUnixStart = 0;
  5350. time_t ulUnixEnd = 0;
  5351. RETVAL_FALSE;
  5352. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5353. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &resEnumBlock, &ulUnixStart, &ulUnixEnd) == FAILURE) return;
  5354. ZEND_FETCH_RESOURCE_C(lpEnumBlock, IEnumFBBlock*, &resEnumBlock, -1, name_fb_enumblock, le_freebusy_enumblock);
  5355. UnixTimeToFileTime(ulUnixStart, &ftmStart);
  5356. UnixTimeToFileTime(ulUnixEnd, &ftmEnd);
  5357. MAPI_G(hr) = lpEnumBlock->Restrict(ftmStart, ftmEnd);
  5358. if(MAPI_G(hr) != hrSuccess)
  5359. goto exit;
  5360. RETVAL_TRUE;
  5361. exit:
  5362. LOG_END();
  5363. THROW_ON_ERROR();
  5364. }
  5365. ZEND_FUNCTION(mapi_freebusyupdate_publish)
  5366. {
  5367. PMEASURE_FUNC;
  5368. LOG_BEGIN();
  5369. // params
  5370. zval* resFBUpdate = NULL;
  5371. zval* aBlocks = NULL;
  5372. IFreeBusyUpdate* lpFBUpdate = NULL;
  5373. // local
  5374. memory_ptr<FBBlock_1> lpBlocks;
  5375. ULONG cBlocks = 0;
  5376. HashTable* target_hash = NULL;
  5377. ULONG i;
  5378. zval** entry = NULL;
  5379. zval** value = NULL;
  5380. HashTable* data = NULL;
  5381. RETVAL_FALSE;
  5382. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5383. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra", &resFBUpdate, &aBlocks) == FAILURE) return;
  5384. ZEND_FETCH_RESOURCE_C(lpFBUpdate, IFreeBusyUpdate*, &resFBUpdate, -1, name_fb_update, le_freebusy_update);
  5385. target_hash = HASH_OF(aBlocks);
  5386. if (!target_hash) {
  5387. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5388. goto exit;
  5389. }
  5390. zend_hash_internal_pointer_reset(target_hash);
  5391. cBlocks = zend_hash_num_elements(target_hash);
  5392. MAPI_G(hr) = MAPIAllocateBuffer(sizeof(FBBlock_1)*cBlocks, &~lpBlocks);
  5393. if(MAPI_G(hr) != hrSuccess)
  5394. goto exit;
  5395. for (i = 0; i < cBlocks; ++i) {
  5396. zend_hash_get_current_data(target_hash, (void **) &entry);
  5397. data = HASH_OF(entry[0]);
  5398. zend_hash_internal_pointer_reset(data);
  5399. if (zend_hash_find(data, "start", sizeof("start"), reinterpret_cast<void **>(&value)) != SUCCESS) {
  5400. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5401. goto exit;
  5402. }
  5403. UnixTimeToRTime(Z_LVAL_PP(value), &lpBlocks[i].m_tmStart);
  5404. if (zend_hash_find(data, "end", sizeof("end"), reinterpret_cast<void **>(&value)) != SUCCESS) {
  5405. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5406. goto exit;
  5407. }
  5408. UnixTimeToRTime(Z_LVAL_PP(value), &lpBlocks[i].m_tmEnd);
  5409. if (zend_hash_find(data, "status", sizeof("status"), reinterpret_cast<void **>(&value)) != SUCCESS) {
  5410. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5411. goto exit;
  5412. }
  5413. lpBlocks[i].m_fbstatus = (enum FBStatus)Z_LVAL_PP(value);
  5414. zend_hash_move_forward(target_hash);
  5415. }
  5416. MAPI_G(hr) = lpFBUpdate->PublishFreeBusy(lpBlocks, cBlocks);
  5417. if(MAPI_G(hr) != hrSuccess)
  5418. goto exit;
  5419. RETVAL_TRUE;
  5420. exit:
  5421. LOG_END();
  5422. THROW_ON_ERROR();
  5423. }
  5424. ZEND_FUNCTION(mapi_freebusyupdate_reset)
  5425. {
  5426. PMEASURE_FUNC;
  5427. LOG_BEGIN();
  5428. IFreeBusyUpdate* lpFBUpdate = NULL;
  5429. zval* resFBUpdate = NULL;
  5430. RETVAL_FALSE;
  5431. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5432. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &resFBUpdate) == FAILURE) return;
  5433. ZEND_FETCH_RESOURCE_C(lpFBUpdate, IFreeBusyUpdate*, &resFBUpdate, -1, name_fb_update, le_freebusy_update);
  5434. MAPI_G(hr) = lpFBUpdate->ResetPublishedFreeBusy();
  5435. if(MAPI_G(hr) != hrSuccess)
  5436. goto exit;
  5437. RETVAL_TRUE;
  5438. exit:
  5439. LOG_END();
  5440. THROW_ON_ERROR();
  5441. }
  5442. ZEND_FUNCTION(mapi_freebusyupdate_savechanges)
  5443. {
  5444. PMEASURE_FUNC;
  5445. LOG_BEGIN();
  5446. // params
  5447. zval* resFBUpdate = NULL;
  5448. time_t ulUnixStart = 0;
  5449. time_t ulUnixEnd = 0;
  5450. IFreeBusyUpdate* lpFBUpdate = NULL;
  5451. // local
  5452. FILETIME ftmStart;
  5453. FILETIME ftmEnd;
  5454. RETVAL_FALSE;
  5455. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5456. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &resFBUpdate, &ulUnixStart, &ulUnixEnd) == FAILURE) return;
  5457. ZEND_FETCH_RESOURCE_C(lpFBUpdate, IFreeBusyUpdate*, &resFBUpdate, -1, name_fb_update, le_freebusy_update);
  5458. UnixTimeToFileTime(ulUnixStart, &ftmStart);
  5459. UnixTimeToFileTime(ulUnixEnd, &ftmEnd);
  5460. MAPI_G(hr) = lpFBUpdate->SaveChanges(ftmStart, ftmEnd);
  5461. if(MAPI_G(hr) != hrSuccess)
  5462. goto exit;
  5463. RETVAL_TRUE;
  5464. exit:
  5465. LOG_END();
  5466. THROW_ON_ERROR();
  5467. }
  5468. ZEND_FUNCTION(mapi_favorite_add)
  5469. {
  5470. PMEASURE_FUNC;
  5471. LOG_BEGIN();
  5472. // params
  5473. zval * resSession = NULL;
  5474. zval * resFolder = NULL;
  5475. IMAPISession *lpSession = NULL;
  5476. LPMAPIFOLDER lpFolder = NULL;
  5477. long ulFlags = 0;
  5478. // local
  5479. object_ptr<IMAPIFolder> lpShortCutFolder;
  5480. ULONG cbAliasName = 0;
  5481. LPSTR lpszAliasName = NULL;
  5482. RETVAL_FALSE;
  5483. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5484. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr|sl", &resSession, &resFolder, &lpszAliasName, &cbAliasName, &ulFlags) == FAILURE) return;
  5485. ZEND_FETCH_RESOURCE_C(lpSession, IMAPISession *, &resSession, -1, name_mapi_session, le_mapi_session);
  5486. ZEND_FETCH_RESOURCE_C(lpFolder, LPMAPIFOLDER, &resFolder, -1, name_mapi_folder, le_mapi_folder);
  5487. if(cbAliasName == 0)
  5488. lpszAliasName = NULL;
  5489. MAPI_G(hr) = GetShortcutFolder(lpSession, nullptr, nullptr, MAPI_CREATE, &~lpShortCutFolder); // use english language
  5490. if(MAPI_G(hr) != hrSuccess)
  5491. goto exit;
  5492. MAPI_G(hr) = AddFavoriteFolder(lpShortCutFolder, lpFolder, (LPCTSTR) lpszAliasName, ulFlags);
  5493. if(MAPI_G(hr) != hrSuccess)
  5494. goto exit;
  5495. RETVAL_TRUE;
  5496. exit:
  5497. LOG_END();
  5498. THROW_ON_ERROR();
  5499. }
  5500. /*
  5501. ***********************************************************************************
  5502. * ICS interfaces
  5503. ***********************************************************************************eight
  5504. */
  5505. ZEND_FUNCTION(mapi_exportchanges_config)
  5506. {
  5507. PMEASURE_FUNC;
  5508. LOG_BEGIN();
  5509. IUnknown * lpImportChanges = NULL; // may be contents or hierarchy
  5510. IExchangeExportChanges *lpExportChanges = NULL;
  5511. IStream * lpStream = NULL;
  5512. zval * resStream = NULL;
  5513. long ulFlags = 0;
  5514. long ulBuffersize = 0;
  5515. zval * resImportChanges = NULL;
  5516. zval * resExportChanges = NULL;
  5517. zval * aRestrict = NULL;
  5518. zval * aIncludeProps = NULL;
  5519. zval * aExcludeProps = NULL;
  5520. int type = -1;
  5521. memory_ptr<SRestriction> lpRestrict;
  5522. memory_ptr<SPropTagArray> lpIncludeProps, lpExcludeProps;
  5523. RETVAL_FALSE;
  5524. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5525. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrlzzzzl", &resExportChanges, &resStream, &ulFlags, &resImportChanges, &aRestrict, &aIncludeProps, &aExcludeProps, &ulBuffersize) == FAILURE) return;
  5526. ZEND_FETCH_RESOURCE_C(lpExportChanges, IExchangeExportChanges *, &resExportChanges, -1, name_mapi_exportchanges, le_mapi_exportchanges);
  5527. if(Z_TYPE_P(resImportChanges) == IS_RESOURCE) {
  5528. zend_list_find(resImportChanges->value.lval, &type);
  5529. if(type == le_mapi_importcontentschanges) {
  5530. ZEND_FETCH_RESOURCE_C(lpImportChanges, IUnknown *, &resImportChanges, -1, name_mapi_importcontentschanges, le_mapi_importcontentschanges);
  5531. } else if(type == le_mapi_importhierarchychanges) {
  5532. ZEND_FETCH_RESOURCE_C(lpImportChanges, IUnknown *, &resImportChanges, -1, name_mapi_importhierarchychanges, le_mapi_importhierarchychanges);
  5533. } else {
  5534. php_error_docref(NULL TSRMLS_CC, E_WARNING, "The importer must be either a contents importer or a hierarchy importer object");
  5535. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5536. goto exit;
  5537. }
  5538. } else if(Z_TYPE_P(resImportChanges) == IS_BOOL && !resImportChanges->value.lval) {
  5539. lpImportChanges = NULL;
  5540. } else {
  5541. php_error_docref(NULL TSRMLS_CC, E_WARNING, "The importer must be an actual importer resource, or FALSE");
  5542. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5543. goto exit;
  5544. }
  5545. ZEND_FETCH_RESOURCE_C(lpStream, IStream *, &resStream, -1, name_istream, le_istream);
  5546. if(Z_TYPE_P(aRestrict) == IS_ARRAY) {
  5547. MAPI_G(hr) = MAPIAllocateBuffer(sizeof(SRestriction), &~lpRestrict);
  5548. if (MAPI_G(hr) != hrSuccess)
  5549. goto exit;
  5550. MAPI_G(hr) = PHPArraytoSRestriction(aRestrict, lpRestrict, lpRestrict TSRMLS_CC);
  5551. if (MAPI_G(hr) != hrSuccess)
  5552. goto exit;
  5553. }
  5554. if(Z_TYPE_P(aIncludeProps) == IS_ARRAY) {
  5555. MAPI_G(hr) = PHPArraytoPropTagArray(aIncludeProps, NULL, &~lpIncludeProps TSRMLS_CC);
  5556. if(MAPI_G(hr) != hrSuccess) {
  5557. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to parse includeprops array");
  5558. goto exit;
  5559. }
  5560. }
  5561. if(Z_TYPE_P(aExcludeProps) == IS_ARRAY) {
  5562. MAPI_G(hr) = PHPArraytoPropTagArray(aExcludeProps, NULL, &~lpExcludeProps TSRMLS_CC);
  5563. if(MAPI_G(hr) != hrSuccess) {
  5564. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to parse excludeprops array");
  5565. goto exit;
  5566. }
  5567. }
  5568. MAPI_G(hr) = lpExportChanges->Config(lpStream, ulFlags, lpImportChanges, lpRestrict, lpIncludeProps, lpExcludeProps, ulBuffersize);
  5569. if(MAPI_G(hr) != hrSuccess)
  5570. goto exit;
  5571. RETVAL_TRUE;
  5572. exit:
  5573. LOG_END();
  5574. THROW_ON_ERROR();
  5575. }
  5576. ZEND_FUNCTION(mapi_exportchanges_synchronize)
  5577. {
  5578. PMEASURE_FUNC;
  5579. LOG_BEGIN();
  5580. zval * resExportChanges = NULL;
  5581. IExchangeExportChanges *lpExportChanges = NULL;
  5582. ULONG ulSteps = 0;
  5583. ULONG ulProgress = 0;
  5584. RETVAL_FALSE;
  5585. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5586. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &resExportChanges) == FAILURE) return;
  5587. ZEND_FETCH_RESOURCE_C(lpExportChanges, IExchangeExportChanges *, &resExportChanges, -1, name_mapi_exportchanges, le_mapi_exportchanges);
  5588. MAPI_G(hr) = lpExportChanges->Synchronize(&ulSteps, &ulProgress);
  5589. if(MAPI_G(hr) == SYNC_W_PROGRESS) {
  5590. array_init(return_value);
  5591. add_next_index_long(return_value, ulSteps);
  5592. add_next_index_long(return_value, ulProgress);
  5593. } else if(MAPI_G(hr) != hrSuccess) {
  5594. goto exit;
  5595. } else {
  5596. // hr == hrSuccess
  5597. RETVAL_TRUE;
  5598. }
  5599. exit:
  5600. LOG_END();
  5601. THROW_ON_ERROR();
  5602. }
  5603. ZEND_FUNCTION(mapi_exportchanges_updatestate)
  5604. {
  5605. PMEASURE_FUNC;
  5606. LOG_BEGIN();
  5607. zval * resExportChanges = NULL;
  5608. zval * resStream = NULL;
  5609. IExchangeExportChanges *lpExportChanges = NULL;
  5610. IStream * lpStream = NULL;
  5611. RETVAL_FALSE;
  5612. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5613. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &resExportChanges, &resStream) == FAILURE) return;
  5614. ZEND_FETCH_RESOURCE_C(lpExportChanges, IExchangeExportChanges *, &resExportChanges, -1, name_mapi_exportchanges, le_mapi_exportchanges);
  5615. ZEND_FETCH_RESOURCE_C(lpStream, IStream *, &resStream, -1, name_istream, le_istream);
  5616. MAPI_G(hr) = lpExportChanges->UpdateState(lpStream);
  5617. if(MAPI_G(hr) != hrSuccess)
  5618. goto exit;
  5619. RETVAL_TRUE;
  5620. exit:
  5621. LOG_END();
  5622. THROW_ON_ERROR();
  5623. }
  5624. ZEND_FUNCTION(mapi_exportchanges_getchangecount)
  5625. {
  5626. PMEASURE_FUNC;
  5627. LOG_BEGIN();
  5628. zval * resExportChanges = NULL;
  5629. IExchangeExportChanges *lpExportChanges = NULL;
  5630. object_ptr<IECExportChanges> lpECExportChanges;
  5631. ULONG ulChanges;
  5632. RETVAL_FALSE;
  5633. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5634. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &resExportChanges) == FAILURE) return;
  5635. ZEND_FETCH_RESOURCE_C(lpExportChanges, IExchangeExportChanges *, &resExportChanges, -1, name_mapi_exportchanges, le_mapi_exportchanges);
  5636. MAPI_G(hr) = lpExportChanges->QueryInterface(IID_IECExportChanges, &~lpECExportChanges);
  5637. if(MAPI_G(hr) != hrSuccess) {
  5638. php_error_docref(NULL TSRMLS_CC, E_WARNING, "ExportChanges does not support IECExportChanges interface which is required for the getchangecount call");
  5639. goto exit;
  5640. }
  5641. MAPI_G(hr) = lpECExportChanges->GetChangeCount(&ulChanges);
  5642. if(MAPI_G(hr) != hrSuccess)
  5643. goto exit;
  5644. RETVAL_LONG(ulChanges);
  5645. exit:
  5646. LOG_END();
  5647. THROW_ON_ERROR();
  5648. }
  5649. ZEND_FUNCTION(mapi_importcontentschanges_config)
  5650. {
  5651. PMEASURE_FUNC;
  5652. LOG_BEGIN();
  5653. zval * resImportContentsChanges = NULL;
  5654. zval * resStream = NULL;
  5655. IExchangeImportContentsChanges *lpImportContentsChanges = NULL;
  5656. IStream * lpStream = NULL;
  5657. long ulFlags = 0;
  5658. RETVAL_FALSE;
  5659. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5660. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrl", &resImportContentsChanges, &resStream, &ulFlags) == FAILURE) return;
  5661. ZEND_FETCH_RESOURCE_C(lpImportContentsChanges, IExchangeImportContentsChanges *, &resImportContentsChanges, -1, name_mapi_importcontentschanges, le_mapi_importcontentschanges);
  5662. ZEND_FETCH_RESOURCE_C(lpStream, IStream *, &resStream, -1, name_istream, le_istream);
  5663. MAPI_G(hr) = lpImportContentsChanges->Config(lpStream, ulFlags);
  5664. if(MAPI_G(hr) != hrSuccess)
  5665. goto exit;
  5666. RETVAL_TRUE;
  5667. exit:
  5668. LOG_END();
  5669. THROW_ON_ERROR();
  5670. }
  5671. ZEND_FUNCTION(mapi_importcontentschanges_updatestate)
  5672. {
  5673. PMEASURE_FUNC;
  5674. LOG_BEGIN();
  5675. zval * resImportContentsChanges = NULL;
  5676. zval * resStream = NULL;
  5677. IExchangeImportContentsChanges *lpImportContentsChanges = NULL;
  5678. IStream * lpStream = NULL;
  5679. RETVAL_FALSE;
  5680. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5681. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|r", &resImportContentsChanges, &resStream) == FAILURE) return;
  5682. ZEND_FETCH_RESOURCE_C(lpImportContentsChanges, IExchangeImportContentsChanges *, &resImportContentsChanges, -1, name_mapi_importcontentschanges, le_mapi_importcontentschanges);
  5683. if (resStream != NULL) {
  5684. ZEND_FETCH_RESOURCE_C(lpStream, IStream *, &resStream, -1, name_istream, le_istream);
  5685. }
  5686. MAPI_G(hr) = lpImportContentsChanges->UpdateState(lpStream);
  5687. if(MAPI_G(hr) != hrSuccess)
  5688. goto exit;
  5689. RETVAL_TRUE;
  5690. exit:
  5691. LOG_END();
  5692. THROW_ON_ERROR();
  5693. }
  5694. ZEND_FUNCTION(mapi_importcontentschanges_importmessagechange)
  5695. {
  5696. PMEASURE_FUNC;
  5697. LOG_BEGIN();
  5698. zval * resImportContentsChanges = NULL;
  5699. zval * resProps = NULL;
  5700. long ulFlags = 0;
  5701. zval * resMessage = NULL;
  5702. memory_ptr<SPropValue> lpProps;
  5703. ULONG cValues = 0;
  5704. IMessage * lpMessage = NULL;
  5705. IExchangeImportContentsChanges * lpImportContentsChanges = NULL;
  5706. RETVAL_FALSE;
  5707. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5708. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ralz", &resImportContentsChanges, &resProps, &ulFlags, &resMessage) == FAILURE) return;
  5709. ZEND_FETCH_RESOURCE_C(lpImportContentsChanges, IExchangeImportContentsChanges *, &resImportContentsChanges, -1, name_mapi_importcontentschanges, le_mapi_importcontentschanges);
  5710. MAPI_G(hr) = PHPArraytoPropValueArray(resProps, NULL, &cValues, &~lpProps TSRMLS_CC);
  5711. if(MAPI_G(hr) != hrSuccess) {
  5712. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to parse property array");
  5713. goto exit;
  5714. }
  5715. MAPI_G(hr) = lpImportContentsChanges->ImportMessageChange(cValues, lpProps, ulFlags, &lpMessage);
  5716. if (MAPI_G(hr) != hrSuccess)
  5717. goto exit;
  5718. UOBJ_REGISTER_RESOURCE(resMessage, lpMessage, le_mapi_message);
  5719. RETVAL_TRUE;
  5720. exit:
  5721. LOG_END();
  5722. THROW_ON_ERROR();
  5723. }
  5724. ZEND_FUNCTION(mapi_importcontentschanges_importmessagedeletion)
  5725. {
  5726. PMEASURE_FUNC;
  5727. LOG_BEGIN();
  5728. zval * resMessages;
  5729. zval * resImportContentsChanges;
  5730. IExchangeImportContentsChanges *lpImportContentsChanges = NULL;
  5731. memory_ptr<SBinaryArray> lpMessages;
  5732. long ulFlags = 0;
  5733. RETVAL_FALSE;
  5734. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5735. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rla", &resImportContentsChanges, &ulFlags, &resMessages) == FAILURE) return;
  5736. ZEND_FETCH_RESOURCE_C(lpImportContentsChanges, IExchangeImportContentsChanges *, &resImportContentsChanges, -1, name_mapi_importcontentschanges, le_mapi_importcontentschanges);
  5737. MAPI_G(hr) = PHPArraytoSBinaryArray(resMessages, NULL, &~lpMessages TSRMLS_CC);
  5738. if(MAPI_G(hr) != hrSuccess) {
  5739. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to parse message list");
  5740. goto exit;
  5741. }
  5742. MAPI_G(hr) = lpImportContentsChanges->ImportMessageDeletion(ulFlags, lpMessages);
  5743. if(MAPI_G(hr) != hrSuccess)
  5744. goto exit;
  5745. exit:
  5746. LOG_END();
  5747. THROW_ON_ERROR();
  5748. }
  5749. ZEND_FUNCTION(mapi_importcontentschanges_importperuserreadstatechange)
  5750. {
  5751. PMEASURE_FUNC;
  5752. LOG_BEGIN();
  5753. zval * resReadStates;
  5754. zval * resImportContentsChanges;
  5755. IExchangeImportContentsChanges *lpImportContentsChanges = NULL;
  5756. memory_ptr<READSTATE> lpReadStates;
  5757. ULONG cValues = 0;
  5758. RETVAL_FALSE;
  5759. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5760. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra", &resImportContentsChanges, &resReadStates) == FAILURE) return;
  5761. ZEND_FETCH_RESOURCE_C(lpImportContentsChanges, IExchangeImportContentsChanges *, &resImportContentsChanges, -1, name_mapi_importcontentschanges, le_mapi_importcontentschanges);
  5762. MAPI_G(hr) = PHPArraytoReadStateArray(resReadStates, NULL, &cValues, &~lpReadStates TSRMLS_CC);
  5763. if(MAPI_G(hr) != hrSuccess) {
  5764. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to parse readstates");
  5765. goto exit;
  5766. }
  5767. MAPI_G(hr) = lpImportContentsChanges->ImportPerUserReadStateChange(cValues, lpReadStates);
  5768. if(MAPI_G(hr) != hrSuccess)
  5769. goto exit;
  5770. RETVAL_TRUE;
  5771. exit:
  5772. LOG_END();
  5773. THROW_ON_ERROR();
  5774. }
  5775. ZEND_FUNCTION(mapi_importcontentschanges_importmessagemove)
  5776. {
  5777. PMEASURE_FUNC;
  5778. LOG_BEGIN();
  5779. ULONG cbSourceKeySrcFolder = 0;
  5780. BYTE * pbSourceKeySrcFolder = NULL;
  5781. ULONG cbSourceKeySrcMessage = 0;
  5782. BYTE * pbSourceKeySrcMessage = NULL;
  5783. ULONG cbPCLMessage = 0;
  5784. BYTE * pbPCLMessage = NULL;
  5785. ULONG cbSourceKeyDestMessage = 0;
  5786. BYTE * pbSourceKeyDestMessage = NULL;
  5787. ULONG cbChangeNumDestMessage = 0;
  5788. BYTE * pbChangeNumDestMessage = NULL;
  5789. zval * resImportContentsChanges;
  5790. IExchangeImportContentsChanges *lpImportContentsChanges = NULL;
  5791. RETVAL_FALSE;
  5792. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5793. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsssss", &resImportContentsChanges,
  5794. &pbSourceKeySrcFolder, &cbSourceKeySrcFolder,
  5795. &pbSourceKeySrcMessage, &cbSourceKeySrcMessage,
  5796. &pbPCLMessage, &cbPCLMessage,
  5797. &pbSourceKeyDestMessage, &cbSourceKeyDestMessage,
  5798. &pbChangeNumDestMessage, &cbChangeNumDestMessage) == FAILURE) return;
  5799. ZEND_FETCH_RESOURCE_C(lpImportContentsChanges, IExchangeImportContentsChanges *, &resImportContentsChanges, -1, name_mapi_importcontentschanges, le_mapi_importcontentschanges);
  5800. MAPI_G(hr) = lpImportContentsChanges->ImportMessageMove(cbSourceKeySrcFolder, pbSourceKeySrcFolder, cbSourceKeySrcMessage, pbSourceKeySrcMessage, cbPCLMessage, pbPCLMessage, cbSourceKeyDestMessage, pbSourceKeyDestMessage, cbChangeNumDestMessage, pbChangeNumDestMessage);
  5801. if(MAPI_G(hr) != hrSuccess)
  5802. goto exit;
  5803. exit:
  5804. LOG_END();
  5805. THROW_ON_ERROR();
  5806. }
  5807. ZEND_FUNCTION(mapi_importhierarchychanges_config)
  5808. {
  5809. PMEASURE_FUNC;
  5810. LOG_BEGIN();
  5811. zval * resImportHierarchyChanges = NULL;
  5812. zval * resStream = NULL;
  5813. IExchangeImportHierarchyChanges *lpImportHierarchyChanges = NULL;
  5814. IStream * lpStream = NULL;
  5815. long ulFlags = 0;
  5816. RETVAL_FALSE;
  5817. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5818. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrl", &resImportHierarchyChanges, &resStream, &ulFlags) == FAILURE) return;
  5819. ZEND_FETCH_RESOURCE_C(lpImportHierarchyChanges, IExchangeImportHierarchyChanges *, &resImportHierarchyChanges, -1, name_mapi_importhierarchychanges, le_mapi_importhierarchychanges);
  5820. ZEND_FETCH_RESOURCE_C(lpStream, IStream *, &resStream, -1, name_istream, le_istream);
  5821. MAPI_G(hr) = lpImportHierarchyChanges->Config(lpStream, ulFlags);
  5822. if(MAPI_G(hr) != hrSuccess)
  5823. goto exit;
  5824. RETVAL_TRUE;
  5825. exit:
  5826. LOG_END();
  5827. THROW_ON_ERROR();
  5828. }
  5829. ZEND_FUNCTION(mapi_importhierarchychanges_updatestate)
  5830. {
  5831. PMEASURE_FUNC;
  5832. LOG_BEGIN();
  5833. zval * resImportHierarchyChanges = NULL;
  5834. zval * resStream = NULL;
  5835. IExchangeImportHierarchyChanges *lpImportHierarchyChanges = NULL;
  5836. IStream * lpStream = NULL;
  5837. RETVAL_FALSE;
  5838. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5839. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|r", &resImportHierarchyChanges, &resStream) == FAILURE) return;
  5840. ZEND_FETCH_RESOURCE_C(lpImportHierarchyChanges, IExchangeImportHierarchyChanges *, &resImportHierarchyChanges, -1, name_mapi_importhierarchychanges, le_mapi_importhierarchychanges);
  5841. if (resStream != NULL) {
  5842. ZEND_FETCH_RESOURCE_C(lpStream, IStream *, &resStream, -1, name_istream, le_istream);
  5843. }
  5844. MAPI_G(hr) = lpImportHierarchyChanges->UpdateState(lpStream);
  5845. if(MAPI_G(hr) != hrSuccess)
  5846. goto exit;
  5847. RETVAL_TRUE;
  5848. exit:
  5849. LOG_END();
  5850. THROW_ON_ERROR();
  5851. }
  5852. ZEND_FUNCTION(mapi_importhierarchychanges_importfolderchange)
  5853. {
  5854. PMEASURE_FUNC;
  5855. LOG_BEGIN();
  5856. zval * resImportHierarchyChanges = NULL;
  5857. zval * resProps = NULL;
  5858. IExchangeImportHierarchyChanges *lpImportHierarchyChanges = NULL;
  5859. memory_ptr<SPropValue> lpProps;
  5860. ULONG cValues = 0;
  5861. RETVAL_FALSE;
  5862. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5863. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra", &resImportHierarchyChanges, &resProps) == FAILURE) return;
  5864. ZEND_FETCH_RESOURCE_C(lpImportHierarchyChanges, IExchangeImportHierarchyChanges *, &resImportHierarchyChanges, -1, name_mapi_importhierarchychanges, le_mapi_importhierarchychanges);
  5865. MAPI_G(hr) = PHPArraytoPropValueArray(resProps, NULL, &cValues, &~lpProps TSRMLS_CC);
  5866. if(MAPI_G(hr) != hrSuccess) {
  5867. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to convert properties in properties array");
  5868. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5869. goto exit;
  5870. }
  5871. MAPI_G(hr) = lpImportHierarchyChanges->ImportFolderChange(cValues, lpProps);
  5872. if(MAPI_G(hr) != hrSuccess)
  5873. goto exit;
  5874. RETVAL_TRUE;
  5875. exit:
  5876. LOG_END();
  5877. THROW_ON_ERROR();
  5878. }
  5879. ZEND_FUNCTION(mapi_importhierarchychanges_importfolderdeletion)
  5880. {
  5881. PMEASURE_FUNC;
  5882. LOG_BEGIN();
  5883. zval * resImportHierarchyChanges = NULL;
  5884. zval * resFolders = NULL;
  5885. IExchangeImportHierarchyChanges *lpImportHierarchyChanges = NULL;
  5886. memory_ptr<SBinaryArray> lpFolders;
  5887. long ulFlags = 0;
  5888. RETVAL_FALSE;
  5889. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5890. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rla", &resImportHierarchyChanges, &ulFlags, &resFolders) == FAILURE) return;
  5891. ZEND_FETCH_RESOURCE_C(lpImportHierarchyChanges, IExchangeImportHierarchyChanges *, &resImportHierarchyChanges, -1, name_mapi_importhierarchychanges, le_mapi_importhierarchychanges);
  5892. MAPI_G(hr) = PHPArraytoSBinaryArray(resFolders, NULL, &~lpFolders TSRMLS_CC);
  5893. if(MAPI_G(hr) != hrSuccess) {
  5894. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to parse folder list");
  5895. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5896. goto exit;
  5897. }
  5898. MAPI_G(hr) = lpImportHierarchyChanges->ImportFolderDeletion(ulFlags, lpFolders);
  5899. if(MAPI_G(hr) != hrSuccess)
  5900. goto exit;
  5901. RETVAL_TRUE;
  5902. exit:
  5903. LOG_END();
  5904. THROW_ON_ERROR();
  5905. }
  5906. /*
  5907. * This function needs some explanation as it is not just a one-to-one MAPI function. This function
  5908. * accepts an object from PHP, and returns a resource. The resource is the MAPI equivalent of the passed
  5909. * object, which can then be passed to mapi_exportchanges_config(). This basically can be seen as a callback
  5910. * system whereby mapi_exportchanges_synchronize() calls back to PHP-space to give it data.
  5911. *
  5912. * The way we do this is to create a real IExchangeImportChanges class that calls back to its PHP equivalent
  5913. * in each method implementation. If the function cannot be found, we simply return an appropriate error.
  5914. *
  5915. * We also have to make sure that we do good refcounting here, as the user may wrap a PHP object, and then
  5916. * delete references to that object. We still hold an internal reference though, so we have to tell Zend
  5917. * that we still have a pointer to the object. We do this with the standard internal Zend refcounting system.
  5918. */
  5919. ZEND_FUNCTION(mapi_wrap_importcontentschanges)
  5920. {
  5921. PMEASURE_FUNC;
  5922. LOG_BEGIN();
  5923. zval * objImportContentsChanges = NULL;
  5924. ECImportContentsChangesProxy * lpImportContentsChanges = NULL;
  5925. RETVAL_FALSE;
  5926. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5927. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &objImportContentsChanges) == FAILURE) return;
  5928. lpImportContentsChanges = new ECImportContentsChangesProxy(objImportContentsChanges TSRMLS_CC);
  5929. // Simply return the wrapped object
  5930. UOBJ_REGISTER_RESOURCE(return_value, lpImportContentsChanges, le_mapi_importcontentschanges);
  5931. MAPI_G(hr) = hrSuccess;
  5932. LOG_END();
  5933. THROW_ON_ERROR();
  5934. }
  5935. // Same for IExchangeImportHierarchyChanges
  5936. ZEND_FUNCTION(mapi_wrap_importhierarchychanges)
  5937. {
  5938. PMEASURE_FUNC;
  5939. LOG_BEGIN();
  5940. zval * objImportHierarchyChanges = NULL;
  5941. ECImportHierarchyChangesProxy * lpImportHierarchyChanges = NULL;
  5942. RETVAL_FALSE;
  5943. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5944. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &objImportHierarchyChanges) == FAILURE) return;
  5945. lpImportHierarchyChanges = new ECImportHierarchyChangesProxy(objImportHierarchyChanges TSRMLS_CC);
  5946. // Simply return the wrapped object
  5947. UOBJ_REGISTER_RESOURCE(return_value, lpImportHierarchyChanges, le_mapi_importhierarchychanges);
  5948. MAPI_G(hr) = hrSuccess;
  5949. LOG_END();
  5950. THROW_ON_ERROR();
  5951. }
  5952. ZEND_FUNCTION(mapi_inetmapi_imtoinet)
  5953. {
  5954. PMEASURE_FUNC;
  5955. LOG_BEGIN();
  5956. zval *resSession;
  5957. zval *resAddrBook;
  5958. zval *resMessage;
  5959. zval *resOptions;
  5960. sending_options sopt;
  5961. object_ptr<ECMemStream> lpMemStream = NULL;
  5962. IStream *lpStream = NULL;
  5963. std::unique_ptr<char[]> lpBuffer;
  5964. imopt_default_sending_options(&sopt);
  5965. sopt.no_recipients_workaround = true;
  5966. IMAPISession *lpMAPISession = NULL;
  5967. IAddrBook *lpAddrBook = NULL;
  5968. IMessage *lpMessage = NULL;
  5969. RETVAL_FALSE;
  5970. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  5971. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrra", &resSession, &resAddrBook, &resMessage, &resOptions) == FAILURE) return;
  5972. ZEND_FETCH_RESOURCE_C(lpMAPISession, IMAPISession *, &resSession, -1, name_mapi_session, le_mapi_session);
  5973. ZEND_FETCH_RESOURCE_C(lpAddrBook, IAddrBook *, &resAddrBook, -1, name_mapi_addrbook, le_mapi_addrbook);
  5974. ZEND_FETCH_RESOURCE_C(lpMessage, IMessage *, &resMessage, -1, name_mapi_message, le_mapi_message);
  5975. MAPI_G(hr) = PHPArraytoSendingOptions(resOptions, &sopt);
  5976. if(MAPI_G(hr) != hrSuccess)
  5977. goto exit;
  5978. MAPI_G(hr) = IMToINet(lpMAPISession, lpAddrBook, lpMessage, &unique_tie(lpBuffer), sopt);
  5979. if(MAPI_G(hr) != hrSuccess)
  5980. goto exit;
  5981. MAPI_G(hr) = ECMemStream::Create(lpBuffer.get(), strlen(lpBuffer.get()), 0, nullptr, nullptr, nullptr, &~lpMemStream);
  5982. if(MAPI_G(hr) != hrSuccess)
  5983. goto exit;
  5984. MAPI_G(hr) = lpMemStream->QueryInterface(IID_IStream, (void **)&lpStream);
  5985. if(MAPI_G(hr) != hrSuccess)
  5986. goto exit;
  5987. ZEND_REGISTER_RESOURCE(return_value, lpStream, le_istream);
  5988. exit:
  5989. LOG_END();
  5990. THROW_ON_ERROR();
  5991. }
  5992. ZEND_FUNCTION(mapi_inetmapi_imtomapi)
  5993. {
  5994. PMEASURE_FUNC;
  5995. LOG_BEGIN();
  5996. zval *resSession;
  5997. zval *resStore;
  5998. zval *resAddrBook;
  5999. zval *resMessage;
  6000. zval *resOptions;
  6001. delivery_options dopt;
  6002. ULONG cbString = 0;
  6003. char *szString = NULL;
  6004. imopt_default_delivery_options(&dopt);
  6005. IMAPISession *lpMAPISession = NULL;
  6006. IAddrBook *lpAddrBook = NULL;
  6007. IMessage *lpMessage = NULL;
  6008. IMsgStore *lpMsgStore = NULL;
  6009. RETVAL_FALSE;
  6010. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  6011. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrrrsa", &resSession, &resStore, &resAddrBook, &resMessage, &szString, &cbString, &resOptions) == FAILURE) return;
  6012. ZEND_FETCH_RESOURCE_C(lpMAPISession, IMAPISession *, &resSession, -1, name_mapi_session, le_mapi_session);
  6013. ZEND_FETCH_RESOURCE_C(lpMsgStore, IMsgStore *, &resStore, -1, name_mapi_msgstore, le_mapi_msgstore);
  6014. ZEND_FETCH_RESOURCE_C(lpAddrBook, IAddrBook *, &resAddrBook, -1, name_mapi_addrbook, le_mapi_addrbook);
  6015. ZEND_FETCH_RESOURCE_C(lpMessage, IMessage *, &resMessage, -1, name_mapi_message, le_mapi_message);
  6016. std::string strInput(szString, cbString);
  6017. MAPI_G(hr) = PHPArraytoDeliveryOptions(resOptions, &dopt);
  6018. if(MAPI_G(hr) != hrSuccess)
  6019. goto exit;
  6020. MAPI_G(hr) = IMToMAPI(lpMAPISession, lpMsgStore, lpAddrBook, lpMessage, strInput, dopt);
  6021. if(MAPI_G(hr) != hrSuccess)
  6022. goto exit;
  6023. RETVAL_TRUE;
  6024. exit:
  6025. LOG_END();
  6026. THROW_ON_ERROR();
  6027. return;
  6028. }
  6029. ZEND_FUNCTION(mapi_icaltomapi)
  6030. {
  6031. zval *resSession;
  6032. zval *resStore;
  6033. zval *resAddrBook;
  6034. zval *resMessage;
  6035. zend_bool *noRecipients;
  6036. ULONG cbString = 0;
  6037. char *szString = nullptr;
  6038. IMAPISession *lpMAPISession = nullptr;
  6039. IAddrBook *lpAddrBook = nullptr;
  6040. IMessage *lpMessage = nullptr;
  6041. IMsgStore *lpMsgStore = nullptr;
  6042. std::unique_ptr<ICalToMapi> lpIcalToMapi;
  6043. RETVAL_FALSE;
  6044. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  6045. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrrrsb",
  6046. &resSession, &resStore, &resAddrBook, &resMessage, &szString,
  6047. &cbString, &noRecipients) == FAILURE)
  6048. return;
  6049. ZEND_FETCH_RESOURCE_C(lpMAPISession, IMAPISession *, &resSession, -1, name_mapi_session, le_mapi_session);
  6050. ZEND_FETCH_RESOURCE_C(lpMsgStore, IMsgStore *, &resStore, -1, name_mapi_msgstore, le_mapi_msgstore);
  6051. ZEND_FETCH_RESOURCE_C(lpAddrBook, IAddrBook *, &resAddrBook, -1, name_mapi_addrbook, le_mapi_addrbook);
  6052. ZEND_FETCH_RESOURCE_C(lpMessage, IMessage *, &resMessage, -1, name_mapi_message, le_mapi_message);
  6053. std::string icalMsg(szString, cbString);
  6054. // noRecpients, skip recipients from ical.
  6055. // Used for DAgent, which uses the mail recipients
  6056. CreateICalToMapi(lpMsgStore, lpAddrBook, noRecipients, &unique_tie(lpIcalToMapi));
  6057. if (lpIcalToMapi == nullptr) {
  6058. MAPI_G(hr) = MAPI_E_NOT_ENOUGH_MEMORY;
  6059. goto exit;
  6060. }
  6061. // Set the default timezone to UTC if none is set, replicating the
  6062. // behaviour of VMIMEToMAPI.
  6063. MAPI_G(hr) = lpIcalToMapi->ParseICal(icalMsg, "utf-8", "UTC", nullptr, 0);
  6064. if (MAPI_G(hr) != hrSuccess)
  6065. goto exit;
  6066. MAPI_G(hr) = lpIcalToMapi->GetItem(0, 0, lpMessage);
  6067. if (MAPI_G(hr) != hrSuccess)
  6068. goto exit;
  6069. exit:
  6070. RETVAL_TRUE;
  6071. LOG_END();
  6072. THROW_ON_ERROR();
  6073. return;
  6074. }
  6075. ZEND_FUNCTION(mapi_mapitoical)
  6076. {
  6077. PMEASURE_FUNC;
  6078. LOG_BEGIN();
  6079. zval *resSession;
  6080. zval *resAddrBook;
  6081. zval *resMessage;
  6082. zval *resOptions;
  6083. IMAPISession *lpMAPISession = nullptr;
  6084. IAddrBook *lpAddrBook = nullptr;
  6085. IMessage *lpMessage = nullptr;
  6086. MapiToICal *lpMtIcal = nullptr;
  6087. std::string strical("");
  6088. std::string method("");
  6089. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  6090. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrra",
  6091. &resSession, &resAddrBook, &resMessage, &resOptions) == FAILURE)
  6092. return;
  6093. ZEND_FETCH_RESOURCE_C(lpMAPISession, IMAPISession *, &resSession, -1, name_mapi_session, le_mapi_session);
  6094. ZEND_FETCH_RESOURCE_C(lpAddrBook, IAddrBook *, &resAddrBook, -1, name_mapi_addrbook, le_mapi_addrbook);
  6095. ZEND_FETCH_RESOURCE_C(lpMessage, IMessage *, &resMessage, -1, name_mapi_message, le_mapi_message);
  6096. // set HR
  6097. CreateMapiToICal(lpAddrBook, "utf-8", &lpMtIcal);
  6098. if (lpMtIcal == nullptr) {
  6099. MAPI_G(hr) = MAPI_E_NOT_ENOUGH_MEMORY;
  6100. goto exit;
  6101. }
  6102. MAPI_G(hr) = lpMtIcal->AddMessage(lpMessage, "", 0);
  6103. if (MAPI_G(hr) != hrSuccess)
  6104. goto exit;
  6105. MAPI_G(hr) = lpMtIcal->Finalize(0, &method, &strical);
  6106. exit:
  6107. delete lpMtIcal;
  6108. LOG_END();
  6109. THROW_ON_ERROR();
  6110. RETURN_STRING(strical.c_str(), sizeof(strical.c_str()));
  6111. }
  6112. ZEND_FUNCTION(mapi_vcftomapi)
  6113. {
  6114. zval *resSession;
  6115. zval *resStore;
  6116. zval *resMessage;
  6117. ULONG cbString = 0;
  6118. char *szString = nullptr;
  6119. IMAPISession *lpMAPISession = nullptr;
  6120. IMessage *lpMessage = nullptr;
  6121. IMsgStore *lpMsgStore = nullptr;
  6122. std::unique_ptr<vcftomapi> conv;
  6123. RETVAL_FALSE;
  6124. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  6125. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrrs",
  6126. &resSession, &resStore, &resMessage, &szString,
  6127. &cbString) == FAILURE)
  6128. return;
  6129. ZEND_FETCH_RESOURCE_C(lpMAPISession, IMAPISession *, &resSession, -1, name_mapi_session, le_mapi_session);
  6130. ZEND_FETCH_RESOURCE_C(lpMsgStore, IMsgStore *, &resStore, -1, name_mapi_msgstore, le_mapi_msgstore);
  6131. ZEND_FETCH_RESOURCE_C(lpMessage, IMessage *, &resMessage, -1, name_mapi_message, le_mapi_message);
  6132. std::string vcfMsg(szString, cbString);
  6133. create_vcftomapi(lpMsgStore, &unique_tie(conv));
  6134. if (conv == nullptr) {
  6135. MAPI_G(hr) = MAPI_E_NOT_ENOUGH_MEMORY;
  6136. goto exit;
  6137. }
  6138. MAPI_G(hr) = conv->parse_vcf(vcfMsg);
  6139. if (MAPI_G(hr) != hrSuccess)
  6140. goto exit;
  6141. MAPI_G(hr) = conv->get_item(lpMessage);
  6142. if (MAPI_G(hr) != hrSuccess)
  6143. goto exit;
  6144. exit:
  6145. RETVAL_TRUE;
  6146. LOG_END();
  6147. THROW_ON_ERROR();
  6148. return;
  6149. }
  6150. ZEND_FUNCTION(mapi_mapitovcf)
  6151. {
  6152. PMEASURE_FUNC;
  6153. LOG_BEGIN();
  6154. zval *resSession;
  6155. zval *resAddrBook;
  6156. zval *resMessage;
  6157. zval *resOptions;
  6158. IMAPISession *lpMAPISession = nullptr;
  6159. IMessage *lpMessage = nullptr;
  6160. std::unique_ptr<mapitovcf> conv;
  6161. std::string vcf;
  6162. MAPI_G(hr) = MAPI_E_INVALID_PARAMETER;
  6163. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrra",
  6164. &resSession, &resAddrBook, &resMessage, &resOptions) == FAILURE)
  6165. return;
  6166. ZEND_FETCH_RESOURCE_C(lpMAPISession, IMAPISession *, &resSession, -1, name_mapi_session, le_mapi_session);
  6167. ZEND_FETCH_RESOURCE_C(lpMessage, IMessage *, &resMessage, -1, name_mapi_message, le_mapi_message);
  6168. create_mapitovcf(&unique_tie(conv));
  6169. if (conv == nullptr) {
  6170. MAPI_G(hr) = MAPI_E_NOT_ENOUGH_MEMORY;
  6171. goto exit;
  6172. }
  6173. MAPI_G(hr) = conv->add_message(lpMessage);
  6174. if (MAPI_G(hr) != hrSuccess)
  6175. goto exit;
  6176. MAPI_G(hr) = conv->finalize(&vcf);
  6177. exit:
  6178. LOG_END();
  6179. THROW_ON_ERROR();
  6180. RETURN_STRING(vcf.c_str(), vcf.size());
  6181. }
  6182. ZEND_FUNCTION(mapi_enable_exceptions)
  6183. {
  6184. PMEASURE_FUNC;
  6185. LOG_BEGIN();
  6186. ULONG cbExClass = 0;
  6187. char * szExClass = NULL;
  6188. zend_class_entry **ce = NULL;
  6189. RETVAL_FALSE;
  6190. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &szExClass, &cbExClass) == FAILURE) return;
  6191. if (zend_hash_find(CG(class_table), szExClass, cbExClass+1, (void **) &ce) == SUCCESS) {
  6192. MAPI_G(exceptions_enabled) = true;
  6193. MAPI_G(exception_ce) = *ce;
  6194. RETVAL_TRUE;
  6195. }
  6196. LOG_END();
  6197. return;
  6198. }
  6199. // Can be queried by client applications to check whether certain API features are supported or not.
  6200. ZEND_FUNCTION(mapi_feature)
  6201. {
  6202. PMEASURE_FUNC;
  6203. LOG_BEGIN();
  6204. static const char *const features[] =
  6205. {"LOGONFLAGS", "NOTIFICATIONS", "INETMAPI_IMTOMAPI"};
  6206. const char *szFeature = NULL;
  6207. ULONG cbFeature = 0;
  6208. RETVAL_FALSE;
  6209. if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &szFeature, &cbFeature) == FAILURE) return;
  6210. for (size_t i = 0; i < ARRAY_SIZE(features); ++i)
  6211. if(strcasecmp(features[i], szFeature) == 0) {
  6212. RETVAL_TRUE;
  6213. break;
  6214. }
  6215. LOG_END();
  6216. return;
  6217. }