Skip to content

Commit d692f57

Browse files
fcneufjengelh
authored andcommitted
php_mapi: allow calling namedprop resolution function with non-stores
1 parent 02fc2b1 commit d692f57

File tree

2 files changed

+37
-18
lines changed

2 files changed

+37
-18
lines changed

exch/zcore/zserver.cpp

+22-6
Original file line numberDiff line numberDiff line change
@@ -3888,10 +3888,18 @@ ec_error_t zs_getnamedpropids(GUID hsession, uint32_t hstore,
38883888
auto pinfo = zs_query_session(hsession);
38893889
if (pinfo == nullptr)
38903890
return ecError;
3891-
auto pstore = pinfo->ptree->get_object<store_object>(hstore, &mapi_type);
3892-
if (pstore == nullptr)
3891+
auto obj = pinfo->ptree->get_object<void>(hstore, &mapi_type);
3892+
if (obj == nullptr)
38933893
return ecNullObject;
3894-
if (mapi_type != zs_objtype::store)
3894+
store_object *pstore = nullptr;
3895+
switch (mapi_type) {
3896+
case zs_objtype::store: pstore = static_cast<store_object *>(obj); break;
3897+
case zs_objtype::folder: pstore = static_cast<folder_object *>(obj)->pstore; break;
3898+
case zs_objtype::message: pstore = static_cast<message_object *>(obj)->get_store(); break;
3899+
case zs_objtype::attach: pstore = static_cast<attachment_object *>(obj)->get_store(); break;
3900+
default: break;
3901+
}
3902+
if (pstore == nullptr)
38953903
return ecNotSupported;
38963904
return pstore->get_named_propids(TRUE, ppropnames, ppropids) ?
38973905
ecSuccess : ecError;
@@ -3904,10 +3912,18 @@ ec_error_t zs_getpropnames(GUID hsession, uint32_t hstore,
39043912
auto pinfo = zs_query_session(hsession);
39053913
if (pinfo == nullptr)
39063914
return ecError;
3907-
auto pstore = pinfo->ptree->get_object<store_object>(hstore, &mapi_type);
3908-
if (pstore == nullptr)
3915+
auto obj = pinfo->ptree->get_object<void>(hstore, &mapi_type);
3916+
if (obj == nullptr)
39093917
return ecNullObject;
3910-
if (mapi_type != zs_objtype::store)
3918+
store_object *pstore = nullptr;
3919+
switch (mapi_type) {
3920+
case zs_objtype::store: pstore = static_cast<store_object *>(obj); break;
3921+
case zs_objtype::folder: pstore = static_cast<folder_object *>(obj)->pstore; break;
3922+
case zs_objtype::message: pstore = static_cast<message_object *>(obj)->get_store(); break;
3923+
case zs_objtype::attach: pstore = static_cast<attachment_object *>(obj)->get_store(); break;
3924+
default: break;
3925+
}
3926+
if (pstore == nullptr)
39113927
return ecNotSupported;
39123928
return pstore->get_named_propnames(ppropids, ppropnames) ?
39133929
ecSuccess : ecError;

php_mapi/mapi.cpp

+15-12
Original file line numberDiff line numberDiff line change
@@ -2282,22 +2282,23 @@ static ZEND_FUNCTION(mapi_getidsfromnames)
22822282
ZCL_MEMORY;
22832283
zval *pzstore, *pznames, *pzguids = nullptr;
22842284
PROPID_ARRAY propids;
2285-
MAPI_RESOURCE *pstore;
22862285
PROPNAME_ARRAY propnames;
22872286

22882287
if (zend_parse_parameters(ZEND_NUM_ARGS(),
22892288
"ra|a", &pzstore, &pznames, &pzguids) == FAILURE
22902289
|| NULL == pzstore || NULL == pznames)
22912290
pthrow(ecInvalidParam);
2292-
ZEND_FETCH_RESOURCE(pstore, pzstore, le_mapi_msgstore);
2293-
if (pstore->type != zs_objtype::store)
2291+
auto pstore = resolve_resource(pzstore, {le_mapi_msgstore,
2292+
le_mapi_folder, le_mapi_message, le_mapi_attachment});
2293+
if (pstore == &invalid_object)
22942294
pthrow(ecInvalidObject);
2295+
else if (pstore == nullptr)
2296+
pthrow(ecInvalidParam);
22952297
auto err = php_to_propname_array(pznames, pzguids, &propnames);
22962298
if (err != ecSuccess)
22972299
pthrow(err);
2298-
auto result = zclient_getnamedpropids(
2299-
pstore->hsession, pstore->hobject,
2300-
&propnames, &propids);
2300+
auto result = zclient_getnamedpropids(pstore->hsession,
2301+
pstore->hobject, &propnames, &propids);
23012302
if (result != ecSuccess)
23022303
pthrow(result);
23032304
zarray_init(return_value);
@@ -2624,17 +2625,19 @@ static ZEND_FUNCTION(mapi_getnamesfromids)
26242625
zval *pzarray, *pzresource;
26252626
char num_buff[20];
26262627
PROPID_ARRAY propids;
2627-
MAPI_RESOURCE *pstore;
26282628
PROPTAG_ARRAY proptags;
26292629
PROPNAME_ARRAY propnames;
26302630

26312631
if (zend_parse_parameters(ZEND_NUM_ARGS(),
26322632
"ra", &pzresource, &pzarray) == FAILURE || NULL
26332633
== pzresource || NULL == pzarray)
26342634
pthrow(ecInvalidParam);
2635-
ZEND_FETCH_RESOURCE(pstore, pzresource, le_mapi_msgstore);
2636-
if (pstore->type != zs_objtype::store)
2637-
pthrow(ecInvalidObject);
2635+
auto probject = resolve_resource(pzresource, {le_mapi_msgstore,
2636+
le_mapi_folder, le_mapi_message, le_mapi_attachment});
2637+
if (probject == &invalid_object)
2638+
pthrow(ecInvalidObject);
2639+
else if (probject == nullptr)
2640+
pthrow(ecInvalidParam);
26382641
auto err = php_to_proptag_array(pzarray, &proptags);
26392642
if (err != ecSuccess)
26402643
pthrow(err);
@@ -2645,8 +2648,8 @@ static ZEND_FUNCTION(mapi_getnamesfromids)
26452648
}
26462649
for (unsigned int i = 0; i < proptags.count; ++i)
26472650
propids[i] = PROP_ID(proptags.pproptag[i]);
2648-
auto result = zclient_getpropnames(pstore->hsession, pstore->hobject,
2649-
propids, &propnames);
2651+
auto result = zclient_getpropnames(probject->hsession,
2652+
probject->hobject, propids, &propnames);
26502653
if (result != ecSuccess)
26512654
pthrow(result);
26522655
zarray_init(return_value);

0 commit comments

Comments
 (0)