Commit 7eca0de9 authored by claes's avatar claes

*** empty log message ***

parent a9e67924
This diff is collapsed.
/*
* Proview $Id: co_pvd_file.h,v 1.1 2006-09-14 14:16:07 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#ifndef co_pvd_file_h
#define co_pvd_file_h
#include "co_provider.h"
#include "co_procom.h"
class co_pvd_file : public co_provider {
public:
co_pvd_file( pvd_eEnv env = pvd_eEnv_Wb) : co_provider(env), root(0), next_oix(1) {}
virtual void object( co_procom *pcom);
virtual void objectOid( co_procom *pcom, pwr_tOix oix);
virtual void objectName( co_procom *pcom, char *name);
virtual void objectBody( co_procom *pcom, pwr_tOix oix);
virtual void createObject( co_procom *pcom, pwr_tOix destoix, int desttype,
pwr_tCid cid, char *name);
virtual void moveObject( co_procom *pcom, pwr_tOix oix, pwr_tOix destoix, int desttype);
virtual void copyObject( co_procom *pcom, pwr_tOix oix, pwr_tOix destoix, int desttype,
char *name);
virtual void deleteObject( co_procom *pcom, pwr_tOix oix);
virtual void deleteFamily( co_procom *pcom, pwr_tOix oix);
virtual void renameObject( co_procom *pcom, pwr_tOix oix, char *name);
virtual void writeAttribute( co_procom *pcom, pwr_tOix oix, unsigned int offset,
unsigned int size, char *buffer);
virtual void readAttribute( co_procom *pcom, pwr_tOix oix, unsigned int offset,
unsigned int size);
virtual void subAssociateBuffer( co_procom *pcom, void **buff, int oix, int offset,
int size, pwr_tSubid sid);
virtual void commit( co_procom *pcom);
virtual void abort( co_procom *pcom);
virtual char *longname( pwr_tOix oix);
virtual void delete_tree( pwr_tOix oix);
virtual void save( pwr_tStatus *sts) {}
virtual void load( pwr_tStatus *rsts) {}
virtual bool find( pwr_tOix fthoix, char *name, pwr_tOix *oix);
vector<procom_obj> m_list;
pwr_tOix root;
pwr_tOix next_oix;
};
#endif
/*
* Proview $Id: co_pvd_udb.cpp,v 1.1 2006-09-14 14:16:07 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#include <vector.h>
#include <string.h>
#include <stdio.h>
#include <iostream.h>
#include <fstream.h>
#include "pwr.h"
#include "pwr_class.h"
#include "pwr_baseclasses.h"
#include "wb_vext.h"
#include "co_pvd_udb.h"
#include "wb_ldh.h"
#include "wb_ldh_msg.h"
extern "C" {
#include "co_cdh.h"
#include "co_dcli.h"
}
void co_pvd_udb::save( pwr_tStatus *sts)
{
gu->clear();
for ( int i = 1; i < (int)m_list.size(); i++) {
if ( m_list[i].flags & procom_obj_mFlags_Deleted)
continue;
switch ( m_list[i].cid) {
case pwr_cClass_SystemGroupReg: {
pwr_sClass_SystemGroupReg *body = (pwr_sClass_SystemGroupReg *)m_list[i].body;
*sts = gu->add_system( groupname(longname( m_list[i].oix)), body->Attributes);
if ( EVEN(*sts)) return;
break;
}
case pwr_cClass_UserReg: {
pwr_sClass_UserReg *body = (pwr_sClass_UserReg *)m_list[i].body;
char gname[120];
char *s;
strcpy( gname, longname( m_list[i].oix));
if ( (s = strrchr( gname, '-')))
*s = 0;
*sts = gu->add_user( groupname(gname), m_list[i].name, body->Password,
body->Privileges);
if ( EVEN(*sts)) return;
break;
}
default: ;
}
}
*sts = gu->save();
}
char *co_pvd_udb::groupname( char *name)
{
static char str[200];
char *s, *t;
for ( s = name, t = str; *s; s++,t++) {
if ( *s == '-')
*t = '.';
else
*t = *s;
}
*t = 0;
return str;
}
void co_pvd_udb::load( pwr_tStatus *rsts)
{
char filename[256];
int sts;
if ( gu)
gu->clear();
else
gu = new GeUser();
sts = dcli_get_defaultfilename( user_cFilename, filename, "");
gu->load( filename);
// Create Root object
procom_obj rootitem;
if ( m_env == pvd_eEnv_Wb) {
strcpy( rootitem.name, "UserDatabase");
rootitem.cid = pwr_eClass_PlantHier;
rootitem.oix = 0;
}
else {
strcpy( rootitem.name, "VolUserDatabase");
rootitem.cid = pwr_eClass_ExternVolume;
rootitem.oix = 0;
rootitem.body_size = sizeof(pwr_sExternVolume);
rootitem.body = calloc( 1, rootitem.body_size);
}
m_list.push_back(rootitem);
menu_stack[menu_cnt] = rootitem.oix;
menu_cnt++;
SystemList *systemgroup = gu->root_system();
while ( systemgroup) {
load_systemgroup( systemgroup);
systemgroup = systemgroup->next_system();
}
if ( m_env == pvd_eEnv_Rt) {
// Convert to Rt style
for ( int i = 1; i < (int)m_list.size(); i++) {
if ( m_list[i].bwsoix == 0)
m_list[i].bwsoix = m_list[m_list[i].fthoix].lchoix;
if ( m_list[i].fwsoix == 0)
m_list[i].fwsoix = m_list[m_list[i].fthoix].fchoix;
}
}
}
void co_pvd_udb::load_systemgroup( SystemList *systemgroup)
{
procom_obj item;
pwr_sClass_SystemGroupReg *body;
char sname[120];
char *s;
item.oix = next_oix++;
item.cid = pwr_cClass_SystemGroupReg;
item.fthoix = menu_stack[menu_cnt - 1];
item.bwsoix = m_list[item.fthoix].lchoix;
if ( item.bwsoix)
m_list[item.bwsoix].fwsoix = item.oix;
if ( m_list[item.fthoix].fchoix == 0)
m_list[item.fthoix].fchoix = item.oix;
m_list[item.fthoix].lchoix = item.oix;
item.body_size = sizeof(pwr_sClass_SystemGroupReg);
body = (pwr_sClass_SystemGroupReg *) calloc( 1, item.body_size);
item.body = body;
gu->get_system_name( systemgroup, sname);
if (( s = strrchr( sname, '.')))
strcpy( item.name, s+1);
else
strcpy( item.name, sname);
gu->get_system_data( sname, &body->Attributes);
menu_stack[menu_cnt] = item.oix;
menu_cnt++;
m_list.push_back( item);
UserList *user = systemgroup->first_user();
while ( user) {
load_user( user, systemgroup);
user = user->next_user();
}
SystemList *sg = systemgroup->first_system();
while ( sg) {
load_systemgroup( sg);
sg = sg->next_system();
}
menu_cnt--;
}
void co_pvd_udb::load_user( UserList *user, SystemList *sg)
{
procom_obj item;
pwr_sClass_UserReg *body;
item.oix = next_oix++;
item.cid = pwr_cClass_UserReg;
item.fthoix = menu_stack[menu_cnt - 1];
item.bwsoix = m_list[item.fthoix].lchoix;
if ( item.bwsoix)
m_list[item.bwsoix].fwsoix = item.oix;
if ( m_list[item.fthoix].fchoix == 0)
m_list[item.fthoix].fchoix = item.oix;
m_list[item.fthoix].lchoix = item.oix;
item.body_size = sizeof(pwr_sClass_UserReg);
body = (pwr_sClass_UserReg *) calloc( 1, item.body_size);
item.body = body;
strcpy( item.name, user->get_name());
user->get_data( body->Password, &body->Privileges);
m_list.push_back( item);
}
/*
* Proview $Id: co_pvd_udb.h,v 1.1 2006-09-14 14:16:07 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
// Provider for user database
#ifndef co_pvd_udb_h
#define co_pvd_udb_h
#include "co_pvd_file.h"
#include "co_user.h"
class co_pvd_udb : public co_pvd_file {
public:
co_pvd_udb( pvd_eEnv env = pvd_eEnv_Wb) : co_pvd_file(env), gu(0), menu_cnt(0)
{
pwr_tStatus sts;
load( &sts);
}
void load( pwr_tStatus *rsts);
void load_systemgroup( SystemList *systemgroup);
void load_user( UserList *user, SystemList *sg);
void save( pwr_tStatus *sts);
char *groupname( char *name);
GeUser *gu;
int menu_stack[100];
int menu_cnt;
};
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment