diff --git a/lib/mapi/oxvcard.cpp b/lib/mapi/oxvcard.cpp index da95535b1..6fafed62f 100644 --- a/lib/mapi/oxvcard.cpp +++ b/lib/mapi/oxvcard.cpp @@ -161,6 +161,19 @@ static std::string join(const char *gn, const char *mn, const char *sn) return r; } +static BOOL xlog_bool(const char *func, unsigned int line) +{ + mlog(LV_ERR, "%s:%u returned false", func, line); + return false; +} + +static std::nullptr_t xlog_null(const char *func, unsigned int line) +{ + mlog(LV_ERR, "%s:%u returned false", func, line); + return nullptr; +} + +#define imp_null xlog_null(__func__, __LINE__) MESSAGE_CONTENT *oxvcard_import(const VCARD *pvcard, GET_PROPIDS get_propids) try { int i; @@ -191,12 +204,12 @@ MESSAGE_CONTENT *oxvcard_import(const VCARD *pvcard, GET_PROPIDS get_propids) tr child_strings.count = 0; child_strings.ppstr = child_buff; if (!oxvcard_check_compatible(pvcard)) - return NULL; + return imp_null; std::unique_ptr pmsg(message_content_init()); if (pmsg == nullptr) - return NULL; + return imp_null; if (pmsg->proplist.set(PR_MESSAGE_CLASS, "IPM.Contact") != 0) - return nullptr; + return imp_null; for (const auto &line : pvcard->m_lines) try { auto pvline = &line; auto pvline_name = pvline->name(); @@ -206,7 +219,7 @@ MESSAGE_CONTENT *oxvcard_import(const VCARD *pvcard, GET_PROPIDS get_propids) tr if (pstring == nullptr) throw unrecog(line); if (pmsg->proplist.set(g_vcarduid_proptag, pstring) != 0) - return nullptr; + return imp_null; } else if (strcasecmp(pvline_name, "FN") == 0) { auto pstring = pvline->get_first_subval(); if (pstring == nullptr) @@ -214,7 +227,7 @@ MESSAGE_CONTENT *oxvcard_import(const VCARD *pvcard, GET_PROPIDS get_propids) tr if (pmsg->proplist.set(PR_DISPLAY_NAME, pstring) != 0 || pmsg->proplist.set(PR_NORMALIZED_SUBJECT, pstring) != 0 || pmsg->proplist.set(PR_CONVERSATION_TOPIC, pstring) != 0) - return nullptr; + return imp_null; } else if (strcasecmp(pvline_name, "N") == 0) { count = 0; for (const auto &vnode : pvline->m_values) { @@ -227,14 +240,14 @@ MESSAGE_CONTENT *oxvcard_import(const VCARD *pvcard, GET_PROPIDS get_propids) tr if (list_count > 0 && !pvvalue->m_subvals[0].empty() && pmsg->proplist.set(g_n_proptags[count], pvvalue->m_subvals[0].c_str()) != 0) - return nullptr; + return imp_null; count ++; } } else if (strcasecmp(pvline_name, "NICKNAME") == 0) { auto pstring = pvline->get_first_subval(); if (pstring != nullptr && pmsg->proplist.set(PR_NICKNAME, pstring) != 0) - return nullptr; + return imp_null; } else if (strcasecmp(pvline_name, "PHOTO") == 0) { if (pmsg->children.pattachments != nullptr) throw unrecog(line); @@ -266,14 +279,14 @@ MESSAGE_CONTENT *oxvcard_import(const VCARD *pvcard, GET_PROPIDS get_propids) tr throw unrecog(line); pattachments = attachment_list_init(); if (pattachments == nullptr) - return nullptr; + return imp_null; pmsg->set_attachments_internal(pattachments); pattachment = attachment_content_init(); if (pattachment == nullptr) - return nullptr; + return imp_null; if (!pattachments->append_internal(pattachment)) { attachment_content_free(pattachment); - return nullptr; + return imp_null; } tmp_len = strlen(pstring); char tmp_buff[VCARD_MAX_BUFFER_LEN]; @@ -284,13 +297,13 @@ MESSAGE_CONTENT *oxvcard_import(const VCARD *pvcard, GET_PROPIDS get_propids) tr tmp_bin.cb = decode_len; if (pattachment->proplist.set(PR_ATTACH_DATA_BIN, &tmp_bin) != 0 || pattachment->proplist.set(PR_ATTACH_EXTENSION, photo_type) != 0) - return nullptr; + return imp_null; snprintf(tmp_buff, std::size(tmp_buff), "ContactPhoto.%s", photo_type); if (pattachment->proplist.set(PR_ATTACH_LONG_FILENAME, tmp_buff) != 0) - return nullptr; + return imp_null; tmp_byte = 1; if (pmsg->proplist.set(PR_ATTACHMENT_CONTACTPHOTO, &tmp_byte) != 0) - return nullptr; + return imp_null; } else if (strcasecmp(pvline_name, "BDAY") == 0) { auto pstring = pvline->get_first_subval(); if (pstring == nullptr) @@ -300,7 +313,7 @@ MESSAGE_CONTENT *oxvcard_import(const VCARD *pvcard, GET_PROPIDS get_propids) tr /* Conversion is not exact */ tmp_int64 = rop_util_unix_to_nttime(mktime(&tmp_tm)); if (pmsg->proplist.set(PR_BIRTHDAY, &tmp_int64) != 0) - return nullptr; + return imp_null; } } else if (strcasecmp(pvline_name, "ADR") == 0) { auto pvparam = pvline->m_params.cbegin(); @@ -328,7 +341,7 @@ MESSAGE_CONTENT *oxvcard_import(const VCARD *pvcard, GET_PROPIDS get_propids) tr else tag = g_otheraddr_proptags[count]; if (pmsg->proplist.set(tag, pvvalue->m_subvals[0].c_str()) != 0) - return nullptr; + return imp_null; } count ++; } @@ -382,7 +395,7 @@ MESSAGE_CONTENT *oxvcard_import(const VCARD *pvcard, GET_PROPIDS get_propids) tr continue; } if (pmsg->proplist.set(tag, pstring) != 0) - return nullptr; + return imp_null; } else if (strcasecmp(pvline_name, "EMAIL") == 0) { auto pstring = pvline->get_first_subval(); if (pstring == nullptr) @@ -390,19 +403,19 @@ MESSAGE_CONTENT *oxvcard_import(const VCARD *pvcard, GET_PROPIDS get_propids) tr if (mail_count > 2) continue; if (pmsg->proplist.set(g_email_proptags[mail_count++], pstring) != 0) - return nullptr; + return imp_null; } else if (strcasecmp(pvline_name, "TITLE") == 0) { auto pstring = pvline->get_first_subval(); if (pstring == nullptr) continue; if (pmsg->proplist.set(PR_TITLE, pstring) != 0) - return nullptr; + return imp_null; } else if (strcasecmp(pvline_name, "ROLE") == 0) { auto pstring = pvline->get_first_subval(); if (pstring == nullptr) continue; if (pmsg->proplist.set(PR_PROFESSION, pstring) != 0) - return nullptr; + return imp_null; } else if (strcasecmp(pvline_name, "ORG") == 0) { auto pvvalue = pvline->m_values.cbegin(); if (pvvalue == pvline->m_values.cend()) @@ -411,14 +424,14 @@ MESSAGE_CONTENT *oxvcard_import(const VCARD *pvcard, GET_PROPIDS get_propids) tr if (pvvalue->m_subvals.size() > 0 && !pvvalue->m_subvals[0].empty() && pmsg->proplist.set(PR_COMPANY_NAME, pvvalue->m_subvals[0].c_str()) != 0) - return nullptr; + return imp_null; } ++pvvalue; if (pvvalue != pvline->m_values.cend()) { if (pvvalue->m_subvals.size() > 0 && !pvvalue->m_subvals[0].empty() && pmsg->proplist.set(PR_DEPARTMENT_NAME, pvvalue->m_subvals[0].c_str()) != 0) - return nullptr; + return imp_null; } } else if (strcasecmp(pvline_name, "CATEGORIES") == 0) { auto pvvalue = pvline->m_values.cbegin(); @@ -437,13 +450,13 @@ MESSAGE_CONTENT *oxvcard_import(const VCARD *pvcard, GET_PROPIDS get_propids) tr strings_array.ppstr = ptrs.data(); if (strings_array.count != 0 && pmsg->proplist.set(g_categories_proptag, &strings_array) != 0) - return nullptr; + return imp_null; } else if (strcasecmp(pvline_name, "NOTE") == 0) { auto pstring = pvline->get_first_subval(); if (pstring == nullptr) continue; if (pmsg->proplist.set(PR_BODY, pstring) != 0) - return nullptr; + return imp_null; } else if (strcasecmp(pvline_name, "REV") == 0) { auto pstring = pvline->get_first_subval(); if (pstring == nullptr) @@ -453,7 +466,7 @@ MESSAGE_CONTENT *oxvcard_import(const VCARD *pvcard, GET_PROPIDS get_propids) tr /* Conversion is not exact */ tmp_int64 = rop_util_unix_to_nttime(mktime(&tmp_tm)); if (pmsg->proplist.set(PR_LAST_MODIFICATION_TIME, &tmp_int64) != 0) - return nullptr; + return imp_null; } } else if (strcasecmp(pvline_name, "URL") == 0) { auto pvparam = pvline->m_params.cbegin(); @@ -476,7 +489,7 @@ MESSAGE_CONTENT *oxvcard_import(const VCARD *pvcard, GET_PROPIDS get_propids) tr else continue; if (pmsg->proplist.set(tag, pstring) != 0) - return nullptr; + return imp_null; } else if (strcasecmp(pvline_name, "CLASS") == 0) { auto pstring = pvline->get_first_subval(); if (pstring != nullptr) { @@ -487,7 +500,7 @@ MESSAGE_CONTENT *oxvcard_import(const VCARD *pvcard, GET_PROPIDS get_propids) tr else tmp_int32 = SENSITIVITY_NONE; if (pmsg->proplist.set(PR_SENSITIVITY, &tmp_int32) != 0) - return nullptr; + return imp_null; } } else if (strcasecmp(pvline_name, "KEY") == 0) { auto pvparam = pvline->m_params.cbegin(); @@ -510,7 +523,7 @@ MESSAGE_CONTENT *oxvcard_import(const VCARD *pvcard, GET_PROPIDS get_propids) tr tmp_bin.pc = tmp_buff; tmp_bin.cb = decode_len; if (pmsg->proplist.set(PR_USER_X509_CERTIFICATE, &bin_array) != 0) - return nullptr; + return imp_null; } else if (strcasecmp(pvline_name, "X-MS-OL-DESIGN") == 0) { auto pstring = pvline->get_first_subval(); if (pstring == nullptr) @@ -518,7 +531,7 @@ MESSAGE_CONTENT *oxvcard_import(const VCARD *pvcard, GET_PROPIDS get_propids) tr tmp_bin.cb = strlen(pstring); tmp_bin.pv = deconst(pstring); if (pmsg->proplist.set(g_bcd_proptag, &tmp_bin) != 0) - return nullptr; + return imp_null; } else if (strcasecmp(pvline_name, "X-MS-CHILD") == 0) { auto pstring = pvline->get_first_subval(); if (pstring == nullptr) @@ -533,14 +546,14 @@ MESSAGE_CONTENT *oxvcard_import(const VCARD *pvcard, GET_PROPIDS get_propids) tr if (ufld_count > 3) throw unrecog(line); if (pmsg->proplist.set(g_ufld_proptags[ufld_count++], pstring) != 0) - return nullptr; + return imp_null; } else if (strcasecmp(pvline_name, "X-MS-IMADDRESS") == 0 || strcasecmp(pvline_name, "X-MS-RM-IMACCOUNT") == 0) { auto pstring = pvline->get_first_subval(); if (pstring == nullptr) continue; if (pmsg->proplist.set(g_im_proptag, pstring) != 0) - return nullptr; + return imp_null; } else if (strcasecmp(pvline_name, "X-MS-TEL") == 0) { auto pvparam = pvline->m_params.cbegin(); if (pvparam == pvline->m_params.cend()) @@ -565,7 +578,7 @@ MESSAGE_CONTENT *oxvcard_import(const VCARD *pvcard, GET_PROPIDS get_propids) tr else throw unrecog(line, *pvparam); if (pmsg->proplist.set(tag, pstring) != 0) - return nullptr; + return imp_null; } else if (strcasecmp(pvline_name, "X-MS-ANNIVERSARY") == 0) { auto pstring = pvline->get_first_subval(); if (pstring == nullptr) @@ -575,7 +588,7 @@ MESSAGE_CONTENT *oxvcard_import(const VCARD *pvcard, GET_PROPIDS get_propids) tr /* Conversion is not exact */ tmp_int64 = rop_util_unix_to_nttime(mktime(&tmp_tm)); if (pmsg->proplist.set(PR_WEDDING_ANNIVERSARY, &tmp_int64) != 0) - return nullptr; + return imp_null; } } else if (strcasecmp(pvline_name, "X-MS-SPOUSE") == 0) { auto pvparam = pvline->m_params.cbegin(); @@ -588,7 +601,7 @@ MESSAGE_CONTENT *oxvcard_import(const VCARD *pvcard, GET_PROPIDS get_propids) tr if (pstring == nullptr) continue; if (pmsg->proplist.set(PR_SPOUSE_NAME, pstring) != 0) - return nullptr; + return imp_null; } else if (strcasecmp(pvline_name, "X-MS-MANAGER") == 0) { auto pvparam = pvline->m_params.cbegin(); if (pvparam == pvline->m_params.cend()) @@ -600,7 +613,7 @@ MESSAGE_CONTENT *oxvcard_import(const VCARD *pvcard, GET_PROPIDS get_propids) tr if (pstring == nullptr) continue; if (pmsg->proplist.set(PR_MANAGER_NAME, pstring) != 0) - return nullptr; + return imp_null; } else if (strcasecmp(pvline_name, "X-MS-ASSISTANT") == 0) { auto pvparam = pvline->m_params.cbegin(); if (pvparam == pvline->m_params.cend()) @@ -612,13 +625,13 @@ MESSAGE_CONTENT *oxvcard_import(const VCARD *pvcard, GET_PROPIDS get_propids) tr if (pstring == nullptr) continue; if (pmsg->proplist.set(PR_ASSISTANT, pstring) != 0) - return nullptr; + return imp_null; } else if (strcasecmp(pvline_name, "FBURL") == 0) { auto pstring = pvline->get_first_subval(); if (pstring == nullptr) continue; if (pmsg->proplist.set(g_fbl_proptag, pstring) != 0) - return nullptr; + return imp_null; } else if (strcasecmp(pvline_name, "X-MS-INTERESTS") == 0) { auto pvvalue = pvline->m_values.cbegin(); if (pvvalue == pvline->m_values.cend()) @@ -636,7 +649,7 @@ MESSAGE_CONTENT *oxvcard_import(const VCARD *pvcard, GET_PROPIDS get_propids) tr strings_array.ppstr = ptrs.data(); if (strings_array.count != 0 && pmsg->proplist.set(PR_HOBBIES, &strings_array) != 0) - return nullptr; + return imp_null; } } catch (const unrecog &e) { if (g_oxvcard_pedantic) { @@ -646,23 +659,23 @@ MESSAGE_CONTENT *oxvcard_import(const VCARD *pvcard, GET_PROPIDS get_propids) tr } if (child_strings.count != 0 && pmsg->proplist.set(PR_CHILDRENS_NAMES, &child_strings) != 0) - return nullptr; + return imp_null; if (!pmsg->proplist.has(PR_DISPLAY_NAME)) { auto dn = join(pmsg->proplist.get(PR_GIVEN_NAME), pmsg->proplist.get(PR_MIDDLE_NAME), pmsg->proplist.get(PR_SURNAME)); if (pmsg->proplist.set(PR_DISPLAY_NAME, dn.c_str()) != 0) - return nullptr; + return imp_null; } if (!pmsg->proplist.has(PR_NORMALIZED_SUBJECT)) { auto dn = pmsg->proplist.get(PR_DISPLAY_NAME); if (dn != nullptr && pmsg->proplist.set(PR_NORMALIZED_SUBJECT, dn) != 0) - return nullptr; + return imp_null; } if (!pmsg->proplist.has(PR_CONVERSATION_TOPIC)) { auto dn = pmsg->proplist.get(PR_DISPLAY_NAME); if (dn != nullptr && pmsg->proplist.set(PR_CONVERSATION_TOPIC, dn) != 0) - return nullptr; + return imp_null; } for (i=0; iproplist.count; i++) { proptag = pmsg->proplist.ppropval[i].proptag; @@ -674,7 +687,7 @@ MESSAGE_CONTENT *oxvcard_import(const VCARD *pvcard, GET_PROPIDS get_propids) tr /* If no namedprops were set, we can exit early */ return pmsg.release(); if (!oxvcard_get_propids(&propids, std::move(get_propids))) - return nullptr; + return imp_null; for (i=0; iproplist.count; i++) { proptag = pmsg->proplist.ppropval[i].proptag; propid = PROP_ID(proptag); @@ -689,7 +702,9 @@ MESSAGE_CONTENT *oxvcard_import(const VCARD *pvcard, GET_PROPIDS get_propids) tr mlog(LV_ERR, "E-1158: ENOMEM"); return nullptr; } +#undef imp_null +#define exp_false xlog_bool(__func__, __LINE__) BOOL oxvcard_export(MESSAGE_CONTENT *pmsg, vcard &vcard, GET_PROPIDS get_propids) try { const char *pvalue; @@ -779,7 +794,7 @@ BOOL oxvcard_export(MESSAGE_CONTENT *pmsg, vcard &vcard, GET_PROPIDS get_propids photo_line.append_param("TYPE", photo_type); photo_line.append_param("ENCODING", "B"); if (encode64(bv->pb, bv->cb, tmp_buff, VCARD_MAX_BUFFER_LEN - 1, &out_len) != 0) - return false; + return exp_false; tmp_buff[out_len] = '\0'; photo_line.append_value(tmp_buff); break; @@ -978,7 +993,7 @@ BOOL oxvcard_export(MESSAGE_CONTENT *pmsg, vcard &vcard, GET_PROPIDS get_propids key_line.append_param("ENCODING", "B"); if (encode64(ba->pbin->pb, ba->pbin->cb, tmp_buff, std::size(tmp_buff) - 1, &out_len) != 0) - return false; + return exp_false; tmp_buff[out_len] = '\0'; key_line.append_value(tmp_buff); } @@ -1025,3 +1040,4 @@ BOOL oxvcard_export(MESSAGE_CONTENT *pmsg, vcard &vcard, GET_PROPIDS get_propids mlog(LV_ERR, "E-1605: ENOMEM"); return false; } +#undef exp_false