Skip to content

Commit

Permalink
Merge branch 'ews'
Browse files Browse the repository at this point in the history
  • Loading branch information
jengelh committed Apr 30, 2024
2 parents ad171ba + 9f500a3 commit 41b0e35
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 22 deletions.
5 changes: 2 additions & 3 deletions exch/ews/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,12 @@ void Cleaner::operator()(MESSAGE_CONTENT *x) {message_content_free(x);}
///////////////////////////////////////////////////////////////////////////////////////////////////

EWSContext::EWSContext(int id, HTTP_AUTH_INFO ai, const char *data, uint64_t length,
const std::vector<uint16_t> &srvver, EWSPlugin &p) :
m_server_version(srvver),
EWSPlugin &p) :
m_ID(id),
m_orig(*get_request(id)),
m_auth_info(ai),
m_request(data, length),
m_response(m_server_version),
m_response(p.server_version()),
m_plugin(p)
{
tinyxml2::XMLElement* imp = nullptr;
Expand Down
11 changes: 5 additions & 6 deletions exch/ews/ews.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,7 @@ http_status EWSPlugin::dispatch(int ctx_id, HTTP_AUTH_INFO& auth_info, const voi
using namespace std::string_literals;
auto &pc = contexts[ctx_id] =
std::make_unique<EWSContext>(ctx_id,
auth_info, static_cast<const char *>(data), len, m_server_version,
*this);
auth_info, static_cast<const char *>(data), len, *this);
EWSContext& context = *pc;
const XMLElement* request = context.request().body->FirstChildElement();
if(!request)
Expand Down Expand Up @@ -479,6 +478,7 @@ static constexpr cfg_directive ews_cfg_defaults[] = {
{"ews_pretty_response", "0", CFG_BOOL},
{"ews_request_logging", "0"},
{"ews_response_logging", "0"},
{"ews_schema_version", "V2017_07_11"},
{"smtp_server_ip", "::1", CFG_DEPRECATED},
{"smtp_server_port", "25", CFG_DEPRECATED},
CFG_TABLE_END,
Expand All @@ -501,9 +501,7 @@ void EWSPlugin::loadConfig()
}
auto str = gxcfg->get_value("reported_server_version");
auto &ver = m_server_version;
ver.clear();
ver.resize(4);
sscanf(str, "%hu.%hu.%hu.%hu", &ver[0], &ver[1], &ver[2], &ver[3]);
sscanf(str, "%hu.%hu.%hu.%hu", &ver.server[0], &ver.server[1], &ver.server[2], &ver.server[3]);

auto cfg = config_file_initd("exmdb_provider.cfg", get_config_path(), x500_defaults);
if(!cfg)
Expand All @@ -526,6 +524,7 @@ void EWSPlugin::loadConfig()
event_stream_interval = std::chrono::milliseconds(cfg->get_ll("ews_event_stream_interval"));
cache_embedded_instance_lifetime = std::chrono::milliseconds(cfg->get_ll("ews_cache_embedded_instance_lifetime"));
max_user_photo_size = cfg->get_ll("ews_max_user_photo_size");
ver.schema = cfg->get_value("ews_schema_version");

str = gxcfg->get_value("outgoing_smtp_url");
if (str != nullptr) {
Expand Down Expand Up @@ -654,7 +653,7 @@ int EWSContext::notify()

mGetStreamingEventsResponse data;
mGetStreamingEventsResponseMessage& msg = data.ResponseMessages.emplace_back();
SOAP::Envelope envelope(m_server_version);
SOAP::Envelope envelope(m_plugin.server_version());
tinyxml2::XMLElement* response = envelope.body->InsertNewChildElement("m:GetStreamingEventsResponse");
response->SetAttribute("xmlns:m", Structures::NS_EWS_Messages::NS_URL);
response->SetAttribute("xmlns:t", Structures::NS_EWS_Types::NS_URL);
Expand Down
7 changes: 4 additions & 3 deletions exch/ews/ews.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ class EWSPlugin {
void unsubscribe(const detail::ExmdbSubscriptionKey&) const;
void wakeContext(int, std::chrono::milliseconds) const;

inline const SOAP::VersionInfo& server_version() const {return m_server_version;}

std::string x500_org_name; ///< organization name or empty string if not configured
std::string smtp_url;
std::string timestampFormat = " "; ///< format specification for log timestamps or empty to disable timestamps
Expand Down Expand Up @@ -219,7 +221,7 @@ class EWSPlugin {

std::unique_ptr<DebugCtx> debug;
std::vector<std::string> logFilters;
std::vector<uint16_t> m_server_version;
SOAP::VersionInfo m_server_version;
bool invertFilter = true;
bool teardown = false;

Expand All @@ -236,7 +238,7 @@ class EWSContext {

enum State : uint8_t {S_DEFAULT, S_WRITE, S_DONE, S_STREAM_NOTIFY};

EWSContext(int, HTTP_AUTH_INFO, const char *, uint64_t, const std::vector<uint16_t> &ver, EWSPlugin &);
EWSContext(int, HTTP_AUTH_INFO, const char *, uint64_t, EWSPlugin &);
~EWSContext();

EWSContext(const EWSContext&) = delete;
Expand Down Expand Up @@ -361,7 +363,6 @@ class EWSContext {

PROPERTY_NAME* getPropertyName(const std::string&, uint16_t) const;

std::vector<uint16_t> m_server_version;
int m_ID = 0;
http_status m_code = http_status::ok;
State m_state = S_DEFAULT;
Expand Down
2 changes: 1 addition & 1 deletion exch/ews/serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1719,8 +1719,8 @@ void mMoveItemResponse::serialize(tinyxml2::XMLElement* xml) const
void mResponseMessageType::serialize(tinyxml2::XMLElement* xml) const
{
XMLDUMPA(ResponseClass);
XMLDUMPM(ResponseCode);
XMLDUMPM(MessageText);
XMLDUMPM(ResponseCode);
XMLDUMPM(DescriptiveLinkKey);
}

Expand Down
12 changes: 6 additions & 6 deletions exch/ews/soaputil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace gromox::EWS::SOAP
/**
* @brief Generate empty SOAP Envelope
*/
Envelope::Envelope(const std::vector<uint16_t> &ver)
Envelope::Envelope(const VersionInfo &ver)
{
auto decl = doc.NewDeclaration();
doc.InsertEndChild(decl);
Expand All @@ -36,11 +36,11 @@ Envelope::Envelope(const std::vector<uint16_t> &ver)

XMLElement* ServerVersionInfo = header->InsertNewChildElement("t:ServerVersionInfo");
ServerVersionInfo->SetAttribute("xmlns:t", NS_TYPS);
assert(ver.size() >= 4);
ServerVersionInfo->SetAttribute("MajorVersion", ver[0]);
ServerVersionInfo->SetAttribute("MinorVersion", ver[1]);
ServerVersionInfo->SetAttribute("MajorBuildNumber", ver[2]);
ServerVersionInfo->SetAttribute("MinorBuildNumber", ver[3]);
ServerVersionInfo->SetAttribute("MajorVersion", ver.server[0]);
ServerVersionInfo->SetAttribute("MinorVersion", ver.server[1]);
ServerVersionInfo->SetAttribute("MajorBuildNumber", ver.server[2]);
ServerVersionInfo->SetAttribute("MinorBuildNumber", ver.server[3]);
ServerVersionInfo->SetAttribute("Version", ver.schema.c_str());
}

/**
Expand Down
9 changes: 7 additions & 2 deletions exch/ews/soaputil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
// This file is part of Gromox.

#pragma once
#include <array>
#include <string>
#include <tinyxml2.h>
#include <vector>

namespace gromox::EWS::SOAP
{
Expand All @@ -15,13 +15,18 @@ static constexpr char NS_XSI[] = "http://www.w3.org/2001/XMLSchema-instance";
static constexpr char NS_XSD[] = "http://www.w3.org/2001/XMLSchema";
static constexpr char NS_TYPS[] = "http://schemas.microsoft.com/exchange/services/2006/types";

struct VersionInfo {
std::array<uint16_t, 4> server; ///< Server version
std::string schema; ///< EWS schema version string
};


/**
* @brief Basic class to manage SOAP Envelopes
*/
class Envelope {
public:
Envelope(const std::vector<uint16_t> &);
explicit Envelope(const VersionInfo &);
explicit Envelope(const char*, size_t=static_cast< size_t >(-1));

tinyxml2::XMLDocument doc; ///< XML document containing the envelope
Expand Down
2 changes: 1 addition & 1 deletion exch/ews/structures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1458,7 +1458,7 @@ struct tSingleRecipient
/**
* Types.xsd:4419
*/
struct tAttendee
struct tAttendee : public NS_EWS_Types
{
static constexpr char NAME[] = "Attendee";

Expand Down

0 comments on commit 41b0e35

Please sign in to comment.