Skip to content

Commit 6531bd1

Browse files
committed
zcore: simplify struct ZNOTIFICATION
Do away with the indirection and just slap it all in one struct.
1 parent e0edebb commit 6531bd1

File tree

5 files changed

+40
-102
lines changed

5 files changed

+40
-102
lines changed

exch/zcore/rpc_ext.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -296,17 +296,18 @@ static pack_result rpc_ext_push_state_array(EXT_PUSH &x, const STATE_ARRAY &r)
296296
return pack_result::ok;
297297
}
298298

299-
static pack_result rpc_ext_push_newmail_znotification(EXT_PUSH &x, const NEWMAIL_ZNOTIFICATION &r)
299+
static pack_result rpc_ext_push_newmail_znotification(EXT_PUSH &x, const ZNOTIFICATION &r)
300300
{
301-
QRF(x.p_bin(r.entryid));
302-
QRF(x.p_bin(r.parentid));
301+
std::string empty;
302+
QRF(x.p_bin(r.pentryid.has_value() ? *r.pentryid : empty));
303+
QRF(x.p_bin(r.pparentid.has_value() ? *r.pparentid : empty));
303304
QRF(x.p_uint32(r.flags));
304305
QRF(x.p_str(r.message_class));
305306
QRF(x.p_uint32(r.message_flags));
306307
return pack_result::ok;
307308
}
308309

309-
static pack_result rpc_ext_push_object_znotification(EXT_PUSH &x, const OBJECT_ZNOTIFICATION &r)
310+
static pack_result rpc_ext_push_object_znotification(EXT_PUSH &x, const ZNOTIFICATION &r)
310311
{
311312
QRF(x.p_uint32(static_cast<uint32_t>(r.object_type)));
312313
if (!r.pentryid.has_value()) {
@@ -347,16 +348,14 @@ static pack_result rpc_ext_push_znotification(EXT_PUSH &x, const ZNOTIFICATION &
347348
QRF(x.p_uint32(r.event_type));
348349
switch (r.event_type) {
349350
case fnevNewMail:
350-
return rpc_ext_push_newmail_znotification(x,
351-
*static_cast<const NEWMAIL_ZNOTIFICATION *>(r.pnotification_data));
351+
return rpc_ext_push_newmail_znotification(x, r);
352352
case fnevObjectCreated:
353353
case fnevObjectDeleted:
354354
case fnevObjectModified:
355355
case fnevObjectMoved:
356356
case fnevObjectCopied:
357357
case fnevSearchComplete:
358-
return rpc_ext_push_object_znotification(x,
359-
*static_cast<const OBJECT_ZNOTIFICATION *>(r.pnotification_data));
358+
return rpc_ext_push_object_znotification(x, r);
360359
default:
361360
return pack_result::ok;
362361
}

exch/zcore/zserver.cpp

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -294,20 +294,18 @@ void zs_notification_proc(const char *dir, BOOL b_table, uint32_t notify_id,
294294
strcmp(dir, pstore->get_dir()) != 0)
295295
return;
296296

297-
ZNOTIFICATION zn, *pnotification = &zn;
297+
ZNOTIFICATION zn, *pnotification = &zn, *pnew_mail = &zn, *oz = &zn;
298298
switch (pdb_notify->type) {
299299
case db_notify_type::new_mail: {
300300
pnotification->event_type = fnevNewMail;
301-
auto pnew_mail = new NEWMAIL_ZNOTIFICATION;
302-
pnotification->pnotification_data = pnew_mail;
303301
auto nt = static_cast<const DB_NOTIFY_NEW_MAIL *>(pdb_notify->pdata);
304302
folder_id = rop_util_nfid_to_eid(nt->folder_id);
305303
message_id = rop_util_make_eid_ex(1, nt->message_id);
306-
pnew_mail->entryid = cu_mid_to_entryid_s(*pstore, folder_id, message_id);
307-
if (pnew_mail->entryid.empty())
304+
pnew_mail->pentryid = cu_mid_to_entryid_s(*pstore, folder_id, message_id);
305+
if (pnew_mail->pentryid->empty())
308306
return;
309-
pnew_mail->parentid = cu_fid_to_entryid_s(*pstore, folder_id);
310-
if (pnew_mail->parentid.empty())
307+
pnew_mail->pparentid = cu_fid_to_entryid_s(*pstore, folder_id);
308+
if (pnew_mail->pparentid->empty())
311309
return;
312310
static constexpr proptag_t proptag_buff[] = {PR_MESSAGE_CLASS, PR_MESSAGE_FLAGS};
313311
static constexpr PROPTAG_ARRAY proptags = {std::size(proptag_buff), deconst(proptag_buff)};
@@ -326,8 +324,6 @@ void zs_notification_proc(const char *dir, BOOL b_table, uint32_t notify_id,
326324
}
327325
case db_notify_type::folder_created: {
328326
pnotification->event_type = fnevObjectCreated;
329-
auto oz = new OBJECT_ZNOTIFICATION;
330-
pnotification->pnotification_data = oz;
331327
auto nt = static_cast<const DB_NOTIFY_FOLDER_CREATED *>(pdb_notify->pdata);
332328
folder_id = rop_util_nfid_to_eid(nt->folder_id);
333329
parent_id = rop_util_nfid_to_eid(nt->parent_id);
@@ -342,8 +338,6 @@ void zs_notification_proc(const char *dir, BOOL b_table, uint32_t notify_id,
342338
}
343339
case db_notify_type::message_created: {
344340
pnotification->event_type = fnevObjectCreated;
345-
auto oz = new OBJECT_ZNOTIFICATION;
346-
pnotification->pnotification_data = oz;
347341
auto nt = static_cast<const DB_NOTIFY_MESSAGE_CREATED *>(pdb_notify->pdata);
348342
folder_id = rop_util_nfid_to_eid(nt->folder_id);
349343
message_id = rop_util_make_eid_ex(1, nt->message_id);
@@ -358,8 +352,6 @@ void zs_notification_proc(const char *dir, BOOL b_table, uint32_t notify_id,
358352
}
359353
case db_notify_type::folder_deleted: {
360354
pnotification->event_type = fnevObjectDeleted;
361-
auto oz = new OBJECT_ZNOTIFICATION;
362-
pnotification->pnotification_data = oz;
363355
auto nt = static_cast<const DB_NOTIFY_FOLDER_DELETED *>(pdb_notify->pdata);
364356
folder_id = rop_util_nfid_to_eid(nt->folder_id);
365357
parent_id = rop_util_nfid_to_eid(nt->parent_id);
@@ -374,8 +366,6 @@ void zs_notification_proc(const char *dir, BOOL b_table, uint32_t notify_id,
374366
}
375367
case db_notify_type::message_deleted: {
376368
pnotification->event_type = fnevObjectDeleted;
377-
auto oz = new OBJECT_ZNOTIFICATION;
378-
pnotification->pnotification_data = oz;
379369
auto nt = static_cast<const DB_NOTIFY_MESSAGE_DELETED *>(pdb_notify->pdata);
380370
folder_id = rop_util_nfid_to_eid(nt->folder_id);
381371
message_id = rop_util_make_eid_ex(1, nt->message_id);
@@ -390,8 +380,6 @@ void zs_notification_proc(const char *dir, BOOL b_table, uint32_t notify_id,
390380
}
391381
case db_notify_type::folder_modified: {
392382
pnotification->event_type = fnevObjectModified;
393-
auto oz = new OBJECT_ZNOTIFICATION;
394-
pnotification->pnotification_data = oz;
395383
auto nt = static_cast<const DB_NOTIFY_FOLDER_MODIFIED *>(pdb_notify->pdata);
396384
folder_id = rop_util_nfid_to_eid(nt->folder_id);
397385
oz->object_type = MAPI_FOLDER;
@@ -402,8 +390,6 @@ void zs_notification_proc(const char *dir, BOOL b_table, uint32_t notify_id,
402390
}
403391
case db_notify_type::message_modified: {
404392
pnotification->event_type = fnevObjectModified;
405-
auto oz = new OBJECT_ZNOTIFICATION;
406-
pnotification->pnotification_data = oz;
407393
auto nt = static_cast<const DB_NOTIFY_MESSAGE_MODIFIED *>(pdb_notify->pdata);
408394
folder_id = rop_util_nfid_to_eid(nt->folder_id);
409395
message_id = rop_util_make_eid_ex(1, nt->message_id);
@@ -420,8 +406,6 @@ void zs_notification_proc(const char *dir, BOOL b_table, uint32_t notify_id,
420406
case db_notify_type::folder_copied: {
421407
pnotification->event_type = pdb_notify->type == db_notify_type::folder_moved ?
422408
fnevObjectMoved : fnevObjectCopied;
423-
auto oz = new OBJECT_ZNOTIFICATION;
424-
pnotification->pnotification_data = oz;
425409
auto nt = static_cast<const DB_NOTIFY_FOLDER_MVCP *>(pdb_notify->pdata);
426410
folder_id = rop_util_nfid_to_eid(nt->folder_id);
427411
parent_id = rop_util_nfid_to_eid(nt->parent_id);
@@ -446,8 +430,6 @@ void zs_notification_proc(const char *dir, BOOL b_table, uint32_t notify_id,
446430
case db_notify_type::message_copied: {
447431
pnotification->event_type = pdb_notify->type == db_notify_type::message_moved ?
448432
fnevObjectMoved : fnevObjectCopied;
449-
auto oz = new OBJECT_ZNOTIFICATION;
450-
pnotification->pnotification_data = oz;
451433
auto nt = static_cast<const DB_NOTIFY_MESSAGE_MVCP *>(pdb_notify->pdata);
452434
old_parentid = rop_util_nfid_to_eid(nt->old_folder_id);
453435
old_eid = rop_util_make_eid_ex(1, nt->old_message_id);
@@ -470,8 +452,6 @@ void zs_notification_proc(const char *dir, BOOL b_table, uint32_t notify_id,
470452
}
471453
case db_notify_type::search_completed: {
472454
pnotification->event_type = fnevSearchComplete;
473-
auto oz = new OBJECT_ZNOTIFICATION;
474-
pnotification->pnotification_data = oz;
475455
auto nt = static_cast<const DB_NOTIFY_SEARCH_COMPLETED *>(pdb_notify->pdata);
476456
folder_id = rop_util_nfid_to_eid(nt->folder_id);
477457
oz->object_type = MAPI_FOLDER;

include/gromox/zcore_types.hpp

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -13,48 +13,16 @@ enum class zs_objtype : uint8_t {
1313
icsupctx, oneoff, invalid = 255,
1414
};
1515

16-
struct GX_EXPORT NEWMAIL_ZNOTIFICATION {
17-
std::string entryid, parentid, message_class;
18-
uint32_t flags = 0; /* unicode or not */
19-
uint32_t message_flags = 0;
20-
};
21-
22-
struct GX_EXPORT OBJECT_ZNOTIFICATION {
23-
mapi_object_type object_type;
16+
struct GX_EXPORT ZNOTIFICATION {
17+
uint32_t event_type = 0;
18+
mapi_object_type object_type{};
2419
std::optional<std::string> pentryid, pparentid, pold_entryid, pold_parentid;
2520
std::optional<std::vector<gromox::proptag_t>> pproptags;
26-
};
2721

28-
struct GX_EXPORT ZNOTIFICATION {
29-
ZNOTIFICATION() = default;
30-
ZNOTIFICATION(ZNOTIFICATION &&o) :
31-
event_type(o.event_type), pnotification_data(std::move(o.pnotification_data))
32-
{
33-
o.pnotification_data = nullptr;
34-
}
35-
36-
~ZNOTIFICATION() { clear(); }
37-
38-
ZNOTIFICATION &operator=(ZNOTIFICATION &&o)
39-
{
40-
clear();
41-
event_type = o.event_type;
42-
pnotification_data = std::move(o.pnotification_data);
43-
o.pnotification_data = nullptr;
44-
return *this;
45-
}
46-
47-
void clear()
48-
{
49-
if (event_type == fnevNewMail)
50-
delete static_cast<NEWMAIL_ZNOTIFICATION *>(pnotification_data);
51-
else
52-
delete static_cast<OBJECT_ZNOTIFICATION *>(pnotification_data);
53-
pnotification_data = nullptr;
54-
}
55-
56-
uint32_t event_type = 0;
57-
void *pnotification_data = nullptr; /* NEWMAIL_ZNOTIFICATION or OBJECT_ZNOTIFICATION */
22+
/* if event_type == fnevNewMail, these are used too: */
23+
std::string message_class;
24+
uint32_t flags = 0; /* unicode or not */
25+
uint32_t message_flags = 0;
5826
};
5927

6028
using ZNOTIFICATION_ARRAY = std::vector<ZNOTIFICATION>;

php_mapi/ext_pack.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,22 @@ pack_result PULL_CTX::g_state_a(STATE_ARRAY *r)
121121
}
122122

123123
static pack_result ext_pack_pull_newmail_znotification(PULL_CTX *pctx,
124-
NEWMAIL_ZNOTIFICATION *r)
124+
ZNOTIFICATION *r) try
125125
{
126-
TRY(pctx->g_bin(&r->entryid));
127-
TRY(pctx->g_bin(&r->parentid));
126+
std::string s;
127+
TRY(pctx->g_bin(&s));
128+
r->pentryid = std::move(s);
129+
TRY(pctx->g_bin(&s));
130+
r->pparentid = std::move(s);
128131
TRY(pctx->g_uint32(&r->flags));
129132
TRY(pctx->g_str(&r->message_class));
130133
return pctx->g_uint32(&r->message_flags);
134+
} catch (const std::bad_alloc &) {
135+
return pack_result::alloc;
131136
}
132137

133138
static pack_result ext_pack_pull_object_znotification(PULL_CTX *pctx,
134-
OBJECT_ZNOTIFICATION *r)
139+
ZNOTIFICATION *r)
135140
{
136141
uint8_t tmp_byte;
137142
uint32_t ot;
@@ -185,23 +190,16 @@ static pack_result ext_pack_pull_znotification(PULL_CTX *pctx, ZNOTIFICATION *r)
185190
{
186191
TRY(pctx->g_uint32(&r->event_type));
187192
switch (r->event_type) {
188-
case fnevNewMail: {
189-
auto nz = new NEWMAIL_ZNOTIFICATION;
190-
r->pnotification_data = nz;
191-
return ext_pack_pull_newmail_znotification(pctx, nz);
192-
}
193+
case fnevNewMail:
194+
return ext_pack_pull_newmail_znotification(pctx, r);
193195
case fnevObjectCreated:
194196
case fnevObjectDeleted:
195197
case fnevObjectModified:
196198
case fnevObjectMoved:
197199
case fnevObjectCopied:
198-
case fnevSearchComplete: {
199-
auto oz = new OBJECT_ZNOTIFICATION;
200-
r->pnotification_data = oz;
201-
return ext_pack_pull_object_znotification(pctx, oz);
202-
}
200+
case fnevSearchComplete:
201+
return ext_pack_pull_object_znotification(pctx, r);
203202
default:
204-
r->pnotification_data = NULL;
205203
return pack_result::ok;
206204
}
207205
} catch (const std::bad_alloc &) {

php_mapi/type_conversion.cpp

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,20 +1532,13 @@ ec_error_t znotification_array_to_php(const ZNOTIFICATION_ARRAY &pnotifications,
15321532
add_assoc_long(&pzvalnotif, "eventtype", nt.event_type);
15331533
switch (nt.event_type) {
15341534
case fnevNewMail: {
1535-
auto pnew_notification = static_cast<const NEWMAIL_ZNOTIFICATION *>(nt.pnotification_data);
1536-
add_assoc_stringl(&pzvalnotif, "entryid",
1537-
pnew_notification->entryid.data(),
1538-
pnew_notification->entryid.size());
1539-
add_assoc_stringl(&pzvalnotif, "parentid",
1540-
pnew_notification->parentid.data(),
1541-
pnew_notification->parentid.size());
1542-
add_assoc_long(&pzvalnotif, "flags",
1543-
pnew_notification->flags);
1544-
add_assoc_stringl(&pzvalnotif, "messageclass",
1545-
pnew_notification->message_class.data(),
1546-
pnew_notification->message_class.size());
1547-
add_assoc_long(&pzvalnotif, "messageflags",
1548-
pnew_notification->message_flags);
1535+
if (nt.pentryid.has_value())
1536+
add_assoc_stringl(&pzvalnotif, "entryid", nt.pentryid->data(), nt.pentryid->size());
1537+
if (nt.pparentid.has_value())
1538+
add_assoc_stringl(&pzvalnotif, "parentid", nt.pparentid->data(), nt.pparentid->size());
1539+
add_assoc_long(&pzvalnotif, "flags", nt.flags);
1540+
add_assoc_stringl(&pzvalnotif, "messageclass", nt.message_class.data(), nt.message_class.size());
1541+
add_assoc_long(&pzvalnotif, "messageflags", nt.message_flags);
15491542
break;
15501543
}
15511544
case fnevObjectCreated:
@@ -1554,7 +1547,7 @@ ec_error_t znotification_array_to_php(const ZNOTIFICATION_ARRAY &pnotifications,
15541547
case fnevObjectMoved:
15551548
case fnevObjectCopied:
15561549
case fnevSearchComplete: {
1557-
auto pobject_notification = static_cast<OBJECT_ZNOTIFICATION *>(nt.pnotification_data);
1550+
auto pobject_notification = &nt;
15581551
if (pobject_notification->pentryid.has_value()) {
15591552
add_assoc_stringl(&pzvalnotif, "entryid",
15601553
pobject_notification->pentryid->data(),

0 commit comments

Comments
 (0)