Skip to content

Commit d0ada06

Browse files
committed
exch: switch ABK helper functions to yield std::string
1 parent 036f5ae commit d0ada06

File tree

8 files changed

+43
-50
lines changed

8 files changed

+43
-50
lines changed

exch/exmdb/common_util.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3947,8 +3947,7 @@ bool cu_get_permission_property(int64_t member_id,
39473947
return TRUE;
39483948
}
39493949

3950-
BOOL common_util_parse_addressbook_entryid(const BINARY *pbin,
3951-
char *address_type, size_t atsize, char *email_address, size_t emsize)
3950+
bool cu_parse_abkeid(const BINARY *pbin, std::string &type, std::string &addr)
39523951
{
39533952
uint32_t flags;
39543953
EXT_PULL ext_pull;
@@ -3963,11 +3962,9 @@ BOOL common_util_parse_addressbook_entryid(const BINARY *pbin,
39633962
/* Tail functions will use EXT_PULL::*_eid, which parse a full EID */
39643963
ext_pull.m_offset = 0;
39653964
if (provider_uid == muidEMSAB)
3966-
return emsab_to_parts(ext_pull, address_type,
3967-
atsize, email_address, emsize) ? TRUE : false;
3965+
return emsab_to_parts(ext_pull, type, addr);
39683966
if (provider_uid == muidOOP)
3969-
return oneoff_to_parts(ext_pull, address_type,
3970-
atsize, email_address, emsize) ? TRUE : false;
3967+
return oneoff_to_parts(ext_pull, type, addr);
39713968
return FALSE;
39723969
}
39733970

exch/exmdb/instance.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,8 +1349,6 @@ BOOL exmdb_server::flush_instance(const char *dir, uint32_t instance_id,
13491349
ec_error_t *pe_result)
13501350
{
13511351
uint64_t folder_id;
1352-
char tmp_buff[1024];
1353-
char address_type[16];
13541352

13551353
auto pdb = db_engine_get_db(dir);
13561354
if (!pdb)
@@ -1462,11 +1460,10 @@ BOOL exmdb_server::flush_instance(const char *dir, uint32_t instance_id,
14621460
!pmsgctnt->proplist.has(PR_SENT_REPRESENTING_EMAIL_ADDRESS)) {
14631461
auto sr_addrtype = pmsgctnt->proplist.get<const char>(PR_SENT_REPRESENTING_ADDRTYPE);
14641462
if (sr_addrtype == nullptr) {
1465-
if (common_util_parse_addressbook_entryid(pbin,
1466-
address_type, std::size(address_type),
1467-
tmp_buff, std::size(tmp_buff))) {
1468-
if (pmsgctnt->proplist.set(PR_SENT_REPRESENTING_ADDRTYPE, address_type) != ecSuccess ||
1469-
pmsgctnt->proplist.set(PR_SENT_REPRESENTING_EMAIL_ADDRESS, tmp_buff) != ecSuccess)
1463+
std::string ntype, naddr;
1464+
if (cu_parse_abkeid(pbin, ntype, naddr)) {
1465+
if (pmsgctnt->proplist.set(PR_SENT_REPRESENTING_ADDRTYPE, ntype.c_str()) != ecSuccess ||
1466+
pmsgctnt->proplist.set(PR_SENT_REPRESENTING_EMAIL_ADDRESS, naddr.c_str()) != ecSuccess)
14701467
return FALSE;
14711468
}
14721469
} else if (strcasecmp(sr_addrtype, "EX") == 0) {
@@ -1486,11 +1483,10 @@ BOOL exmdb_server::flush_instance(const char *dir, uint32_t instance_id,
14861483
if (pbin != nullptr && !pmsgctnt->proplist.has(PR_SENDER_EMAIL_ADDRESS)) {
14871484
auto sr_addrtype = pmsgctnt->proplist.get<const char>(PR_SENDER_ADDRTYPE);
14881485
if (sr_addrtype == nullptr) {
1489-
if (common_util_parse_addressbook_entryid(pbin,
1490-
address_type, std::size(address_type),
1491-
tmp_buff, std::size(tmp_buff))) {
1492-
if (pmsgctnt->proplist.set(PR_SENDER_ADDRTYPE, address_type) != ecSuccess ||
1493-
pmsgctnt->proplist.set(PR_SENDER_EMAIL_ADDRESS, tmp_buff) != ecSuccess)
1486+
std::string ntype, naddr;
1487+
if (cu_parse_abkeid(pbin, ntype, naddr)) {
1488+
if (pmsgctnt->proplist.set(PR_SENDER_ADDRTYPE, ntype.c_str()) != ecSuccess ||
1489+
pmsgctnt->proplist.set(PR_SENDER_EMAIL_ADDRESS, naddr.c_str()) != ecSuccess)
14941490
return FALSE;
14951491
}
14961492
} else if (strcasecmp(sr_addrtype, "EX") == 0) {

exch/zcore/common_util.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,7 @@ char *common_util_dup(std::string_view sv)
410410
return out;
411411
}
412412

413-
BOOL common_util_parse_addressbook_entryid(BINARY entryid_bin, uint32_t *ptype,
414-
char *pessdn, size_t dsize)
413+
bool cu_parse_abkeid(BINARY entryid_bin, uint32_t *ptype, std::string &essdn)
415414
{
416415
EXT_PULL ext_pull;
417416
EMSAB_ENTRYID tmp_entryid;
@@ -420,7 +419,7 @@ BOOL common_util_parse_addressbook_entryid(BINARY entryid_bin, uint32_t *ptype,
420419
if (ext_pull.g_abk_eid(&tmp_entryid) != pack_result::ok)
421420
return FALSE;
422421
*ptype = tmp_entryid.type;
423-
gx_strlcpy(pessdn, tmp_entryid.x500dn.c_str(), dsize);
422+
essdn = std::move(tmp_entryid.x500dn);
424423
return TRUE;
425424
}
426425

exch/zcore/common_util.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ template<typename T> T *cu_alloc(size_t elem)
115115
void common_util_set_clifd(int clifd);
116116
extern int common_util_get_clifd();
117117
extern char *common_util_dup(std::string_view);
118-
extern BOOL common_util_parse_addressbook_entryid(BINARY, uint32_t *type, char *essdn, size_t);
118+
extern bool cu_parse_abkeid(BINARY, uint32_t *type, std::string &essdn);
119119
uint16_t common_util_get_messaging_entryid_type(BINARY bin);
120120
extern BOOL cu_entryid_to_fid(BINARY bin, BOOL *pb_private, int *pdb_id, uint64_t *pfolder_id);
121121
extern BOOL cu_entryid_to_mid(BINARY bin, BOOL *pb_private, int *pdb_id, uint64_t *pfolder_id, uint64_t *pmessage_id);

exch/zcore/zserver.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ ec_error_t zs_openentry(GUID hsession, BINARY entryid,
713713
{
714714
BOOL b_private;
715715
int account_id;
716-
char essdn[1024];
716+
std::string essdn;
717717
uint64_t folder_id;
718718
uint64_t message_id;
719719
uint32_t address_type;
@@ -724,12 +724,10 @@ ec_error_t zs_openentry(GUID hsession, BINARY entryid,
724724
return ecError;
725725
if (strncmp(entryid.pc, "/exmdb=", 7) == 0) {
726726
/* Stupid GUID-less entryid from submit.php */
727-
gx_strlcpy(essdn, entryid.pc, sizeof(essdn));
728-
return zs_openentry_emsab(hsession, entryid, flags, essdn,
727+
return zs_openentry_emsab(hsession, entryid, flags, entryid.pc,
729728
DT_REMOTE_MAILUSER, pmapi_type, phobject);
730-
} else if (common_util_parse_addressbook_entryid(entryid, &address_type,
731-
essdn, std::size(essdn))) {
732-
return zs_openentry_emsab(hsession, entryid, flags, essdn,
729+
} else if (cu_parse_abkeid(entryid, &address_type, essdn)) {
730+
return zs_openentry_emsab(hsession, entryid, flags, essdn.c_str(),
733731
address_type, pmapi_type, phobject);
734732
} else if (entryid.cb >= 20 && *reinterpret_cast<const FLATUID *>(&entryid.pb[4]) == muidZCSAB) {
735733
return zs_openentry_zcsab(hsession, entryid, flags,
@@ -828,7 +826,6 @@ ec_error_t zs_openstoreentry(GUID hsession, uint32_t hobject, BINARY entryid,
828826
uint16_t type;
829827
BOOL b_private;
830828
int account_id;
831-
char essdn[1024];
832829
uint64_t fid_val;
833830
uint8_t loc_type;
834831
zs_objtype mapi_type;
@@ -851,6 +848,9 @@ ec_error_t zs_openstoreentry(GUID hsession, uint32_t hobject, BINARY entryid,
851848
PRIVATE_FID_ROOT : PUBLIC_FID_ROOT);
852849
message_id = 0;
853850
} else {
851+
std::string essdn_s;
852+
const char *essdn = essdn_s.c_str();
853+
854854
type = common_util_get_messaging_entryid_type(entryid);
855855
switch (type) {
856856
case EITLT_PRIVATE_FOLDER:
@@ -869,12 +869,11 @@ ec_error_t zs_openstoreentry(GUID hsession, uint32_t hobject, BINARY entryid,
869869
break;
870870
}
871871
if (strncmp(entryid.pc, "/exmdb=", 7) == 0) {
872-
gx_strlcpy(essdn, entryid.pc, sizeof(essdn));
873-
} else if (common_util_parse_addressbook_entryid(entryid,
874-
&address_type, essdn, std::size(essdn)) &&
875-
strncmp(essdn, "/exmdb=", 7) == 0 &&
872+
essdn = entryid.pc;
873+
} else if (cu_parse_abkeid(entryid, &address_type, essdn_s) &&
874+
strncmp(essdn_s.c_str(), "/exmdb=", 7) == 0 &&
876875
address_type == DT_REMOTE_MAILUSER) {
877-
/* do nothing */
876+
essdn = essdn_s.c_str();
878877
} else {
879878
return ecInvalidParam;
880879
}
@@ -1049,13 +1048,13 @@ static ec_error_t zs_openab_emsab(USER_INFO_REF &&pinfo, BINARY entryid,
10491048
int base_id, zs_objtype *pmapi_type, uint32_t *phobject)
10501049
{
10511050
int user_id, domain_id;
1052-
char essdn[1024];
1051+
std::string essdn_s;
10531052
uint32_t address_type;
10541053

1055-
if (!common_util_parse_addressbook_entryid(entryid, &address_type,
1056-
essdn, std::size(essdn)))
1054+
if (!cu_parse_abkeid(entryid, &address_type, essdn_s))
10571055
return ecInvalidParam;
10581056

1057+
auto essdn = essdn_s.data();
10591058
if (address_type == DT_CONTAINER) {
10601059
CONTAINER_ID container_id;
10611060
uint8_t type;

include/gromox/exmdb_common_util.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void common_util_set_message_read(sqlite3 *psqlite,
106106
uint64_t message_id, uint8_t is_read);
107107
BINARY* common_util_username_to_addressbook_entryid(
108108
const char *username);
109-
extern BOOL common_util_parse_addressbook_entryid(const BINARY *, char *address_type, size_t atsize, char *email_address, size_t emsize);
109+
extern bool cu_parse_abkeid(const BINARY *, std::string &type, std::string &addr);
110110
BINARY* common_util_to_private_folder_entryid(
111111
sqlite3 *psqlite, const char *username,
112112
uint64_t folder_id);

include/gromox/ext_buffer.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,5 +332,5 @@ struct GX_EXPORT EXT_PUSH {
332332
EXT_BUFFER_MGT m_mgt{};
333333
};
334334

335-
extern GX_EXPORT bool emsab_to_parts(EXT_PULL &, char *type, size_t tsize, char *addr, size_t asize);
336-
extern GX_EXPORT bool oneoff_to_parts(EXT_PULL &, char *type, size_t tsize, char *addr, size_t asize);
335+
extern GX_EXPORT bool emsab_to_parts(EXT_PULL &, std::string &type, std::string &addr);
336+
extern GX_EXPORT bool oneoff_to_parts(EXT_PULL &, std::string &type, std::string &addr);

lib/mapi/ext_buffer.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3584,29 +3584,31 @@ uint8_t *EXT_PUSH::release()
35843584
return t;
35853585
}
35863586

3587-
bool emsab_to_parts(EXT_PULL &ser, char *type, size_t tsize,
3588-
char *addr, size_t asize)
3587+
bool emsab_to_parts(EXT_PULL &ser, std::string &type, std::string &addr) try
35893588
{
35903589
EMSAB_ENTRYID eid;
35913590
if (ser.g_abk_eid(&eid) != pack_result::ok || eid.type != DT_MAILUSER)
35923591
return false;
3593-
if (type != nullptr)
3594-
gx_strlcpy(type, "EX", tsize);
3595-
gx_strlcpy(addr, eid.x500dn.c_str(), asize);
3592+
type = "EX";
3593+
addr = std::move(eid.x500dn);
35963594
return true;
3595+
} catch (const std::bad_alloc &) {
3596+
mlog(LV_ERR, "E-1991: ENOMEM");
3597+
return false;
35973598
}
35983599

3599-
bool oneoff_to_parts(EXT_PULL &ser, char *type, size_t tsize,
3600-
char *addr, size_t asize)
3600+
bool oneoff_to_parts(EXT_PULL &ser, std::string &type, std::string &addr) try
36013601
{
36023602
ONEOFF_ENTRYID eid;
36033603
if (ser.g_oneoff_eid(&eid) != pack_result::ok ||
36043604
strcasecmp(eid.paddress_type.c_str(), "SMTP") != 0)
36053605
return false;
3606-
if (type != nullptr)
3607-
gx_strlcpy(type, "SMTP", tsize);
3608-
gx_strlcpy(addr, eid.pmail_address.c_str(), asize);
3606+
type = "SMTP";
3607+
addr = std::move(eid.pmail_address);
36093608
return true;
3609+
} catch (const std::bad_alloc &) {
3610+
mlog(LV_ERR, "E-1990: ENOMEM");
3611+
return false;
36103612
}
36113613

36123614
freebusy_event::freebusy_event(time_t start, time_t end, uint32_t b_status,

0 commit comments

Comments
 (0)