Skip to content

Commit

Permalink
php_mapi: allow calling namedprop resolution function with non-stores
Browse files Browse the repository at this point in the history
  • Loading branch information
fcneuf authored and jengelh committed Oct 6, 2024
1 parent 02fc2b1 commit d692f57
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 18 deletions.
28 changes: 22 additions & 6 deletions exch/zcore/zserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3888,10 +3888,18 @@ ec_error_t zs_getnamedpropids(GUID hsession, uint32_t hstore,
auto pinfo = zs_query_session(hsession);
if (pinfo == nullptr)
return ecError;
auto pstore = pinfo->ptree->get_object<store_object>(hstore, &mapi_type);
if (pstore == nullptr)
auto obj = pinfo->ptree->get_object<void>(hstore, &mapi_type);
if (obj == nullptr)
return ecNullObject;
if (mapi_type != zs_objtype::store)
store_object *pstore = nullptr;
switch (mapi_type) {
case zs_objtype::store: pstore = static_cast<store_object *>(obj); break;
case zs_objtype::folder: pstore = static_cast<folder_object *>(obj)->pstore; break;
case zs_objtype::message: pstore = static_cast<message_object *>(obj)->get_store(); break;
case zs_objtype::attach: pstore = static_cast<attachment_object *>(obj)->get_store(); break;
default: break;
}
if (pstore == nullptr)
return ecNotSupported;
return pstore->get_named_propids(TRUE, ppropnames, ppropids) ?
ecSuccess : ecError;
Expand All @@ -3904,10 +3912,18 @@ ec_error_t zs_getpropnames(GUID hsession, uint32_t hstore,
auto pinfo = zs_query_session(hsession);
if (pinfo == nullptr)
return ecError;
auto pstore = pinfo->ptree->get_object<store_object>(hstore, &mapi_type);
if (pstore == nullptr)
auto obj = pinfo->ptree->get_object<void>(hstore, &mapi_type);
if (obj == nullptr)
return ecNullObject;
if (mapi_type != zs_objtype::store)
store_object *pstore = nullptr;
switch (mapi_type) {
case zs_objtype::store: pstore = static_cast<store_object *>(obj); break;
case zs_objtype::folder: pstore = static_cast<folder_object *>(obj)->pstore; break;
case zs_objtype::message: pstore = static_cast<message_object *>(obj)->get_store(); break;
case zs_objtype::attach: pstore = static_cast<attachment_object *>(obj)->get_store(); break;
default: break;
}
if (pstore == nullptr)
return ecNotSupported;
return pstore->get_named_propnames(ppropids, ppropnames) ?
ecSuccess : ecError;
Expand Down
27 changes: 15 additions & 12 deletions php_mapi/mapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2282,22 +2282,23 @@ static ZEND_FUNCTION(mapi_getidsfromnames)
ZCL_MEMORY;
zval *pzstore, *pznames, *pzguids = nullptr;
PROPID_ARRAY propids;
MAPI_RESOURCE *pstore;
PROPNAME_ARRAY propnames;

if (zend_parse_parameters(ZEND_NUM_ARGS(),
"ra|a", &pzstore, &pznames, &pzguids) == FAILURE
|| NULL == pzstore || NULL == pznames)
pthrow(ecInvalidParam);
ZEND_FETCH_RESOURCE(pstore, pzstore, le_mapi_msgstore);
if (pstore->type != zs_objtype::store)
auto pstore = resolve_resource(pzstore, {le_mapi_msgstore,
le_mapi_folder, le_mapi_message, le_mapi_attachment});
if (pstore == &invalid_object)
pthrow(ecInvalidObject);
else if (pstore == nullptr)
pthrow(ecInvalidParam);
auto err = php_to_propname_array(pznames, pzguids, &propnames);
if (err != ecSuccess)
pthrow(err);
auto result = zclient_getnamedpropids(
pstore->hsession, pstore->hobject,
&propnames, &propids);
auto result = zclient_getnamedpropids(pstore->hsession,
pstore->hobject, &propnames, &propids);
if (result != ecSuccess)
pthrow(result);
zarray_init(return_value);
Expand Down Expand Up @@ -2624,17 +2625,19 @@ static ZEND_FUNCTION(mapi_getnamesfromids)
zval *pzarray, *pzresource;
char num_buff[20];
PROPID_ARRAY propids;
MAPI_RESOURCE *pstore;
PROPTAG_ARRAY proptags;
PROPNAME_ARRAY propnames;

if (zend_parse_parameters(ZEND_NUM_ARGS(),
"ra", &pzresource, &pzarray) == FAILURE || NULL
== pzresource || NULL == pzarray)
pthrow(ecInvalidParam);
ZEND_FETCH_RESOURCE(pstore, pzresource, le_mapi_msgstore);
if (pstore->type != zs_objtype::store)
pthrow(ecInvalidObject);
auto probject = resolve_resource(pzresource, {le_mapi_msgstore,
le_mapi_folder, le_mapi_message, le_mapi_attachment});
if (probject == &invalid_object)
pthrow(ecInvalidObject);
else if (probject == nullptr)
pthrow(ecInvalidParam);
auto err = php_to_proptag_array(pzarray, &proptags);
if (err != ecSuccess)
pthrow(err);
Expand All @@ -2645,8 +2648,8 @@ static ZEND_FUNCTION(mapi_getnamesfromids)
}
for (unsigned int i = 0; i < proptags.count; ++i)
propids[i] = PROP_ID(proptags.pproptag[i]);
auto result = zclient_getpropnames(pstore->hsession, pstore->hobject,
propids, &propnames);
auto result = zclient_getpropnames(probject->hsession,
probject->hobject, propids, &propnames);
if (result != ecSuccess)
pthrow(result);
zarray_init(return_value);
Expand Down

0 comments on commit d692f57

Please sign in to comment.