Skip to content

Commit 036f5ae

Browse files
committed
lib: automatic (de)allocation for ONEOFF_ENTRYID
1 parent 0ffa01e commit 036f5ae

File tree

9 files changed

+43
-39
lines changed

9 files changed

+43
-39
lines changed

exch/zcore/objects.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,10 @@ struct user_object {
222222

223223
struct oneoff_object {
224224
protected:
225-
oneoff_object(const ONEOFF_ENTRYID &);
225+
oneoff_object(ONEOFF_ENTRYID &&);
226226

227227
public:
228-
static std::unique_ptr<oneoff_object> create(const ONEOFF_ENTRYID &);
228+
static std::unique_ptr<oneoff_object> create(ONEOFF_ENTRYID &&);
229229
ec_error_t get_props(const PROPTAG_ARRAY *, TPROPVAL_ARRAY *);
230230

231231
static const uint32_t all_tags_raw[];

exch/zcore/user_object.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
using namespace gromox;
1919

20-
std::unique_ptr<oneoff_object> oneoff_object::create(const ONEOFF_ENTRYID &e) try
20+
std::unique_ptr<oneoff_object> oneoff_object::create(ONEOFF_ENTRYID &&e) try
2121
{
22-
return std::unique_ptr<oneoff_object>(new oneoff_object(e));
22+
return std::unique_ptr<oneoff_object>(new oneoff_object(std::move(e)));
2323
} catch (const std::bad_alloc &) {
2424
return nullptr;
2525
}
@@ -32,9 +32,9 @@ const uint32_t oneoff_object::all_tags_raw[] = {
3232
const PROPTAG_ARRAY oneoff_object::all_tags =
3333
{std::size(all_tags_raw), deconst(all_tags_raw)};
3434

35-
oneoff_object::oneoff_object(const ONEOFF_ENTRYID &e) :
36-
m_flags(e.ctrl_flags), m_dispname(znul(e.pdisplay_name)),
37-
m_addrtype(znul(e.paddress_type)), m_emaddr(znul(e.pmail_address))
35+
oneoff_object::oneoff_object(ONEOFF_ENTRYID &&e) :
36+
m_flags(e.ctrl_flags), m_dispname(std::move(e.pdisplay_name)),
37+
m_addrtype(std::move(e.paddress_type)), m_emaddr(std::move(e.pmail_address))
3838
{}
3939

4040
ec_error_t oneoff_object::get_props(const PROPTAG_ARRAY *tags, TPROPVAL_ARRAY *vals)

exch/zcore/zserver.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ static ec_error_t zs_openab_oop(USER_INFO_REF &&info, BINARY bin,
10051005
ep.init(bin.pv, bin.cb, common_util_alloc, EXT_FLAG_WCOUNT | EXT_FLAG_UTF16);
10061006
if (ep.g_oneoff_eid(&eid) != pack_result::ok)
10071007
return ecInvalidParam;
1008-
auto u = oneoff_object::create(eid);
1008+
auto u = oneoff_object::create(std::move(eid));
10091009
if (u == nullptr)
10101010
return ecServerOOM;
10111011
*zmg_type = zs_objtype::oneoff;
@@ -3006,7 +3006,6 @@ ec_error_t zs_modifyrecipients(GUID hsession,
30063006
TPROPVAL_ARRAY *prcpt;
30073007
FLATUID provider_uid;
30083008
TAGGED_PROPVAL *ppropval;
3009-
ONEOFF_ENTRYID oneoff_entry;
30103009

30113010
if (prcpt_list->count >= 0x7fef || (flags != MODRECIP_ADD &&
30123011
flags != MODRECIP_MODIFY && flags != MODRECIP_REMOVE))
@@ -3080,6 +3079,8 @@ ec_error_t zs_modifyrecipients(GUID hsession,
30803079
continue;
30813080
if (provider_uid == muidEMSAB) {
30823081
EMSAB_ENTRYID ab_entryid;
3082+
EXT_PULL ext_pull;
3083+
30833084
ext_pull.init(pbin->pb, pbin->cb, common_util_alloc, EXT_FLAG_UTF16);
30843085
if (ext_pull.g_abk_eid(&ab_entryid) != pack_result::ok ||
30853086
ab_entryid.type != DT_MAILUSER)
@@ -3114,9 +3115,12 @@ ec_error_t zs_modifyrecipients(GUID hsession,
31143115
return ecServerOOM;
31153116
cu_set_propval(prcpt, PR_DISPLAY_NAME, dupval);
31163117
} else if (provider_uid == muidOOP) {
3118+
ONEOFF_ENTRYID oneoff_entry;
3119+
EXT_PULL ext_pull;
3120+
31173121
ext_pull.init(pbin->pb, pbin->cb, common_util_alloc, EXT_FLAG_UTF16);
31183122
if (ext_pull.g_oneoff_eid(&oneoff_entry) != pack_result::ok ||
3119-
strcasecmp(oneoff_entry.paddress_type, "SMTP") != 0)
3123+
strcasecmp(oneoff_entry.paddress_type.c_str(), "SMTP") != 0)
31203124
continue;
31213125
ppropval = cu_alloc<TAGGED_PROPVAL>(prcpt->count + 5);
31223126
if (ppropval == nullptr)

include/gromox/ext_buffer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ struct GX_EXPORT EXT_PUSH {
311311
pack_result p_permission_data(const PERMISSION_DATA &);
312312
pack_result p_rule_data(const RULE_DATA &);
313313
pack_result p_abk_eid(const EMSAB_ENTRYID_view &);
314-
pack_result p_oneoff_eid(const ONEOFF_ENTRYID &);
314+
pack_result p_oneoff_eid(const ONEOFF_ENTRYID_view &);
315315
pack_result p_persistdata_a(std::span<const PERSISTDATA>);
316316
pack_result p_eid_a(const EID_ARRAY &);
317317
pack_result p_systime(const SYSTEMTIME &);

include/gromox/mapidefs.h

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,13 +1040,22 @@ struct GX_EXPORT NOTIF_SINK {
10401040
ADVISE_INFO *padvise;
10411041
};
10421042

1043+
struct GX_EXPORT ONEOFF_ENTRYID_view {
1044+
uint32_t flags = 0;
1045+
uint16_t version = 0;
1046+
uint16_t ctrl_flags = 0;
1047+
const char *pdisplay_name, *paddress_type, *pmail_address;
1048+
};
1049+
10431050
struct GX_EXPORT ONEOFF_ENTRYID {
1044-
uint32_t flags;
1045-
uint16_t version; /* should be 0x0000 */
1046-
uint16_t ctrl_flags;
1047-
char *pdisplay_name;
1048-
char *paddress_type;
1049-
char *pmail_address;
1051+
uint32_t flags = 0;
1052+
uint16_t version = 0; /* should be 0x0000 */
1053+
uint16_t ctrl_flags = 0;
1054+
std::string pdisplay_name, paddress_type, pmail_address;
1055+
operator ONEOFF_ENTRYID_view() const {
1056+
return {flags, version, ctrl_flags, pdisplay_name.c_str(),
1057+
paddress_type.c_str(), pmail_address.c_str()};
1058+
}
10501059
};
10511060

10521061
struct GX_EXPORT PERMISSION_ROW {

lib/mapi/ext_buffer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3267,7 +3267,7 @@ pack_result EXT_PUSH::p_abk_eid(const EMSAB_ENTRYID_view &r)
32673267
return p_str(r.px500dn);
32683268
}
32693269

3270-
pack_result EXT_PUSH::p_oneoff_eid(const ONEOFF_ENTRYID &r)
3270+
pack_result EXT_PUSH::p_oneoff_eid(const ONEOFF_ENTRYID_view &r)
32713271
{
32723272
TRY(p_uint32(r.flags));
32733273
TRY(p_guid(muidOOP));
@@ -3601,11 +3601,11 @@ bool oneoff_to_parts(EXT_PULL &ser, char *type, size_t tsize,
36013601
{
36023602
ONEOFF_ENTRYID eid;
36033603
if (ser.g_oneoff_eid(&eid) != pack_result::ok ||
3604-
strcasecmp(eid.paddress_type, "SMTP") != 0)
3604+
strcasecmp(eid.paddress_type.c_str(), "SMTP") != 0)
36053605
return false;
36063606
if (type != nullptr)
36073607
gx_strlcpy(type, "SMTP", tsize);
3608-
gx_strlcpy(addr, eid.pmail_address, asize);
3608+
gx_strlcpy(addr, eid.pmail_address.c_str(), asize);
36093609
return true;
36103610
}
36113611

lib/mapi/oxcmail.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2947,23 +2947,18 @@ static bool oxcmail_export_reply_to(const MESSAGE_CONTENT *pmsg,
29472947
for (size_t i = 0; i < address_array.count; ++i) {
29482948
EXT_PULL ep2;
29492949
ONEOFF_ENTRYID oo{};
2950-
auto cl_1 = HX::make_scope_exit([&]() {
2951-
free(oo.pdisplay_name);
2952-
free(oo.paddress_type);
2953-
free(oo.pmail_address);
2954-
});
29552950
ep2.init(address_array.pbin[i].pb, address_array.pbin[i].cb,
29562951
malloc, EXT_FLAG_UTF16);
29572952
if (ep2.g_oneoff_eid(&oo) != pack_result::ok ||
2958-
strcasecmp(oo.paddress_type, "SMTP") != 0) {
2953+
strcasecmp(oo.paddress_type.c_str(), "SMTP") != 0) {
29592954
mlog(LV_WARN, "W-1964: skipping non-SMTP reply-to entry");
29602955
continue;
29612956
}
29622957
auto mb = vmime::make_shared<vmime::mailbox>("");
2963-
if (oo.pdisplay_name != nullptr && *oo.pdisplay_name != '\0')
2964-
mb->setName(vmime::text(oo.pdisplay_name, vmime::charsets::UTF_8));
2965-
if (*oo.pmail_address != '\0')
2966-
mb->setEmail(oo.pmail_address);
2958+
if (!oo.pdisplay_name.empty())
2959+
mb->setName(vmime::text(std::move(oo.pdisplay_name), vmime::charsets::UTF_8));
2960+
if (!oo.pmail_address.empty())
2961+
mb->setEmail(std::move(oo.pmail_address));
29672962
adrlist.appendAddress(mb);
29682963
}
29692964
return true;

lib/mapi/usercvt.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,10 @@ static ec_error_t cvt_oneoff_to_smtpaddr(EXT_PULL &ser, const char *org,
121121
cvt_id2user id2user, std::string &smtpaddr)
122122
{
123123
ONEOFF_ENTRYID eid{};
124-
auto cl_0 = HX::make_scope_exit([&]() {
125-
free(eid.pdisplay_name);
126-
free(eid.paddress_type);
127-
free(eid.pmail_address);
128-
});
129124
if (ser.g_oneoff_eid(&eid) != pack_result::success)
130125
return ecInvalidParam;
131-
return cvt_genaddr_to_smtpaddr(eid.paddress_type, eid.pmail_address,
126+
return cvt_genaddr_to_smtpaddr(eid.paddress_type.c_str(),
127+
eid.pmail_address.c_str(),
132128
org, std::move(id2user), smtpaddr);
133129
}
134130

php_mapi/mapi.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -653,9 +653,9 @@ static ZEND_FUNCTION(mapi_parseoneoff)
653653
if (pull_ctx.g_oneoff_eid(&oneoff_entry) != pack_result::ok)
654654
pthrow(ecError);
655655
zarray_init(return_value);
656-
add_assoc_string(return_value, "name", oneoff_entry.pdisplay_name);
657-
add_assoc_string(return_value, "type", oneoff_entry.paddress_type);
658-
add_assoc_string(return_value, "address", oneoff_entry.pmail_address);
656+
add_assoc_string(return_value, "name", oneoff_entry.pdisplay_name.c_str());
657+
add_assoc_string(return_value, "type", oneoff_entry.paddress_type.c_str());
658+
add_assoc_string(return_value, "address", oneoff_entry.pmail_address.c_str());
659659
MAPI_G(hr) = ecSuccess;
660660
}
661661

0 commit comments

Comments
 (0)