home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Encyclopedia 96-1
/
novell-nsepro-1996-1-cd2.iso
/
download
/
netware
/
snapx2.exe
/
VWSCMA.EXE
/
VIEWSCMA.C
next >
Wrap
Text File
|
1995-01-04
|
20KB
|
884 lines
/****************************************************************************
** File: VIEWSCMA.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
** -----------------------------------------------------------------------
** 10-13-94 klb First code.
*/
/****************************************************************************
** Include headers, macros, function prototypes, etc.
*/
/*------------------------------------------------------------------------
** ANSI
*/
#include <windows.h>
#include <toolhelp.h>
#include <string.h>
#include <stdio.h>
/*------------------------------------------------------------------------
** NetWare
*/
#include <nwnet.h>
#include <nwsnapin.h>
#include "viewscma.h"
/*------------------------------------------------------------------------
** Prototypes
*/
#ifdef __cplusplus
extern "C"
{
#endif
BOOL FAR PASCAL _export ViewSchemaDlgProc(HWND hDlg, UINT message, UINT wParam,
LONG lParam);
BOOL FAR PASCAL _export ViewAttrInfoDlgProc(HWND hDlg, UINT message, UINT wParam,
LONG lParam);
N_EXTERN_LIBRARY( void ) ViewSchemaMenuAction(void);
N_EXTERN_LIBRARY( void ) ViewSchemaMenuValid(pnuint16 pFlags);
WORD UpdateClassDlgBoxes(HWND hDlg);
WORD InitClassDefListBox(HWND hDlg);
OpenAttrInfoDlgBox(HWND hDlg, int SOURCE_DLG);
ReadAttributeInfo(NWATTR_INFO *attrInfo);
ReadAllAttributes(HWND hDlg);
UpdateClassFlags(HWND hDlg, Class_Info_T *classInfo);
#ifdef __cplusplus
}
#endif
/*------------------------------------------------------------------------
** Globals
*/
HINSTANCE hDLL;
char attrNameBuf[MAX_SCHEMA_NAME_BYTES];
char classNameBuf[MAX_SCHEMA_NAME_BYTES];
int superClassFlag = 0;
int updateFlag = 0;
int topFlag = 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;
/*-----------------------------------------------------------------------
** 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 */ "&View Schema",
/* Menu Hint */ "View Schema Definitions",
/* Menu Act. Proc */ ViewSchemaMenuAction,
/* Menu Valic Prc */ ViewSchemaMenuValid,
/* Snapin Version */ NWA_SNAPIN_VERSION
);
return NWA_RET_SUCCESS;
}
/******************************************************************************
** Function : ViewSchemaMenuAction(void)
** Description :
** Menu Action Callback Proc for ViewSchemaAction
*/
N_GLOBAL_LIBRARY( void ) _export
ViewSchemaMenuAction( void )
{
HWND hwnd;
MSG msg;
static FARPROC lpfnViewSchemaDlgProc;
lpfnViewSchemaDlgProc = MakeProcInstance((FARPROC)ViewSchemaDlgProc, hDLL);
DialogBox(hDLL, "VIEW_SCMA", GetActiveWindow(), lpfnViewSchemaDlgProc);
FreeProcInstance(lpfnViewSchemaDlgProc);
}
/*******************************************************************************
** Function : ViewSchemaMenuValid(void)
** Description :
** Menu Valid Callback Proc for Menu
*/
N_GLOBAL_LIBRARY( void ) _export
ViewSchemaMenuValid( pnuint16 pFlags )
{
*pFlags=MF_ENABLED;
}
BOOL FAR PASCAL _export ViewSchemaDlgProc(HWND hDlg, UINT message, UINT wParam,
LONG lParam)
{
WORD n;
switch(message)
{
case WM_INITDIALOG:
InitClassDefListBox(hDlg);
ReadAllAttributes(hDlg);
SetFocus(GetDlgItem(hDlg, CLASS_NAMES));
return FALSE;
case WM_COMMAND:
switch(wParam)
{
case EXIT_DLG:
EndDialog(hDlg, TRUE);
return TRUE;
case CLASS_NAMES:
if (HIWORD (lParam) == LBN_SELCHANGE)
{
n = (WORD) SendDlgItemMessage(hDlg, CLASS_NAMES,
LB_GETCURSEL, 0, 0L);
SendDlgItemMessage(hDlg, CLASS_NAMES, LB_GETTEXT, n,
(LONG) (LPSTR) classNameBuf);
superClassFlag = 0;
UpdateClassDlgBoxes(hDlg);
}
break;
case ATTR_NAMES:
if (HIWORD (lParam) == LBN_DBLCLK)
OpenAttrInfoDlgBox(hDlg, ATTR_NAMES);
break;
case MANDATORY_ATT:
if (HIWORD (lParam) == LBN_SELCHANGE)
OpenAttrInfoDlgBox(hDlg, MANDATORY_ATT);
break;
case OPTIONAL_ATT:
if (HIWORD (lParam) == LBN_SELCHANGE)
OpenAttrInfoDlgBox(hDlg, OPTIONAL_ATT);
break;
case SUPER_CLASSES:
if (HIWORD (lParam) == LBN_DBLCLK)
{
n = (WORD) SendDlgItemMessage(hDlg, SUPER_CLASSES,
LB_GETCURSEL, 0, 0L);
SendDlgItemMessage(hDlg, SUPER_CLASSES, LB_GETTEXT, n,
(LONG) (LPSTR) classNameBuf);
topFlag = 0;
updateFlag = 0;
superClassFlag = 1;
UpdateClassDlgBoxes(hDlg);
}
break;
}
break;
}
return FALSE;
}
OpenAttrInfoDlgBox(HWND hDlg, int SOURCE_DLG)
{
static FARPROC lpfnViewAttrInfoDlgProc;
WORD n;
memset(attrNameBuf, 0, sizeof(attrNameBuf));
n = (WORD) SendDlgItemMessage(hDlg, SOURCE_DLG,
LB_GETCURSEL, 0, 0L);
SendDlgItemMessage(hDlg, SOURCE_DLG, LB_GETTEXT, n,
(LONG) (LPSTR) attrNameBuf);
if(!strcmp(attrNameBuf, "(none)"))
return FALSE;
lpfnViewAttrInfoDlgProc = MakeProcInstance((FARPROC)ViewAttrInfoDlgProc, hDLL);
DialogBox(hDLL, "ATTR_INFO", GetActiveWindow(), lpfnViewAttrInfoDlgProc);
FreeProcInstance(lpfnViewAttrInfoDlgProc);
return FALSE;
}
BOOL FAR PASCAL _export ViewAttrInfoDlgProc(HWND hDlg, UINT message, UINT wParam,
LONG lParam)
{
NWATTR_INFO attrInfo;
int i;
char boundsBuf[7];
WORD n;
char labelCompareBuf[30];
switch(message)
{
case WM_INITDIALOG:
ReadAttributeInfo(&attrInfo);
SetDlgItemText(hDlg, ATTR_NAME, attrNameBuf);
for(i=0; i < 9; ++i)
{
if(attrInfo.attrFlags & attrFlagsInfo[i].attrFlag)
SendDlgItemMessage(hDlg, ATTR_FLAGS, LB_ADDSTRING, 0,
(LONG) (LPSTR) attrFlagsInfo[i].szLabel);
}
SetDlgItemText(hDlg, SYNTAX, syntax[attrInfo.attrSyntaxID]);
wsprintf(boundsBuf, "%04X", attrInfo.attrLower);
SetDlgItemText(hDlg, LOWER, boundsBuf);
wsprintf(boundsBuf, "%04X", attrInfo.attrUpper);
SetDlgItemText(hDlg, UPPER, boundsBuf);
SetFocus(GetDlgItem(hDlg, ATTR_FLAGS));
return FALSE;
case WM_COMMAND:
switch(wParam)
{
case EXIT_DLG2:
EndDialog(hDlg, TRUE);
return TRUE;
case ATTR_FLAGS:
if (HIWORD (lParam) == LBN_SELCHANGE)
{
n = (WORD) SendDlgItemMessage(hDlg, ATTR_FLAGS,
LB_GETCURSEL, 0, 0L);
SendDlgItemMessage(hDlg, ATTR_FLAGS, LB_GETTEXT, n,
(LONG) (LPSTR) labelCompareBuf );
for(i=0; i < 9; ++i)
{
if(strcmp(labelCompareBuf, attrFlagsInfo[i].szLabel) == 0)
SetDlgItemText(hDlg, DESCRIPTION,
attrFlagsInfo[i].szDesc);
}
}
break;
}
break;
}
return FALSE;
}
ReadAttributeInfo(NWATTR_INFO *attrInfo)
{
NWDSContextHandle dContext;
NWDS_ITERATION iterHandle = -1L;
NWDS_BUFFER *outBuf, *inBuf;
NWDSCCODE cCode;
NWCOUNT attrCount;
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.*/ &inBuf
);
if (cCode < 0)
{
NWDSFreeContext(dContext);
return(cCode);
}
cCode = NWDSAllocBuf(
/* Buffer Size */ DEFAULT_MESSAGE_LEN,
/* Buff. Point.*/ &outBuf
);
if (cCode < 0)
{
NWDSFreeContext(dContext);
NWDSFreeBuf(inBuf);
return(cCode);
}
cCode = NWDSInitBuf(
/* Context handle */ dContext,
/* Operation */ DSV_READ_ATTR_DEF,
/* Buffer */ inBuf
);
if (cCode < 0)
{
NWDSFreeContext(dContext);
NWDSFreeBuf(outBuf);
NWDSFreeBuf(inBuf);
return(cCode);
}
cCode = NWDSPutAttrName(
/* Context Handle */ dContext,
/* In buffer */ inBuf,
/* class name */ attrNameBuf
);
if (cCode < 0)
{
NWDSFreeContext(dContext);
NWDSFreeBuf(outBuf);
NWDSFreeBuf(inBuf);
return(cCode);
}
do
{
cCode = NWDSReadAttrDef(
/* Contxt Handle */ dContext,
/* Info Type */ DS_ATTR_DEFS,
/* All classes ? */ FALSE,
/* Class Names */ inBuf,
/* Iter handle */ &iterHandle,
/* Result Buf */ outBuf
);
if (cCode < 0)
{
NWDSFreeContext(dContext);
NWDSFreeBuf(inBuf);
NWDSFreeBuf(outBuf);
return(cCode);
}
cCode = NWDSGetAttrCount(
/* Contxt Handle */ dContext,
/* Result buffer */ outBuf,
/* Class Def count*/ &attrCount
);
if (cCode < 0)
{
NWDSFreeContext(dContext);
NWDSFreeBuf(outBuf);
NWDSFreeBuf(inBuf);
return(cCode);
}
for (i = 0; i < (int)attrCount; ++i)
{
cCode = NWDSGetAttrDef(
/* Contxt Handle */ dContext,
/* Result Buffer */ outBuf,
/* Item Name */ attrName,
/* Class info */ attrInfo
);
if (cCode < 0)
{
NWDSFreeContext(dContext);
NWDSFreeBuf(outBuf);
NWDSFreeBuf(inBuf);
return(cCode);
}
}
} while(iterHandle != -1L);
NWDSFreeContext(dContext);
NWDSFreeBuf(outBuf);
NWDSFreeBuf(inBuf);
return FALSE;
}
WORD InitClassDefListBox(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];
char classItemName[MAX_SCHEMA_NAME_BYTES];
char classDefItemName[50];
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, CLASS_NAMES, LB_ADDSTRING, 0,
(LONG) (LPSTR) classDefName);
}
} while(iterHandle != -1L);
NWDSFreeContext(dContext);
NWDSFreeBuf(outBuf);
return FALSE;
}
WORD UpdateClassDlgBoxes(HWND hDlg)
{
NWDSContextHandle dContext;
NWDS_ITERATION iterHandle = -1L;
NWDS_BUFFER *outBuf, *className;
Class_Info_T classInfo;
NWDSCCODE cCode;
NWCOUNT classDefCount, classItemCount;
char classDefName[MAX_SCHEMA_NAME_BYTES];
char classItemName[MAX_SCHEMA_NAME_BYTES];
char classDefItemName[50];
char *cptr;
int h, i, j, k;
long rval;
if (!superClassFlag)
{
for(h = 0; h < 6; ++h)
SendDlgItemMessage(hDlg, (h + 102), LB_RESETCONTENT, 0, 0);
}
else
{
for (j=0; j<6; ++j)
{
SendDlgItemMessage(hDlg, (j + 102), LB_ADDSTRING,
0, (LONG) (LPSTR) "____________________________");
}
}
dContext = NWDSCreateContext();
if (dContext == ERR_CONTEXT_CREATION)
{
goto _FreeContext;
}
cCode = NWDSAllocBuf(
/* Buffer Size */ DEFAULT_MESSAGE_LEN,
/* Buff. Point.*/ &outBuf
);
if (cCode < 0)
{
goto _FreeContext;
}
cCode = NWDSAllocBuf(
/* Buffer Size */ DEFAULT_MESSAGE_LEN,
/* Buff. Point.*/ &className
);
if (cCode < 0)
{
goto _FreeOutBuf;
}
cCode = NWDSInitBuf(
/* Context handle */ dContext,
/* Operation */ DSV_READ_CLASS_DEF,
/* Buffer */ className
);
if (cCode < 0)
{
goto _FreeInBuf;
}
cCode = NWDSPutClassName(
/* Context Handle */ dContext,
/* In buffer */ className,
/* class name */ classNameBuf
);
if (cCode < 0)
{
goto _FreeInBuf;
}
do
{
cCode = NWDSReadClassDef(
/* Contxt Handle */ dContext,
/* Info Type */ DS_CLASS_DEFS,
/* All classes ? */ FALSE,
/* Class Names */ className,
/* Iter handle */ &iterHandle,
/* Result Buf */ outBuf
);
if (cCode < 0)
{
goto _FreeInBuf;
}
cCode = NWDSGetClassDefCount(
/* Contxt Handle */ dContext,
/* Result buffer */ outBuf,
/* Class Def count*/ &classDefCount
);
if (cCode < 0)
{
goto _FreeInBuf;
}
for (i = 0; i < (int)classDefCount; ++i)
{
cCode = NWDSGetClassDef(
/* Contxt Handle */ dContext,
/* Result Buffer */ outBuf,
/* Item Name */ classDefName,
/* Class info */ &classInfo
);
if (cCode < 0)
{
goto _FreeInBuf;
}
for (j = 0; j < 5; ++j)
{
cCode = NWDSGetClassItemCount(
/* Context Handle */ dContext,
/* Result Buffer */ outBuf,
/* item Count */ &classItemCount
);
if (cCode < 0)
{
goto _FreeInBuf;
}
for (k = 0; k < classItemCount; ++k)
{
cCode = NWDSGetClassItem(
/* Context Handle */ dContext,
/* Result buffer */ outBuf,
/* Item Name */ classItemName
);
if (cCode < 0)
{
goto _FreeInBuf;
}
if(superClassFlag == 1)
{
if ((j==0) || ((strcmp(classDefName, "Top") == 0) && (j == 3)))
{
rval = SendDlgItemMessage(hDlg, SUPER_CLASSES, LB_FINDSTRING, -1,
(LONG) (LPSTR) classItemName);
if(rval == LB_ERR)
updateFlag = 1;
rval = SendDlgItemMessage(hDlg, OPTIONAL_ATT, LB_FINDSTRING, -1,
(LONG) "ACL");
if(rval == LB_ERR)
topFlag = 1;
}
if(updateFlag ==1 && topFlag ==1)
{
SendDlgItemMessage(hDlg, (j + 102), LB_ADDSTRING,
0, (LONG) (LPSTR) classItemName);
}
}
else
SendDlgItemMessage(hDlg, (j + 102), LB_ADDSTRING,
0, (LONG) (LPSTR) classItemName);
}
if ((superClassFlag == 1) && (j == 0) && (updateFlag ==1) && (topFlag ==1))
UpdateClassFlags(hDlg, &classInfo);
}
if(!superClassFlag)
UpdateClassFlags(hDlg, &classInfo);
}
} while(iterHandle != -1L);
_FreeInBuf:
NWDSFreeBuf(className);
_FreeOutBuf:
NWDSFreeBuf(outBuf);
_FreeContext:
NWDSFreeContext(dContext);
return FALSE;
}
UpdateClassFlags(HWND hDlg, Class_Info_T *classInfo)
{
int i;
for(i=0; i < 5; ++i)
{
if(classInfo->classFlags & classFlagsInfo[i].classFlag)
SendDlgItemMessage(hDlg, CLASS_FLAGS, LB_ADDSTRING, 0,
(LONG) (LPSTR) classFlagsInfo[i].szLabel);
}
}
ReadAllAttributes(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, ATTR_NAMES, LB_ADDSTRING, 0,
(LONG) (LPSTR) attrName);
}
} while(iterHandle != -1L);
NWDSFreeContext(dContext);
NWDSFreeBuf(outBuf);
return FALSE;
}