Skip to content

Commit

Permalink
Merge branch 'gxl-388'
Browse files Browse the repository at this point in the history
  • Loading branch information
jengelh committed Aug 22, 2023
2 parents 2b0e9d5 + 20c4555 commit 7bcacb2
Show file tree
Hide file tree
Showing 18 changed files with 781 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ libgromox_email_la_LIBADD = ${fmt_LIBS} ${HX_LIBS} ${jsoncpp_LIBS} ${ssl_LIBS} $
libgromox_epoll_la_CXXFLAGS = ${libgromox_common_la_CXXFLAGS}
libgromox_epoll_la_SOURCES = lib/contexts_pool.cpp lib/threads_pool.cpp
libgromox_epoll_la_LIBADD = -lpthread libgromox_common.la
libgromox_exrpc_la_SOURCES = lib/exmdb_client.cpp lib/exmdb_ext.cpp lib/exmdb_rpc.cpp lib/ruleproc.cpp
libgromox_exrpc_la_SOURCES = lib/exmdb_client.cpp lib/exmdb_ext.cpp lib/exmdb_rpc.cpp lib/freebusy.cpp lib/ruleproc.cpp
libgromox_exrpc_la_LIBADD = libgromox_mapi.la
libgromox_mapi_la_CXXFLAGS = ${libgromox_common_la_CXXFLAGS}
libgromox_mapi_la_SOURCES = lib/mapi/eid_array.cpp lib/mapi/element_data.cpp lib/mapi/html.cpp lib/mapi/idset.cpp lib/mapi/lzxpress.cpp lib/mapi/msgchg_grouping.cpp lib/mapi/oxcical.cpp lib/mapi/oxcmail.cpp lib/mapi/oxvcard.cpp lib/mapi/pcl.cpp lib/mapi/proptag_array.cpp lib/mapi/propval.cpp lib/mapi/restriction.cpp lib/mapi/restriction2.cpp lib/mapi/rop_util.cpp lib/mapi/rtf.cpp lib/mapi/rtfcp.cpp lib/mapi/rule_actions.cpp lib/mapi/sortorder_set.cpp lib/mapi/tarray_set.cpp lib/mapi/tnef.cpp lib/mapi/tpropval_array.cpp
Expand Down Expand Up @@ -327,7 +327,7 @@ tzd_files = data/AUS_Central.tzd data/AUS_Eastern.tzd data/Afghanistan.tzd data/
tzd_files += data/Haiti.tzd data/Hawaiian.tzd data/India.tzd data/Iran.tzd data/Israel.tzd data/Jordan.tzd data/Kaliningrad.tzd data/Korea.tzd data/Libya.tzd data/Line_Islands.tzd data/Lord_Howe.tzd data/Magadan.tzd data/Magallanes.tzd data/Marquesas.tzd data/Mauritius.tzd data/Middle_East.tzd data/Montevideo.tzd data/Morocco.tzd data/Mountain.tzd data/Mountain__Mexico_.tzd data/Myanmar.tzd data/N__Central_Asia.tzd data/Namibia.tzd data/Nepal.tzd data/New_Zealand.tzd data/Newfoundland.tzd data/Norfolk.tzd data/North_Asia.tzd data/North_Asia_East.tzd data/North_Korea.tzd data/Omsk.tzd data/Pacific.tzd data/Pacific_SA.tzd data/Pacific__Mexico_.tzd data/Pakistan.tzd data/Paraguay.tzd data/Qyzylorda.tzd data/Romance.tzd data/Russia_Time_Zone_10.tzd data/Russia_Time_Zone_11.tzd data/Russia_Time_Zone_3.tzd data/Russian.tzd
tzd_files += data/SA_Eastern.tzd data/SA_Pacific.tzd data/SA_Western.tzd data/SE_Asia.tzd data/Saint_Pierre.tzd data/Sakhalin.tzd data/Samoa.tzd data/Sao_Tome.tzd data/Saratov.tzd data/Singapore.tzd data/South_Africa.tzd data/South_Sudan.tzd data/Sri_Lanka.tzd data/Sudan.tzd data/Syria.tzd data/Taipei.tzd data/Tasmania.tzd data/Tocantins.tzd data/Tokyo.tzd data/Tomsk.tzd data/Tonga.tzd data/Transbaikal.tzd data/Turkey.tzd data/Turks_And_Caicos.tzd data/US_Eastern.tzd data/US_Mountain.tzd data/UTC+12.tzd data/UTC+13.tzd data/UTC-02.tzd data/UTC-08.tzd data/UTC-09.tzd data/UTC-11.tzd data/UTC.tzd data/Ulaanbaatar.tzd data/Venezuela.tzd data/Vladivostok.tzd data/Volgograd.tzd data/W__Australia.tzd data/W__Central_Africa.tzd data/W__Europe.tzd data/W__Mongolia.tzd data/West_Asia.tzd data/West_Bank.tzd data/West_Pacific.tzd data/Yakutsk.tzd data/Yukon.tzd data/_GMT_+01_00_.tzd
header_files = include/gromox/ab_tree.hpp include/gromox/arcfour.hpp include/gromox/atomic.hpp include/gromox/authmgr.hpp include/gromox/binrdwr.hpp include/gromox/bounce_gen.hpp include/gromox/clock.hpp include/gromox/common_types.hpp include/gromox/config_file.hpp include/gromox/contexts_pool.hpp include/gromox/cookie_parser.hpp include/gromox/cryptoutil.hpp include/gromox/database.h include/gromox/database_mysql.hpp include/gromox/dbop.h include/gromox/dcerpc.hpp include/gromox/defs.h include/gromox/double_list.hpp include/gromox/dsn.hpp include/gromox/eid_array.hpp include/gromox/element_data.hpp include/gromox/endian.hpp include/gromox/exmdb_client.hpp include/gromox/exmdb_common_util.hpp include/gromox/exmdb_ext.hpp include/gromox/exmdb_idef.hpp include/gromox/exmdb_provider_client.hpp include/gromox/exmdb_rpc.hpp include/gromox/exmdb_server.hpp include/gromox/ext_buffer.hpp
header_files += include/gromox/fileio.h include/gromox/flusher_common.h include/gromox/generic_connection.hpp include/gromox/hook_common.h include/gromox/hpm_common.h include/gromox/html.hpp include/gromox/ical.hpp include/gromox/icase.hpp include/gromox/int_hash.hpp include/gromox/json.hpp include/gromox/list_file.hpp include/gromox/lzxpress.hpp include/gromox/mail.hpp include/gromox/mail_func.hpp include/gromox/mapi_types.hpp include/gromox/mapidefs.h include/gromox/mapierr.hpp include/gromox/mapitags.hpp include/gromox/mem_file.hpp include/gromox/midb.hpp include/gromox/mime.hpp include/gromox/mime_pool.hpp include/gromox/mjson.hpp include/gromox/msg_unit.hpp include/gromox/msgchg_grouping.hpp include/gromox/mysql_adaptor.hpp include/gromox/ndr.hpp include/gromox/ntlmssp.hpp include/gromox/oxcmail.hpp include/gromox/oxoabkt.hpp
header_files += include/gromox/fileio.h include/gromox/flusher_common.h include/gromox/freebusy.hpp include/gromox/generic_connection.hpp include/gromox/hook_common.h include/gromox/hpm_common.h include/gromox/html.hpp include/gromox/ical.hpp include/gromox/icase.hpp include/gromox/int_hash.hpp include/gromox/json.hpp include/gromox/list_file.hpp include/gromox/lzxpress.hpp include/gromox/mail.hpp include/gromox/mail_func.hpp include/gromox/mapi_types.hpp include/gromox/mapidefs.h include/gromox/mapierr.hpp include/gromox/mapitags.hpp include/gromox/mem_file.hpp include/gromox/midb.hpp include/gromox/mime.hpp include/gromox/mime_pool.hpp include/gromox/mjson.hpp include/gromox/msg_unit.hpp include/gromox/msgchg_grouping.hpp include/gromox/mysql_adaptor.hpp include/gromox/ndr.hpp include/gromox/ntlmssp.hpp include/gromox/oxcmail.hpp include/gromox/oxoabkt.hpp
header_files += include/gromox/paths.h.in include/gromox/pcl.hpp include/gromox/plugin.hpp include/gromox/proc_common.h include/gromox/proptag_array.hpp include/gromox/propval.hpp include/gromox/range_set.hpp include/gromox/resource_pool.hpp include/gromox/restriction.hpp include/gromox/rop_util.hpp include/gromox/rpc_types.hpp include/gromox/rtf.hpp include/gromox/rtfcp.hpp include/gromox/rule_actions.hpp include/gromox/safeint.hpp include/gromox/scope.hpp include/gromox/simple_tree.hpp include/gromox/sortorder_set.hpp include/gromox/stream.hpp include/gromox/svc_common.h include/gromox/svc_loader.hpp include/gromox/textmaps.hpp include/gromox/threads_pool.hpp include/gromox/tie.hpp include/gromox/timezone.hpp include/gromox/tnef.hpp include/gromox/util.hpp include/gromox/vcard.hpp include/gromox/xarray2.hpp include/gromox/zcore_client.hpp include/gromox/zcore_rpc.hpp include/gromox/zz_ndr_stack.hpp
dist_pkgdata_DATA = ${abkt_files} ${tzd_files}
toolprogs = tools/defs2php.pl tools/defs2php.sh tools/duplogid tools/enumsort tools/exmidl.pl tools/exmidl.sh tools/includesort tools/proptagsort tools/stackusage tools/warncount tools/zcidl.pl tools/zcidl.sh
Expand Down
5 changes: 3 additions & 2 deletions exch/zcore/names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,16 @@ static constexpr const char *zcore_rpc_names[] = {
E(icaltomessage2),
E(imtomessage2),
E(essdn_to_username),
E(logon_token)
E(logon_token),
E(getuserfreebusy),
};
#undef E
#undef EXP

const char *zcore_rpc_idtoname(zcore_callid i)
{
auto j = static_cast<uint8_t>(i);
static_assert(std::size(zcore_rpc_names) == static_cast<uint8_t>(zcore_callid::logon_token) + 1);
static_assert(std::size(zcore_rpc_names) == static_cast<uint8_t>(zcore_callid::getuserfreebusy) + 1);
auto s = j < std::size(zcore_rpc_names) ? zcore_rpc_names[j] : nullptr;
return znul(s);
}
19 changes: 19 additions & 0 deletions exch/zcore/rpc_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1525,6 +1525,23 @@ static pack_result zrpc_pull(EXT_PULL &x, zcreq_vcftomessage &d)
return pack_result::ok;
}

static pack_result zrpc_pull(EXT_PULL &x, zcreq_getuserfreebusy &d)
{
QRF(x.g_guid(&d.hsession));
QRF(x.g_bin(&d.entryid));
QRF(x.g_uint64(&d.starttime));
QRF(x.g_uint64(&d.endtime));
return pack_result::ok;
}

static pack_result zrpc_push(EXT_PUSH &x, const zcresp_getuserfreebusy &d)
{
QRF(x.p_uint32(d.fb_events.count));
for (size_t i = 0; i < d.fb_events.count; ++i)
QRF(x.p_fbevent(d.fb_events.fb_events[i]));
return pack_result::ok;
}

static pack_result zrpc_pull(EXT_PULL &x, zcreq_getuseravailability &d)
{
QRF(x.g_guid(&d.hsession));
Expand Down Expand Up @@ -1692,6 +1709,7 @@ pack_result rpc_ext_pull_request(const BINARY *pbin_in, zcreq *&prequest)
E(imtomessage2)
E(essdn_to_username)
E(logon_token)
E(getuserfreebusy)
#undef E
default:
return pack_result::bad_switch;
Expand Down Expand Up @@ -1808,6 +1826,7 @@ pack_result rpc_ext_push_response(const zcresp *presponse, BINARY *pbin_out)
E(imtomessage2)
E(essdn_to_username)
E(logon_token)
E(getuserfreebusy)
#undef E
default:
return pack_result::bad_switch;
Expand Down
29 changes: 29 additions & 0 deletions exch/zcore/zserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <gromox/defs.h>
#include <gromox/ext_buffer.hpp>
#include <gromox/fileio.h>
#include <gromox/freebusy.hpp>
#include <gromox/int_hash.hpp>
#include <gromox/mapi_types.hpp>
#include <gromox/mapidefs.h>
Expand Down Expand Up @@ -5080,6 +5081,34 @@ ec_error_t zs_vcftomessage(GUID hsession,
return pmessage->write_message(pmsgctnt) ? ecSuccess : ecError;
}

ec_error_t zs_getuserfreebusy(GUID hsession, BINARY entryid,
uint64_t starttime, uint64_t endtime, FB_ARRAY *fb_events)
{
char maildir[256];
char username[UADDR_SIZE];

auto pinfo = zs_query_session(hsession);
if (pinfo == nullptr)
return ecError;
if (!common_util_addressbook_entryid_to_username(entryid,
username, std::size(username)) ||
!system_services_get_maildir(username, maildir, std::size(maildir)))
return ecSuccess;

std::vector<freebusy_event> fb_data;
get_freebusy(pinfo->get_username(), maildir, starttime, endtime, fb_data);
pinfo.reset();

fb_events->count = 0;
fb_events->fb_events = cu_alloc<freebusy_event>(fb_data.size());
for (const auto &fb_event: fb_data) {
fb_events->fb_events[fb_events->count++] = fb_event;
}
fb_data.clear();

return ecSuccess;
}

ec_error_t zs_getuseravailability(GUID hsession, BINARY entryid,
uint64_t starttime, uint64_t endtime, char **ppresult_string)
{
Expand Down
1 change: 1 addition & 0 deletions exch/zcore/zserver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,4 @@ extern ec_error_t zs_getuseravailability(GUID ses, BINARY entryid, uint64_t star
extern ec_error_t zs_setpasswd(const char *username, const char *passwd, const char *new_passwd);
extern ec_error_t zs_linkmessage(GUID ses, BINARY search_eid, BINARY msg_eid);
extern ec_error_t zs_essdn_to_username(const char *essdn, char **username);
extern ec_error_t zs_getuserfreebusy(GUID ses, BINARY entryid, uint64_t starttime, uint64_t endtime, FB_ARRAY *fb_events);
3 changes: 3 additions & 0 deletions include/gromox/ext_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ struct EXT_PULL {
pack_result g_apptrecpat(APPOINTMENT_RECUR_PAT *);
pack_result g_goid(GLOBALOBJECTID *);
pack_result g_msgctnt(MESSAGE_CONTENT *);
pack_result g_fb(freebusy_event *);
pack_result g_fb_a(FB_ARRAY *);

template<typename T> inline T *anew() { return static_cast<T *>(m_alloc(sizeof(T))); }
template<typename T> inline T *anew(size_t elem) { return static_cast<T *>(m_alloc(sizeof(T) * elem)); }
Expand Down Expand Up @@ -275,6 +277,7 @@ struct EXT_PUSH {
pack_result p_goid(const GLOBALOBJECTID &);
pack_result p_msgctnt(const MESSAGE_CONTENT &);
pack_result p_rpchdr(const RPC_HEADER_EXT &);
pack_result p_fbevent(const freebusy_event &);

BOOL b_alloc = false;
union {
Expand Down
40 changes: 40 additions & 0 deletions include/gromox/freebusy.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#pragma once
#include <vector>
#include <fmt/core.h>
#include <fmt/format.h>
#include <gromox/defs.h>
#include <gromox/ical.hpp>
#include <gromox/mapidefs.h>
#include <gromox/mapi_types.hpp>

using namespace gromox;

template<> struct fmt::formatter<ICAL_TIME>
{
auto parse(format_parse_context &ctx) { return ctx.begin(); }
format_context::iterator format(const ICAL_TIME &t, format_context &ctx) const
{
return fmt::format_to(ctx.out(), "{:04}{:02}{:02}T{:02}{:02}{:02}",
t.year, t.month, t.day, t.hour, t.minute, t.second);
}
};

struct event
{
time_t start_time = 0, end_time = 0;
EXCEPTIONINFO *ei = nullptr;
EXTENDEDEXCEPTION *xe = nullptr;
};

struct freebusy_tags
{
freebusy_tags(const char *);

uint32_t apptstartwhole = 0, apptendwhole = 0, busystatus = 0, recurring = 0,
apptrecur = 0, apptsubtype = 0, private_flag = 0, apptstateflags = 0,
clipend = 0, location = 0, reminderset = 0, globalobjectid = 0,
timezonestruct = 0;
};

extern GX_EXPORT bool get_freebusy(const char *, const char *, uint64_t, uint64_t,
std::vector<freebusy_event> &);
22 changes: 22 additions & 0 deletions include/gromox/mapidefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <cstdint>
#include <cstring>
#include <memory>
#include <optional>
#include <string>
#include <gromox/defs.h>

Expand Down Expand Up @@ -867,6 +868,27 @@ struct DOUBLE_ARRAY {
double *mval;
};

struct freebusy_event_details {
freebusy_event_details(char *, char *, char *, bool, bool, bool, bool, bool);

char *id, *subject, *location;
bool is_meeting, is_recurring, is_exception, is_reminderset, is_private;
};

struct freebusy_event {
freebusy_event(time_t, time_t, uint32_t, char *, char *, char *,
bool, bool, bool, bool, bool, bool);

time_t start_time, end_time;
uint32_t busy_status;
std::optional<freebusy_event_details> details;
};

struct FB_ARRAY {
uint32_t count;
freebusy_event *fb_events;
};

/**
* The host-endian view of struct GUID is often not needed, and so a plethora
* of GUIDs exist as bytearrays/FLATUID, mostly when the consumer does not care
Expand Down
1 change: 1 addition & 0 deletions include/gromox/zcore_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,6 @@ ZCIDL(checksession, (GUID hsession))
ZCIDL(imtomessage2, (GUID session, uint32_t folder, uint32_t data_type, const char *im_data, IDLOUT LONG_ARRAY *msg_handles))
ZCIDL(essdn_to_username, (const char *essdn, IDLOUT char **username))
ZCIDL(logon_token, (const char *token, IDLOUT GUID *hsession))
ZCIDL(getuserfreebusy, (GUID hsession, BINARY entryid, uint64_t starttime, uint64_t endtime, IDLOUT FB_ARRAY *fb_events))
#undef ZCIDL
#undef IDLOUT
12 changes: 12 additions & 0 deletions include/gromox/zcore_rpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ enum class zcore_callid : uint8_t {
imtomessage2 = 0x58,
essdn_to_username = 0x59,
logon_token = 0x5a,
getuserfreebusy = 0x5b,
/* update exch/zcore/names.cpp! */
};

Expand Down Expand Up @@ -635,6 +636,13 @@ struct zcreq_essdn_to_username : public zcreq {
char *essdn;
};

struct zcreq_getuserfreebusy : public zcreq {
GUID hsession;
BINARY entryid;
uint64_t starttime;
uint64_t endtime;
};

struct zcresp {
zcore_callid call_id;
ec_error_t result;
Expand Down Expand Up @@ -873,6 +881,10 @@ struct zcresp_essdn_to_username : public zcresp {
char *username;
};

struct zcresp_getuserfreebusy : public zcresp {
FB_ARRAY fb_events;
};

using zcresp_checksession = zcresp;
using zcresp_configimport = zcresp;
using zcresp_copyfolder = zcresp;
Expand Down
Loading

0 comments on commit 7bcacb2

Please sign in to comment.