Browse Source

add group_join()

LIB-11
heck 3 months ago
parent
commit
9780232015
9 changed files with 168 additions and 14 deletions
  1. +29
    -10
      src/group_manager_api.cc
  2. +29
    -1
      src/group_manager_api.h
  3. +42
    -1
      src/grp_driver_dummy.cc
  4. +6
    -1
      src/grp_driver_dummy.hh
  5. +11
    -1
      src/grp_driver_engine.cc
  6. +5
    -0
      src/grp_driver_engine.hh
  7. +36
    -0
      src/grp_driver_replicator.cc
  8. +5
    -0
      src/grp_driver_replicator.hh
  9. +5
    -0
      src/grp_manager_interface.hh

+ 29
- 10
src/group_manager_api.cc View File

@ -1,7 +1,7 @@
// This file is under GNU General Public License 3.0
// see LICENSE.txt
//#include <pEp/group.h>
// clang-format off
#include "group_manager_api.h"
#include "grp_driver_replicator.hh"
#include "pEpLog.hh"
@ -23,17 +23,21 @@ DYNAMIC_API PEP_STATUS adapter_group_init()
{
PEP_STATUS status;
try {
const string lm_dummy_db_filename = "listman_dummy.db";
const string lm_dummy_db_filename = "groups.db";
#ifdef WIN32
const string lm_dummy_db_path = string(::per_user_directory()) + "\\" + lm_dummy_db_filename;
#else
const string lm_dummy_db_path = string(::per_user_directory()) + "/" + lm_dummy_db_filename;
#endif
grp_drv_dummy = make_shared<Adapter::GroupDriverDummy>(lm_dummy_db_path);
grp_drv_engine = make_shared<Adapter::GroupDriverEngine>();
if(!grp_drv_dummy) {
grp_drv_dummy = make_shared<Adapter::GroupDriverDummy>(lm_dummy_db_path);
}
if(!grp_drv_engine) {
grp_drv_engine = make_shared<Adapter::GroupDriverEngine>();
}
adapter_grp_manager.set_replication_source(*grp_drv_dummy.get());
adapter_grp_manager.set_replication_destination(*grp_drv_engine.get());
// adapter_grp_manager.logger.set_enabled(true);
} catch (const std::exception &e) {
pEpLog(Utils::nested_exception_to_string(e));
status = PEP_UNKNOWN_ERROR;
@ -54,14 +58,19 @@ DYNAMIC_API PEP_STATUS adapter_group_create(
identity_list *memberlist)
{
pEpLog("called");
PEP_STATUS status = adapter_grp_manager
.adapter_group_create(session, group_identity, manager, memberlist);
PEP_STATUS status = adapter_grp_manager.adapter_group_create(
session,
group_identity,
manager,
memberlist);
return status;
}
DYNAMIC_API PEP_STATUS
adapter_group_dissolve(PEP_SESSION session, pEp_identity *group_identity, pEp_identity *manager)
DYNAMIC_API PEP_STATUS adapter_group_dissolve(
PEP_SESSION session,
pEp_identity *group_identity,
pEp_identity *manager)
{
pEpLog("called");
PEP_STATUS status = adapter_grp_manager.adapter_group_dissolve(session, group_identity, manager);
@ -81,7 +90,7 @@ DYNAMIC_API PEP_STATUS adapter_group_invite_member(
return status;
}
PEP_STATUS adapter_group_remove_member(
DYNAMIC_API PEP_STATUS adapter_group_remove_member(
PEP_SESSION session,
pEp_identity *group_identity,
pEp_identity *group_member)
@ -94,6 +103,16 @@ PEP_STATUS adapter_group_remove_member(
return status;
}
DYNAMIC_API PEP_STATUS adapter_group_join(
PEP_SESSION session,
pEp_identity *group_identity,
pEp_identity *as_member)
{
pEpLog("called");
PEP_STATUS status = adapter_grp_manager.adapter_group_join(session, group_identity, as_member);
return status;
}
/*************************************************************************************************
* Group query functions
*************************************************************************************************/


+ 29
- 1
src/group_manager_api.h View File

@ -129,12 +129,40 @@ DYNAMIC_API PEP_STATUS adapter_group_invite_member(
* @todo Revamp implementation and execute key reset
*
*/
PEP_STATUS adapter_group_remove_member(
DYNAMIC_API PEP_STATUS adapter_group_remove_member(
PEP_SESSION session,
pEp_identity *group_identity,
pEp_identity *group_member);
/**
* <!-- group_join() -->
*
* @brief Join a group for which we have received an invitation, marking
* our own membership in the database for the group and sending the manager
* a confirmation of the acceptance of the invitation
*
* @param[in] session associated session object
* @param[in] group_identity the pEp_identity object representing the group. Must contain at least
* a user_id and address
* @param[in] as_member the pEp_identity object representing the own identity we want to use to
* join the group. This must match the identity which was invited to the group.
* Must contain a user_id and address.
*
* @retval PEP_STATUS_OK on success
* error on failure
*
* @ownership FIXME
*
*
*/
DYNAMIC_API PEP_STATUS adapter_group_join(
PEP_SESSION session,
pEp_identity *group_identity,
pEp_identity *as_member
);
/*************************************************************************************************
* Group query functions
*************************************************************************************************/


+ 42
- 1
src/grp_driver_dummy.cc View File

@ -214,6 +214,47 @@ namespace pEp {
return status;
}
PEP_STATUS GroupDriverDummy::adapter_group_join(
PEP_SESSION session,
pEp_identity *group_identity,
pEp_identity *as_member) noexcept
{
pEpLogClass("called");
// TODO: listmanager member db list_join()
// PEP_STATUS status = PEP_UNKNOWN_ERROR;
// if (!group_identity || !group_member) {
// status = PEP_ILLEGAL_VALUE;
// } else {
// if (Utils::is_c_str_empty(group_identity->address) ||
// Utils::is_c_str_empty(group_member->address)) {
// status = PEP_ILLEGAL_VALUE;
// } else {
// const string addr_list{ group_identity->address };
// const string addr_member{ group_member->address };
//
// try {
// lmd.member_remove(addr_list, addr_member);
// status = PEP_STATUS_OK;
// } catch (const MemberDoesNotExistException &e) {
// pEpLogClass(Utils::nested_exception_to_string(e));
// // TODO: Silently succeed???
// status = PEP_STATUS_OK;
// } catch (const ListDoesNotExistException &e) {
// pEpLogClass(Utils::nested_exception_to_string(e));
// status = PEP_GROUP_NOT_FOUND;
// } catch (const exception &e) {
// pEpLogClass(Utils::nested_exception_to_string(e));
// status = PEP_UNKNOWN_ERROR;
// } catch (...) {
// pEpLogClass("unknown exception");
// status = PEP_UNKNOWN_ERROR;
// }
// }
// }
return PEP_STATUS_OK;
}
PEP_STATUS GroupDriverDummy::group_query_groups(PEP_SESSION session, identity_list **groups) noexcept
{
pEpLogClass("called");
@ -302,7 +343,7 @@ namespace pEp {
if (!session || !group) {
status = PEP_ILLEGAL_VALUE;
} else {
if (!Utils::is_c_str_empty(group->address)) {
if (Utils::is_c_str_empty(group->address)) {
status = PEP_ILLEGAL_VALUE;
} else {
const string addr_grp{ group->address };


+ 6
- 1
src/grp_driver_dummy.hh View File

@ -13,7 +13,7 @@ namespace pEp {
class GroupDriverDummy : public GroupManagerInterface {
public:
GroupDriverDummy() = delete;
GroupDriverDummy(const std::string &db_path);
explicit GroupDriverDummy(const std::string &db_path);
// GroupUpdateInterface
PEP_STATUS adapter_group_create(
@ -37,6 +37,11 @@ namespace pEp {
::pEp_identity *group_identity,
::pEp_identity *group_member) noexcept override;
PEP_STATUS adapter_group_join(
::PEP_SESSION session,
::pEp_identity *group_identity,
::pEp_identity *as_member) noexcept override;
// GroupQueryInterface
PEP_STATUS group_query_groups(::PEP_SESSION session, ::identity_list **groups) noexcept override;


+ 11
- 1
src/grp_driver_engine.cc View File

@ -9,7 +9,8 @@ namespace pEp {
namespace Adapter {
bool GroupDriverEngine::log_enabled = false;
GroupDriverEngine::GroupDriverEngine() {
GroupDriverEngine::GroupDriverEngine()
{
pEpLogClass("called");
}
@ -49,5 +50,14 @@ namespace pEp {
pEpLogClass("called");
return ::group_remove_member(session, group_identity, group_member);
}
PEP_STATUS GroupDriverEngine::adapter_group_join(
PEP_SESSION session,
pEp_identity *group_identity,
pEp_identity *as_member) noexcept
{
pEpLogClass("called");
return ::group_join(session, group_identity, as_member);
}
} // namespace Adapter
} // namespace pEp

+ 5
- 0
src/grp_driver_engine.hh View File

@ -34,6 +34,11 @@ namespace pEp {
::pEp_identity *group_identity,
::pEp_identity *group_member) noexcept override;
PEP_STATUS adapter_group_join(
::PEP_SESSION session,
::pEp_identity *group_identity,
::pEp_identity *as_member) noexcept override;
// Logging
static bool log_enabled;
Adapter::pEpLog::pEpLogger logger{ "GroupDriverEngine", log_enabled };


+ 36
- 0
src/grp_driver_replicator.cc View File

@ -175,6 +175,42 @@ namespace pEp {
return status;
}
PEP_STATUS GroupDriverReplicator::adapter_group_join(
::PEP_SESSION session,
::pEp_identity *group_identity,
::pEp_identity *as_member) noexcept
{
pEpLogClass("called");
if (!has_repl_src_and_dst()) {
return PEP_UNKNOWN_ERROR;
}
// Do listmanager
PEP_STATUS status = repl_src->adapter_group_join(
session,
group_identity,
as_member);
if (status != PEP_STATUS_OK) {
return status;
}
// Do engine
status = repl_dst->adapter_group_join(session, group_identity, as_member);
if (status != PEP_STATUS_OK) {
// Rollback
// TODO: need group_leave
// PEP_STATUS rb_stat = repl_src->adapter_group(
// session,
// group_identity,
// as_member);
// if (rb_stat != PEP_STATUS_OK) {
// //FATAL ERROR ON ROLLBACK
// status = (PEP_STATUS)-9999;
// }
}
return status;
}
// GroupQueryInterface
PEP_STATUS GroupDriverReplicator::group_query_groups(
PEP_SESSION session,


+ 5
- 0
src/grp_driver_replicator.hh View File

@ -40,6 +40,11 @@ namespace pEp {
::pEp_identity *group_identity,
::pEp_identity *group_member) noexcept override;
PEP_STATUS adapter_group_join(
::PEP_SESSION session,
::pEp_identity *group_identity,
::pEp_identity *as_member) noexcept override;
// GroupQueryInterface
PEP_STATUS group_query_groups(::PEP_SESSION session, ::identity_list **groups) noexcept override;


+ 5
- 0
src/grp_manager_interface.hh View File

@ -31,6 +31,11 @@ namespace pEp {
::pEp_identity *group_identity,
::pEp_identity *group_member) noexcept = 0;
virtual PEP_STATUS adapter_group_join(
::PEP_SESSION session,
::pEp_identity *group_identity,
::pEp_identity *as_member) noexcept = 0;
private:
};


Loading…
Cancel
Save