////////////////////////////////////////////////////////////
//
// Implementation of classes
// CDSGroupManager
//
// Copyright 2001
//
////////////////////////////////////////////////////////////
#include <string.h>
#include "DceManager.h"
// CDSGroupManager
int CDSGroupManager::node::set_name(const unsigned_char_t *n)
{
delete []name; name=0;
name=new unsigned_char_t [strlen((const char*)n) +1];
strcpy((char*)name,(const char*)n);
return 0;
}
CDSGroupManager::CDSGroupManager(const char *n, bool create, bool clear,unsigned32 syntax):
status(0),
group_name(0),
group_name_syntax(syntax),
clear_group(clear),
clear_group_entry(clear)
{
unsigned32 s=0;
group_name = new unsigned_char_t [strlen(n)+1];
strcpy((char*)group_name,n);
if(!create) clear_group_entry=false;
else
{
rpc_ns_mgmt_entry_create(group_name_syntax,group_name,&s);
if(s==rpc_s_entry_already_exists) clear_group_entry=false;
else if(s != rpc_s_ok)
{
status=1;
return;
}
}
if(!clear_group) clear_group_entry=false;
}
CDSGroupManager::~CDSGroupManager()
{
unsigned32 s=0;
if(clear_group)
{
node n;
while( ! members.pop(n))
{
rpc_ns_group_mbr_remove(group_name_syntax,group_name,n.syntax,n.name,&s);
}
}
if(clear_group_entry)
rpc_ns_mgmt_entry_delete(group_name_syntax,group_name,&s);
delete []group_name;
}
int CDSGroupManager::add_member(const char *name, unsigned32 syntax )
{
if(status) return 1;
unsigned32 s=0;
rpc_ns_group_mbr_add(group_name_syntax,group_name,syntax,(unsigned_char_p_t)name,&s);
if(s != rpc_s_ok) return 1;
if(clear_group)
{
node n(name,syntax);
members.push(n);
}
return 0;
}