home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Encyclopedia 96-1
/
novell-nsepro-1996-1-cd2.iso
/
download
/
netware
/
modsma.exe
/
MODSCMA.C
next >
Wrap
C/C++ Source or Header
|
1995-03-13
|
36KB
|
1,376 lines
/****************************************************************************
** File: MODSCMA.C
**
** Desc: This program designed to display the NDS Schema. It lists all of
** classes and the attributes associated with each class. Also
** demonstrated is how to add this program to the NWAdmin "Tools"
** menu.
**
**
** DISCLAIMER
**
** Novell, Inc. makes no representations or warranties with respect to
** any NetWare software, and specifically disclaims any express or
** implied warranties of merchantability, title, or fitness for a
** particular purpose.
**
** Distribution of any NetWare software is forbidden without the
** express written consent of Novell, Inc. Further, Novell reserves
** the right to discontinue distribution of any NetWare software.
**
** Novell is not responsible for lost profits or revenue, loss of use
** of the software, loss of data, costs of re-creating lost data, the
** cost of any substitute equipment or program, or claims by any party
** other than you. Novell strongly recommends a backup be made before
** any software is installed. Technical support for this software
** may be provided at the discretion of Novell.
**
** Programmers:
**
** Ini Who Firm
** -----------------------------------------------------------------------
** KLB Karl Bunnell Novell Developer Support.
**
** History:
**
** When Who What
** -----------------------------------------------------------------------
** 12-01-94 klb First code.
*/
/****************************************************************************
** Include headers, macros, function prototypes, etc.
*/
/*------------------------------------------------------------------------
** ANSI
*/
#include <windows.h>
#include <bwcc.h>
#include <toolhelp.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
/*------------------------------------------------------------------------
** NetWare
*/
#include <nwnet.h>
#include <nwsnapin.h>
#include "modscma.h"
/*------------------------------------------------------------------------
** Prototypes
*/
#ifdef __cplusplus
extern "C"
{
#endif
BOOL FAR PASCAL _export ModSchemaDlgProc(HWND hDlg, UINT message, UINT wParam,
LONG lParam);
ReadAttributeInfo(HWND hDlg);
WORD ReadClassInfo(HWND hDlg);
N_EXTERN_LIBRARY( void ) ModSchemaMenuAction(void);
N_EXTERN_LIBRARY( void ) ModSchemaMenuValid(pnuint16 pFlags);
WORD CreateClass(HWND hDlg);
WORD ReadClassFlagInfo(HWND hDlg);
WORD ReadAttrFlagInfo(HWND hDlg);
WORD ReadSyntaxInfo(HWND hDlg);
WORD RemoveClassDefinition(HWND hDlg);
WORD RemoveAttributeDefinition(HWND hDlg);
WORD ModifyClass(HWND hDlg);
WORD CreateAttribute(HWND hDlg);
AttrClear(HWND hDlg);
ClassClear(HWND hDlg);
ClassResetComboBoxes(HWND hDlg);
AttrResetComboBoxes(HWND hDlg);
#ifdef __cplusplus
}
#endif
/*------------------------------------------------------------------------
** Globals
*/
HINSTANCE hDLL;
char attrNameBuf[MAX_SCHEMA_NAME_BYTES];
char classNameBuf[MAX_SCHEMA_NAME_BYTES];
// int superClassFlag = 0;
// int superClassCount = 0;
/***************************************************************************
** DLL Entry Point
*/
int FAR PASCAL LibMain (HINSTANCE hInstance, WORD wDataSeg,
WORD cbHeapSize, LPSTR lpCmdLine)
{
hDLL = hInstance;
if(cbHeapSize != 0)
UnlockData (0);
return 1;
};
/***************************************************************************
** Function : InitSnapin(void)
** Description :
** Every Snapin DLL must provide this function. In this function,
** snapin menu items (under Tools) are registered. Also, object procs
** are registered.
*/
int _export FAR PASCAL InitSnapin()
{
nuint16 ShowSchemaForm=0;
BWCCRegister(hDLL);
/*-----------------------------------------------------------------------
** Registering Menu Item
*/
NWARegisterMenu(
/* View Name */ NWA_VIEW_BROWSER,
/* Menu Parent ID */ 0,
/* Menu Parent */ NULL,
/* Menu Option */ MF_STRING,
/* Menu ID */ &ShowSchemaForm,
/* Menu String */ "&Modify Schema",
/* Menu Hint */ "Add Schema Definitions",
/* Menu Act. Proc */ ModSchemaMenuAction,
/* Menu Valic Prc */ ModSchemaMenuValid,
/* Snapin Version */ NWA_SNAPIN_VERSION
);
return NWA_RET_SUCCESS;
}
/******************************************************************************
** Function : ViewSchemaMenuAction(void)
** Description :
** Menu Action Callback Proc for ViewSchemaAction
*/
N_GLOBAL_LIBRARY( void ) _export
ModSchemaMenuAction( void )
{
HWND hwnd;
MSG msg;
static FARPROC lpfnModSchemaDlgProc;
lpfnModSchemaDlgProc = MakeProcInstance((FARPROC)ModSchemaDlgProc, hDLL);
DialogBox(hDLL, "MODSCMA", GetActiveWindow(), lpfnModSchemaDlgProc);
FreeProcInstance(lpfnModSchemaDlgProc);
}
/*******************************************************************************
** Function : ViewSchemaMenuValid(void)
** Description :
** Menu Valid Callback Proc for Menu
*/
N_GLOBAL_LIBRARY( void ) _export
ModSchemaMenuValid( pnuint16 pFlags )
{
*pFlags=MF_ENABLED;
}
BOOL FAR PASCAL _export ModSchemaDlgProc(HWND hDlg, UINT message, UINT wParam,
LONG lParam)
{
WORD n;
char attrDefName[50];
char flagName[40];
long rval;
switch(message)
{
case WM_INITDIALOG:
ReadClassInfo(hDlg);
ReadAttributeInfo(hDlg);
ReadClassFlagInfo(hDlg);
ReadAttrFlagInfo(hDlg);
ReadSyntaxInfo(hDlg);
SetFocus(GetDlgItem(hDlg, NEW_CLASS));
return FALSE;
case WM_SYSCOMMAND:
if (wParam == SC_CLOSE)
{
EndDialog(hDlg, TRUE);
return TRUE;
}
case WM_COMMAND:
switch(wParam)
{
case SUPER_CLASS:
break;
case NAME_ATTR:
if (HIWORD (lParam) == CBN_SELCHANGE)
SetFocus(GetDlgItem(hDlg, SYNTAX));
break;
case SYNTAX:
if (HIWORD (lParam) == CBN_SELCHANGE)
SetFocus(GetDlgItem(hDlg, FLAGS));
break;
case CONTAINMENT:
if (HIWORD (lParam) == CBN_SELCHANGE)
{
n = (WORD) SendDlgItemMessage(hDlg, CONTAINMENT,
CB_GETCURSEL, 0, 0L);
SendDlgItemMessage(hDlg, CONTAINMENT, CB_GETLBTEXT, n,
(LONG) (LPSTR) attrDefName);
if(strcmp(attrDefName, "\0") != 0)
{
rval = SendDlgItemMessage(hDlg, CONTAINMENT_LB, LB_FINDSTRING, -1,
(LONG) (LPSTR) attrDefName);
if (rval == LB_ERR)
{
SendDlgItemMessage(hDlg, CONTAINMENT_LB, LB_ADDSTRING, 0,
(LONG) (LPSTR) attrDefName);
SendDlgItemMessage(hDlg, CONTAINMENT, CB_SETCURSEL, 0, 0);
}
}
}
break;
case MANDATORY_ATTR:
if (HIWORD (lParam) == CBN_SELCHANGE)
{
n = (WORD) SendDlgItemMessage(hDlg, MANDATORY_ATTR,
CB_GETCURSEL, 0, 0L);
SendDlgItemMessage(hDlg, MANDATORY_ATTR, CB_GETLBTEXT, n,
(LONG) (LPSTR) attrDefName);
if(strcmp(attrDefName, "\0") != 0)
{
rval = SendDlgItemMessage(hDlg, MANDATORY_LB, LB_FINDSTRING, -1,
(LONG) (LPSTR) attrDefName);
if (rval == LB_ERR)
{
SendDlgItemMessage(hDlg, MANDATORY_LB, LB_ADDSTRING, 0,
(LONG) (LPSTR) attrDefName);
SendDlgItemMessage(hDlg, MANDATORY_ATTR, CB_SETCURSEL, 0, 0);
}
}
}
break;
case MANDATORY_LB:
if (HIWORD (lParam) == LBN_DBLCLK)
{
n = (WORD) SendDlgItemMessage(hDlg, MANDATORY_LB,
CB_GETCURSEL, 0, 0L);
SendDlgItemMessage(hDlg, MANDATORY_LB, LB_DELETESTRING, n, 0);
}
break;
case OPTIONAL_LB:
if (HIWORD (lParam) == LBN_DBLCLK)
{
n = (WORD) SendDlgItemMessage(hDlg, OPTIONAL_LB,
CB_GETCURSEL, 0, 0L);
SendDlgItemMessage(hDlg, OPTIONAL_LB, LB_DELETESTRING, n, 0);
}
break;
case CONTAINMENT_LB:
if (HIWORD (lParam) == LBN_DBLCLK)
{
n = (WORD) SendDlgItemMessage(hDlg, CONTAINMENT_LB,
CB_GETCURSEL, 0, 0L);
SendDlgItemMessage(hDlg, CONTAINMENT_LB, LB_DELETESTRING, n, 0);
}
break;
case CLASS_LB:
if (HIWORD (lParam) == LBN_DBLCLK)
{
n = (WORD) SendDlgItemMessage(hDlg, CLASS_LB,
CB_GETCURSEL, 0, 0L);
SendDlgItemMessage(hDlg, CLASS_LB, LB_DELETESTRING, n, 0);
}
break;
case FLAGS_LB:
if (HIWORD (lParam) == LBN_DBLCLK)
{
n = (WORD) SendDlgItemMessage(hDlg, FLAGS_LB,
CB_GETCURSEL, 0, 0L);
SendDlgItemMessage(hDlg, FLAGS_LB, LB_DELETESTRING, n, 0);
}
break;
case OPTIONAL_ATTR:
if (HIWORD (lParam) == CBN_SELCHANGE)
{
n = (WORD) SendDlgItemMessage(hDlg, OPTIONAL_ATTR,
CB_GETCURSEL, 0, 0L);
SendDlgItemMessage(hDlg, OPTIONAL_ATTR, CB_GETLBTEXT, n,
(LONG) (LPSTR) attrDefName);
if(strcmp(attrDefName, "\0") != 0)
{
rval = SendDlgItemMessage(hDlg, OPTIONAL_LB, LB_FINDSTRING, -1,
(LONG) (LPSTR) attrDefName);
if (rval == LB_ERR)
{
SendDlgItemMessage(hDlg, OPTIONAL_LB, LB_ADDSTRING, 0,
(LONG) (LPSTR) attrDefName);
SendDlgItemMessage(hDlg, OPTIONAL_ATTR, CB_SETCURSEL, 0, 0);
}
}
}
break;
case CREATE_CLASS:
CreateClass(hDlg);
break;
case CREATE_ATTR:
CreateAttribute(hDlg);
break;
case MODIFY_CLASS:
ModifyClass(hDlg);
break;
case REMOVE_ATTR:
RemoveAttributeDefinition(hDlg);
break;
case REMOVE_CLASS:
RemoveClassDefinition(hDlg);
break;
case CLASS_FLAGS:
if (HIWORD (lParam) == CBN_SELCHANGE)
{
n = (WORD) SendDlgItemMessage(hDlg, CLASS_FLAGS,
CB_GETCURSEL, 0, 0L);
SendDlgItemMessage(hDlg, CLASS_FLAGS, CB_GETLBTEXT, n,
(LONG) (LPSTR) flagName);
if(strcmp(flagName, "\0") != 0)
{
rval = SendDlgItemMessage(hDlg, CLASS_LB, LB_FINDSTRING, -1,
(LONG) (LPSTR) flagName);
if (rval == LB_ERR)
{
SendDlgItemMessage(hDlg, CLASS_LB, LB_ADDSTRING, 0,
(LONG) (LPSTR) flagName);
SendDlgItemMessage(hDlg, CLASS_FLAGS, CB_SETCURSEL, 0, 0);
}
}
}
break;
case FLAGS:
if (HIWORD (lParam) == CBN_SELCHANGE)
{
n = (WORD) SendDlgItemMessage(hDlg, FLAGS,
CB_GETCURSEL, 0, 0L);
SendDlgItemMessage(hDlg, FLAGS, CB_GETLBTEXT, n,
(LONG) (LPSTR) flagName);
if(strcmp(flagName, "\0") != 0)
{
rval = SendDlgItemMessage(hDlg, FLAGS_LB, LB_FINDSTRING, -1,
(LONG) (LPSTR) flagName);
if (rval == LB_ERR)
{
SendDlgItemMessage(hDlg, FLAGS_LB, LB_ADDSTRING, 0,
(LONG) (LPSTR) flagName);
SendDlgItemMessage(hDlg, FLAGS, CB_SETCURSEL, 0, 0);
}
}
}
break;
}
break;
}
return FALSE;
}
WORD ReadClassInfo(HWND hDlg)
{
NWDSContextHandle dContext;
NWDS_ITERATION iterHandle = -1L;
NWDS_BUFFER *outBuf;
Class_Info_T classInfo;
NWDSCCODE cCode;
NWCOUNT classDefCount /* classItemCount */;
char classDefName[MAX_SCHEMA_NAME_BYTES];
int i;
dContext = NWDSCreateContext();
if (dContext == ERR_CONTEXT_CREATION)
{
NWDSFreeContext(dContext);
return(dContext);
}
cCode = NWDSAllocBuf(
/* Buffer Size */ DEFAULT_MESSAGE_LEN,
/* Buff. Point.*/ &outBuf
);
if (cCode < 0)
{
NWDSFreeContext(dContext);
return(cCode);
}
do
{
cCode = NWDSReadClassDef(
/* Contxt Handle */ dContext,
/* Info Type */ DS_CLASS_DEF_NAMES,
/* All classes ? */ TRUE,
/* Class Names */ NULL,
/* Iter handle */ &iterHandle,
/* Result Buf */ outBuf
);
if (cCode < 0)
{
NWDSFreeContext(dContext);
NWDSFreeBuf(outBuf);
return(cCode);
}
cCode = NWDSGetClassDefCount(
/* Contxt Handle */ dContext,
/* Result buffer */ outBuf,
/* Class Def count*/ &classDefCount
);
if (cCode < 0)
{
NWDSFreeContext(dContext);
NWDSFreeBuf(outBuf);
return(cCode);
}
for (i = 0; i < (int)classDefCount; ++i)
{
cCode = NWDSGetClassDef(
/* Contxt Handle */ dContext,
/* Result Buffer */ outBuf,
/* Item Name */ classDefName,
/* Class info */ &classInfo
);
if (cCode < 0)
{
NWDSFreeContext(dContext);
NWDSFreeBuf(outBuf);
return(cCode);
}
SendDlgItemMessage(hDlg, SUPER_CLASS, CB_ADDSTRING, 0,
(LONG) (LPSTR) classDefName);
SendDlgItemMessage(hDlg, CONTAINMENT, CB_ADDSTRING, 0,
(LONG) (LPSTR) classDefName);
SendDlgItemMessage(hDlg, NEW_CLASS, CB_ADDSTRING, 0,
(LONG) (LPSTR) classDefName);
}
} while(iterHandle != -1L);
SendDlgItemMessage(hDlg, CONTAINMENT, CB_ADDSTRING, 0,
(LONG) "\0 ");
SendDlgItemMessage(hDlg, SUPER_CLASS, CB_ADDSTRING, 0,
(LONG) "\0 ");
NWDSFreeContext(dContext);
NWDSFreeBuf(outBuf);
return FALSE;
}
ReadAttributeInfo(HWND hDlg)
{
NWDSContextHandle dContext;
NWDS_ITERATION iterHandle = -1L;
NWDS_BUFFER *outBuf;
NWDSCCODE cCode;
NWCOUNT attrCount;
Attr_Info_T attributeInfo;
char attrName[MAX_SCHEMA_NAME_CHARS];
int i;
dContext = NWDSCreateContext();
if (dContext == ERR_CONTEXT_CREATION)
{
NWDSFreeContext(dContext);
return(dContext);
}
cCode = NWDSAllocBuf(
/* Buffer Size */ DEFAULT_MESSAGE_LEN,
/* Buff. Point.*/ &outBuf
);
if (cCode < 0)
{
NWDSFreeContext(dContext);
return(cCode);
}
do
{
cCode = NWDSReadAttrDef(
/* Contxt Handle */ dContext,
/* Info Type */ DS_ATTR_DEFS,
/* All classes ? */ TRUE,
/* Class Names */ NULL,
/* Iter handle */ &iterHandle,
/* Result Buf */ outBuf
);
if (cCode < 0)
{
NWDSFreeContext(dContext);
NWDSFreeBuf(outBuf);
return(cCode);
}
cCode = NWDSGetAttrCount(
/* Contxt Handle */ dContext,
/* Result buffer */ outBuf,
/* Class Def count*/ &attrCount
);
if (cCode < 0)
{
NWDSFreeContext(dContext);
NWDSFreeBuf(outBuf);
return(cCode);
}
for (i = 0; i < (int)attrCount; ++i)
{
cCode = NWDSGetAttrDef(
/* Contxt Handle */ dContext,
/* Result Buffer */ outBuf,
/* Item Name */ attrName,
/* Class info */ &attributeInfo
);
if (cCode < 0)
{
NWDSFreeContext(dContext);
NWDSFreeBuf(outBuf);
return(cCode);
}
SendDlgItemMessage(hDlg, MANDATORY_ATTR, CB_ADDSTRING, 0,
(LONG) (LPSTR) attrName);
SendDlgItemMessage(hDlg, OPTIONAL_ATTR, CB_ADDSTRING, 0,
(LONG) (LPSTR) attrName);
SendDlgItemMessage(hDlg, NAME_ATTR, CB_ADDSTRING, 0,
(LONG) (LPSTR) attrName);
SendDlgItemMessage(hDlg, ATTR_NAME, CB_ADDSTRING, 0,
(LONG) (LPSTR) attrName);
}
} while(iterHandle != -1L);
SendDlgItemMessage(hDlg, MANDATORY_ATTR, CB_ADDSTRING, 0,
(LONG) "\0 ");
SendDlgItemMessage(hDlg, OPTIONAL_ATTR, CB_ADDSTRING, 0,
(LONG) "\0");
SendDlgItemMessage(hDlg, NAME_ATTR, CB_ADDSTRING, 0,
(LONG) "\0 ");
NWDSFreeContext(dContext);
NWDSFreeBuf(outBuf);
return FALSE;
}
WORD ReadClassFlagInfo(HWND hDlg)
{
int i;
for (i=0; i < 5; ++i)
{
SendDlgItemMessage(hDlg, CLASS_FLAGS, CB_ADDSTRING, 0,
(LONG) (LPSTR) classFlagsInfo[i].szLabel);
}
SendDlgItemMessage(hDlg, CLASS_FLAGS, CB_ADDSTRING, 0,
(LONG) "\0 ");
return TRUE;
}
WORD ReadAttrFlagInfo(HWND hDlg)
{
int i;
for (i=0; i < 11; ++i)
{
SendDlgItemMessage(hDlg, FLAGS, CB_ADDSTRING, 0,
(LONG) (LPSTR) attrFlagsInfo[i].szLabel);
}
SendDlgItemMessage(hDlg, FLAGS, CB_ADDSTRING, 0,
(LONG) " \0");
return TRUE;
}
WORD ReadSyntaxInfo(HWND hDlg)
{
int i;
for (i=0; i < 29; ++i)
{
SendDlgItemMessage(hDlg, SYNTAX, CB_ADDSTRING, 0,
(LONG) (LPSTR) syntaxInfo[i].szLabel);
}
SendDlgItemMessage(hDlg, SYNTAX, CB_ADDSTRING, 0,
(LONG) "\0 ");
return TRUE;
}
WORD CreateClass(HWND hDlg)
{
NWDSContextHandle dContext;
char className[MAX_DN_CHARS];
char superClassName[MAX_DN_CHARS];
char namingAttr[MAX_DN_CHARS];
char containment[MAX_DN_CHARS];
char optionalAttr[MAX_DN_CHARS];
char mandatoryAttr[MAX_DN_CHARS];
char flagLabel[50];
char tempBuf[1024];
NWDS_BUFFER *classBuf;
NWDSCCODE cCode;
WORD n = MAX_DN_CHARS;
long rval;
DWORD mandatoryCnt = 0 ;
DWORD optionalCnt = 0;
int i, j;
int containCnt = 0, name = 0;
Class_Info_T classInfo;
memset(&classInfo, (int) '\0', sizeof(Class_Info_T));
rval = SendDlgItemMessage(hDlg, NEW_CLASS, WM_GETTEXT, n,
(LONG) (LPSTR) className);
if ((rval == CB_ERR) || (rval == 0))
{
sprintf(tempBuf, "You must enter a Class Name \n in the Class Name field!");
MessageBox(NULL, tempBuf, "No Class Specified ", MB_ICONSTOP);
return FALSE;
}
rval = SendDlgItemMessage(hDlg, SUPER_CLASS, WM_GETTEXT, n,
(LONG) (LPSTR) superClassName);
if ((rval == CB_ERR) || (rval == 0))
{
sprintf(tempBuf, "You must select a Super Class \n in the Super Class field!");
MessageBox(NULL, tempBuf, "No Super Class Selected", MB_ICONSTOP);
return FALSE;
}
rval = SendDlgItemMessage(hDlg, NAME_ATTR, WM_GETTEXT, n,
(LONG) (LPSTR) namingAttr);
if ((rval == CB_ERR) || (rval == 0))
name = 1;
rval = SendDlgItemMessage(hDlg, CONTAINMENT_LB, LB_GETCOUNT, 0, 0);
if ((rval > 0) && (rval != LB_ERR))
containCnt = rval;
rval = SendDlgItemMessage(hDlg, CLASS_LB, LB_GETCOUNT, 0, 0);
if ((rval == 0) || (rval == LB_ERR))
{
sprintf(tempBuf, "You must select Class Flag(s)!");
MessageBox(NULL, tempBuf, "No Class Flag(s) Selected", MB_ICONSTOP);
return FALSE;
}
classInfo.classFlags = 0x00;
for(i=0; i < rval; ++i)
{
SendDlgItemMessage(hDlg, CLASS_LB, LB_GETTEXT, i,
(LONG) (LPSTR) flagLabel);
for(j=0; j < 5; ++j)
{
if(strcmp(flagLabel, classFlagsInfo[j].szLabel) == 0)
classInfo.classFlags |= classFlagsInfo[j].classFlag;
}
}
rval = SendDlgItemMessage(hDlg, MANDATORY_LB, LB_GETCOUNT, 0, 0);
if ((rval > 0) && (rval != LB_ERR))
mandatoryCnt = rval;
rval = SendDlgItemMessage(hDlg, OPTIONAL_LB, LB_GETCOUNT, 0, 0);
if ((rval > 0) && (rval != LB_ERR))
optionalCnt = rval;
dContext = NWDSCreateContext();
if (dContext == ERR_CONTEXT_CREATION)
{
NWDSFreeContext(dContext);
return(dContext);
}
cCode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN, &classBuf);
if( cCode < 0 )
{
sprintf(tempBuf, "\nNWDSAllocBuf returned %04X", cCode);
MessageBox(NULL, tempBuf, "NWDSAllocBuf() Failed", MB_ICONSTOP);
NWDSFreeContext(dContext);
return FALSE;
}
cCode = NWDSInitBuf(dContext, DSV_DEFINE_CLASS, classBuf);
if( cCode < 0 )
{
sprintf(tempBuf, "\nNWDSInitBuf returned %04X", cCode);
MessageBox(NULL, tempBuf, "NWDSInitBuf Failed!", MB_ICONSTOP);
NWDSFreeContext(dContext);
NWDSFreeBuf(classBuf);
return FALSE;
}
/*----------------------------------------------------------------
** entries for super class names
*/
cCode = NWDSBeginClassItem(dContext, classBuf);
if( cCode < 0 )
{
sprintf(tempBuf, "\nNWDSBeginClasss returned %04X", cCode);
MessageBox(NULL, tempBuf, "NWDSBeginClass Failed!", MB_ICONSTOP);
NWDSFreeContext(dContext);
NWDSFreeBuf(classBuf);
return FALSE;
}
cCode = NWDSPutClassItem(dContext, classBuf, superClassName);
if( cCode < 0 )
{
sprintf(tempBuf, "\nNWDSPutClassItem returned %04X", cCode);
MessageBox(NULL, tempBuf, "NWDSPutClassItem Failed!", MB_ICONSTOP);
NWDSFreeContext(dContext);
NWDSFreeBuf(classBuf);
return FALSE;
}
/*----------------------------------------------------------------
** entries for containment class names; which are none
*/
cCode = NWDSBeginClassItem(dContext, classBuf);
if( cCode < 0 )
{
sprintf(tempBuf, "\nNWDSBeginClass returned %04X", cCode);
MessageBox(NULL, tempBuf, "NWDSBeginClass Failed!", MB_ICONSTOP);
NWDSFreeContext(dContext);
NWDSFreeBuf(classBuf);
return FALSE;
}
if (containCnt > 0)
{
for(i=0; i < containCnt; ++ i)
{
SendDlgItemMessage(hDlg, CONTAINMENT_LB, LB_GETTEXT, i,
(LONG) (LPSTR) containment);
cCode = NWDSPutClassItem(dContext, classBuf, containment);
if( cCode < 0 )
{
sprintf(tempBuf, "\nNWDSPutClassItem returned %04X", cCode);
MessageBox(NULL, tempBuf, "NWDSPutClassItem Failed!", MB_ICONSTOP);
NWDSFreeContext(dContext);
NWDSFreeBuf(classBuf);
return FALSE;
}
}
}
/*----------------------------------------------------------------
** entries for naming attribute names; same as Server
*/
cCode = NWDSBeginClassItem(dContext, classBuf);
if( cCode < 0 )
{
sprintf(tempBuf, "\nNWDSBeginClass returned %04X", cCode);
MessageBox(NULL, tempBuf, "NWDSBeginClass Failed!", MB_ICONSTOP);
NWDSFreeContext(dContext);
NWDSFreeBuf(classBuf);
return FALSE;
}
if (!name)
{
cCode = NWDSPutClassItem(dContext, classBuf, namingAttr);
if( cCode < 0 )
{
sprintf(tempBuf, "\nNWDSPutClassItem returned %04X", cCode);
MessageBox(NULL, tempBuf, "NWDSPutClassItem Failed!", MB_ICONSTOP);
NWDSFreeContext(dContext);
NWDSFreeBuf(classBuf);
return FALSE;
}
}
/*----------------------------------------------------------------
** entries for mandatory attribute names; same as Server
*/
cCode = NWDSBeginClassItem(dContext, classBuf);
if( cCode < 0 )
{
sprintf(tempBuf, "\nNWDSBeginClass returned %04X", cCode);
MessageBox(NULL, tempBuf, "NWDSBeginClass Failed!", MB_ICONSTOP);
NWDSFreeContext(dContext);
NWDSFreeBuf(classBuf);
return FALSE;
}
if (mandatoryCnt > 0)
{
for(i=0; i < mandatoryCnt; ++ i)
{
SendDlgItemMessage(hDlg, MANDATORY_LB, LB_GETTEXT, i,
(LONG) (LPSTR) mandatoryAttr);
cCode = NWDSPutClassItem(dContext, classBuf, mandatoryAttr);
if( cCode < 0 )
{
sprintf(tempBuf, "\nNWDSPutClassItem returned %04X", cCode);
MessageBox(NULL, tempBuf, "NWDSPutClassItem Failed!", MB_ICONSTOP);
NWDSFreeContext(dContext);
NWDSFreeBuf(classBuf);
return FALSE;
}
}
}
/*----------------------------------------------------------------
** entries for optional attribute names; same as server for now.
*/
cCode = NWDSBeginClassItem(dContext, classBuf);
if( cCode < 0 )
{
sprintf(tempBuf, "\nNWDSBeginClass returned %04X", cCode);
MessageBox(NULL, tempBuf, "NWDSBeginClass Failed!", MB_ICONSTOP);
NWDSFreeContext(dContext);
NWDSFreeBuf(classBuf);
return FALSE;
}
if (optionalCnt > 0)
{
for(i=0; i < optionalCnt; ++ i)
{
SendDlgItemMessage(hDlg, OPTIONAL_LB, LB_GETTEXT, i,
(LONG) (LPSTR) optionalAttr);
cCode = NWDSPutClassItem(dContext, classBuf, optionalAttr);
if( cCode < 0 )
{
sprintf(tempBuf, "\nNWDSPutClassItem returned %04X", cCode);
MessageBox(NULL, tempBuf, "NWDSPutClassItem Failed!", MB_ICONSTOP);
NWDSFreeContext(dContext);
NWDSFreeBuf(classBuf);
return FALSE;
}
}
}
cCode = NWDSDefineClass(dContext, className, &classInfo, classBuf);
if( cCode < 0 )
{
sprintf(tempBuf, "\nNWDSDefineClass returned %04X", cCode);
MessageBox(NULL, tempBuf, "NWDSDefineClass Failed!", MB_ICONSTOP);
NWDSFreeContext(dContext);
NWDSFreeBuf(classBuf);
}
else
{
sprintf(tempBuf, "Class %s successfully added!", className);
MessageBox(NULL, tempBuf, "Successfully added!", MB_OK);
}
ClassClear(hDlg);
ClassResetComboBoxes(hDlg);
ReadClassInfo(hDlg);
NWDSFreeBuf(classBuf);
NWDSFreeContext(dContext);
return TRUE;
}
WORD RemoveClassDefinition(HWND hDlg)
{
WORD n = MAX_DN_CHARS;
long rval;
char className[MAX_DN_CHARS];
char tempBuf[1024];
NWDSContextHandle dContext;
NWDSCCODE cCode;
dContext = NWDSCreateContext();
if (dContext == ERR_CONTEXT_CREATION)
{
NWDSFreeContext(dContext);
return(dContext);
}
rval = SendDlgItemMessage(hDlg, NEW_CLASS, WM_GETTEXT, n,
(LONG) (LPSTR) className);
if ((rval == CB_ERR) || (rval == 0))
{
sprintf(tempBuf, "You must enter a Class Name \n in the Class Name field!");
MessageBox(NULL, tempBuf, "No Class Specified ", MB_ICONSTOP);
NWDSFreeContext(dContext);
return FALSE;
}
cCode = NWDSRemoveClassDef(
/* Context Handle */ dContext,
/* Class Name */ className
);
if (cCode < 0)
{
sprintf(tempBuf, "NWDSRemoveClassDef() returned %04X\n\
Remember that clients cannot subtract\n\
from the standard set of class\n\
definitions defined by the directory.\n\
If an instance of this class\n\
exists the class definition cannot\n\
be removed util all objects of this\n\
class are deleted.", cCode);
MessageBox(NULL, tempBuf, "Remove Class Failed!", MB_ICONSTOP);
NWDSFreeContext(dContext);
return FALSE;
}
else
{
sprintf(tempBuf, "Class %s successfully removed!", className);
MessageBox(NULL, tempBuf, "Successfully removed!", MB_OK);
}
ClassClear(hDlg);
ClassResetComboBoxes(hDlg);
ReadClassInfo(hDlg);
NWDSFreeContext(dContext);
return TRUE;
}
WORD RemoveAttributeDefinition(HWND hDlg)
{
WORD n = MAX_DN_CHARS;
long rval;
char attrName[MAX_DN_CHARS];
char tempBuf[1024];
NWDSContextHandle dContext;
NWDSCCODE cCode;
rval = SendDlgItemMessage(hDlg, ATTR_NAME, WM_GETTEXT, n,
(LONG) (LPSTR) attrName);
if ((rval == CB_ERR) || (rval == 0))
{
sprintf(tempBuf, "You must enter an Attribute \n name in the Attribute Name field!");
MessageBox(NULL, tempBuf, "No Attribute Specified ", MB_ICONSTOP);
return FALSE;
}
dContext = NWDSCreateContext();
if (dContext == ERR_CONTEXT_CREATION)
{
NWDSFreeContext(dContext);
return(dContext);
}
cCode = NWDSRemoveAttrDef(
/* Context Handle */ dContext,
/* Class Name */ attrName
);
if (cCode < 0)
{
sprintf(tempBuf, "NWDSRemoveAttrDef() returned %04X\n\
Remember that clients cannot subtract\n\
from the standard set of attribute\n\
definitions defined by the directory.\n\
If this attribute is in use by an existing\n\
class this attribute cannot be removed!", cCode);
MessageBox(NULL, tempBuf, "Remove Attribute Failed!", MB_ICONSTOP);
NWDSFreeContext(dContext);
return FALSE;
}
else
{
sprintf(tempBuf, "Attribute %s successfully removed!", attrName);
MessageBox(NULL, tempBuf, "Successfully removed!", MB_OK);
}
AttrClear(hDlg);
AttrResetComboBoxes(hDlg);
ReadAttributeInfo(hDlg);
NWDSFreeContext(dContext);
return TRUE;
}
WORD ModifyClass(HWND hDlg)
{
NWDSContextHandle dContext;
char className[MAX_DN_CHARS];
char optionalAttr[MAX_DN_CHARS];
char tempBuf[1024];
NWDSCCODE cCode;
WORD n = MAX_DN_CHARS;
long optionalCnt = 0;
Buf_T *classBuf;
long rval;
int i;
rval = SendDlgItemMessage(hDlg, NEW_CLASS, WM_GETTEXT, n,
(LONG) (LPSTR) className);
if ((rval == CB_ERR) || (rval == 0))
{
sprintf(tempBuf, "You must enter a Class Name \n in the Class Name field!");
MessageBox(NULL, tempBuf, "No Class Specified ", MB_ICONSTOP);
return FALSE;
}
rval = SendDlgItemMessage(hDlg, OPTIONAL_LB, LB_GETCOUNT, 0, 0);
if ((rval > 0) && (rval != LB_ERR))
optionalCnt = rval;
else
{
sprintf(tempBuf, "You must select at least \n one optional attribute!");
MessageBox(NULL, tempBuf, "No Optional Attribute Selected ", MB_ICONSTOP);
return FALSE;
}
dContext = NWDSCreateContext();
if (dContext == ERR_CONTEXT_CREATION)
{
NWDSFreeContext(dContext);
return(dContext);
}
cCode = NWDSAllocBuf(
/* Number of Bytes */ DEFAULT_MESSAGE_LEN,
/* PTR NWDS_BUFFER */&classBuf
);
if( cCode < 0 )
{
sprintf(tempBuf, "\nNWDSAllocBuf returned %04X", cCode);
MessageBox(NULL, tempBuf, "NWDSAllocBuf Failed!", MB_ICONSTOP);
NWDSFreeContext(dContext);
return FALSE;
}
cCode = NWDSInitBuf(
/* Context Handle */ dContext,
/* Operation */ DSV_MODIFY_CLASS_DEF,
/* PTR to Buffer */ classBuf
);
if( cCode < 0 )
{
sprintf(tempBuf, "\nNWDSInitBuf returned %04X", cCode);
MessageBox(NULL, tempBuf, "NWDSInitBuf Failed!", MB_ICONSTOP);
NWDSFreeContext(dContext);
NWDSFreeBuf(classBuf);
return FALSE;
}
/*---------------------------------------------------------------
** Add optional attribute(s)
*/
if (optionalCnt > 0)
{
for(i=0; i < optionalCnt; ++ i)
{
SendDlgItemMessage(hDlg, OPTIONAL_LB, LB_GETTEXT, i,
(LONG) (LPSTR) optionalAttr);
cCode = NWDSPutClassItem(dContext, classBuf, optionalAttr);
if( cCode < 0 )
{
sprintf(tempBuf, "\nNWDSPutClassItem returned %04X", cCode);
MessageBox(NULL, tempBuf, "NWDSPutClassItem Failed!", MB_ICONSTOP);
NWDSFreeContext(dContext);
NWDSFreeBuf(classBuf);
return FALSE;
}
}
}
cCode = NWDSModifyClassDef(
/* Context Handle */ dContext,
/* Class Name */ className,
/* Class Buffer */ classBuf
);
if( cCode < 0 )
{
sprintf(tempBuf, "\nNWDSModifyClassDef returned %04X", cCode);
MessageBox(NULL, tempBuf, "NWDSModifyClassDef Failed!", MB_ICONSTOP);
NWDSFreeContext(dContext);
NWDSFreeBuf(classBuf);
return FALSE;
}
else
{
sprintf(tempBuf, "Class %s successfully modified", className);
MessageBox(NULL, tempBuf, "Successfully modified!", MB_OK);
}
ClassClear(hDlg);
ClassResetComboBoxes(hDlg);
ReadClassInfo(hDlg);
NWDSFreeBuf(classBuf);
NWDSFreeContext(dContext);
return TRUE;
}
WORD CreateAttribute(HWND hDlg)
{
char tempBuf[1024];
char flagLabel[50];
char attrName[MAX_DN_CHARS];
char attrBounds[12];
char syntaxField[40];
NWDSCCODE cCode;
NWDSContextHandle dContext;
WORD n = MAX_DN_CHARS;
Attr_Info_T attrInfo;
long rval;
int i, j;
memset(&attrInfo, (int) '\0', sizeof(Attr_Info_T));
rval = SendDlgItemMessage(hDlg, ATTR_NAME, WM_GETTEXT, n,
(LONG) (LPSTR) attrName);
if ((rval == CB_ERR) || (rval == 0))
{
sprintf(tempBuf, "You must enter an Attribute \n name in the Attribute Name field!");
MessageBox(NULL, tempBuf, "No Attribute Specified ", MB_ICONSTOP);
return FALSE;
}
rval = SendDlgItemMessage(hDlg, SYNTAX, WM_GETTEXT, n,
(LONG) (LPSTR) syntaxField);
if ((rval == CB_ERR) || (rval == 0))
{
sprintf(tempBuf, "You must select a Syntax \n in the Syntax field!");
MessageBox(NULL, tempBuf, "No Syntax Selected!", MB_ICONSTOP);
return FALSE;
}
rval = SendDlgItemMessage(hDlg, FLAGS_LB, LB_GETCOUNT, 0, 0);
if ((rval != 0) && (rval != LB_ERR))
{
for(i=0; i < rval; ++i)
{
SendDlgItemMessage(hDlg, FLAGS_LB, LB_GETTEXT, i,
(LONG) (LPSTR) flagLabel);
for(j=0; j < 11; ++j)
{
if(strcmp(flagLabel, attrFlagsInfo[j].szLabel) == 0)
attrInfo.attrFlags |= attrFlagsInfo[j].attrFlag;
}
}
}
else
attrInfo.attrFlags = 0;
rval = SendDlgItemMessage(hDlg, ATTR_UPPER, WM_GETTEXT, 10,
(LONG) (LPSTR) attrBounds);
if((rval > 0) && (rval != LB_ERR))
attrInfo.attrUpper = atol(attrBounds);
rval = SendDlgItemMessage(hDlg, ATTR_LOWER, WM_GETTEXT, 10,
(LONG) (LPSTR) attrBounds);
if((rval > 0) && (rval != LB_ERR))
attrInfo.attrLower = atol(attrBounds);
for(j=0; j < 29; ++j)
{
if(strcmp(syntaxField, syntaxInfo[j].szLabel) == 0)
attrInfo.attrSyntaxID = syntaxInfo[j].syntaxID;
}
dContext = NWDSCreateContext();
if (dContext == ERR_CONTEXT_CREATION)
{
NWDSFreeContext(dContext);
return(dContext);
}
cCode = NWDSDefineAttr(dContext, attrName, &attrInfo);
if( cCode < 0 )
{
sprintf(tempBuf, "\nNWDSDefineAttr() returned %04X", cCode);
MessageBox(NULL, tempBuf, "NWDSDefineAttr() Failed!", MB_ICONSTOP);
NWDSFreeContext(dContext);
return FALSE;
}
else
{
sprintf(tempBuf, "Attribute %s successfully added!", attrName);
MessageBox(NULL, tempBuf, "Successfully Added!", MB_OK);
}
AttrClear(hDlg);
AttrResetComboBoxes(hDlg);
ReadAttributeInfo(hDlg);
SendDlgItemMessage(hDlg, ATTR_LOWER, WM_SETTEXT, 0, (LONG) "\0");
SendDlgItemMessage(hDlg, ATTR_UPPER, WM_SETTEXT, 0, (LONG) "\0");
NWDSFreeContext(dContext);
return TRUE;
}
AttrClear(HWND hDlg)
{
SendDlgItemMessage(hDlg, ATTR_NAME, WM_SETTEXT, 0, (LONG) "\0");
SendDlgItemMessage(hDlg, SYNTAX, CB_SETCURSEL, 0, 0);
SendDlgItemMessage(hDlg, FLAGS, WM_SETTEXT, 0, (LONG) "\0");
SendDlgItemMessage(hDlg, FLAGS_LB, LB_RESETCONTENT, 0, 0);
}
ClassClear(HWND hDlg)
{
SendDlgItemMessage(hDlg, NEW_CLASS, WM_SETTEXT, 0, (LONG) "\0");
SendDlgItemMessage(hDlg, SUPER_CLASS, CB_SETCURSEL, 0, 0);
SendDlgItemMessage(hDlg, NAME_ATTR, CB_SETCURSEL, 0, 0);
SendDlgItemMessage(hDlg, CLASS_FLAGS, CB_SETCURSEL, 0, 0);
SendDlgItemMessage(hDlg, CLASS_LB, LB_RESETCONTENT, 0, 0);
SendDlgItemMessage(hDlg, CONTAINMENT, CB_SETCURSEL, 0, 0);
SendDlgItemMessage(hDlg, CONTAINMENT_LB, LB_RESETCONTENT, 0, 0);
SendDlgItemMessage(hDlg, OPTIONAL_ATTR, CB_SETCURSEL, 0, 0);
SendDlgItemMessage(hDlg, OPTIONAL_LB, LB_RESETCONTENT, 0, 0);
SendDlgItemMessage(hDlg, MANDATORY_ATTR, CB_SETCURSEL, 0, 0);
SendDlgItemMessage(hDlg, MANDATORY_LB, LB_RESETCONTENT, 0, 0);
}
AttrResetComboBoxes(HWND hDlg)
{
SendDlgItemMessage(hDlg, ATTR_NAME, CB_RESETCONTENT, 0, 0);
SendDlgItemMessage(hDlg, NAME_ATTR, CB_RESETCONTENT, 0, 0);
SendDlgItemMessage(hDlg, MANDATORY_ATTR, CB_RESETCONTENT, 0, 0);
SendDlgItemMessage(hDlg, OPTIONAL_ATTR, CB_RESETCONTENT, 0, 0);
}
ClassResetComboBoxes(HWND hDlg)
{
SendDlgItemMessage(hDlg, NEW_CLASS, CB_RESETCONTENT, 0, 0);
SendDlgItemMessage(hDlg, SUPER_CLASS, CB_RESETCONTENT, 0, 0);
SendDlgItemMessage(hDlg, CONTAINMENT, CB_RESETCONTENT, 0, 0);
}