Skip to content

Commit

Permalink
ews: add ews schema version
Browse files Browse the repository at this point in the history
Cherry-pick commit gromox-2.27-119-g9f500a39a .
  • Loading branch information
juliaschroeder authored and jengelh committed May 2, 2024
1 parent ed08e67 commit 53695e9
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 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
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

0 comments on commit 53695e9

Please sign in to comment.