Get SupportDownload SoftwareGo ShoppingContact Us
Log-In Log-Out
 














 
Last Updated
 
Course Home Download NLM.exe 96KB

An NLM That Uses NDS

Open the recent project NDS.mcp.

File/Open Recent menu

Click on the Target setting ICON in the project screen.

The Target icon looks like this.

Target Icon

Click on NLM Target.

You should see the following.

NDS.mcp Window

We should now look at how to read, write, and modify Novells Directory. You need to remember that this is instructional code and not release production code. You might be able to cut and paste some sections of this code, but you need to add error handling and verification.

/***************************************************************************

 Copyright (c) 1998 Novell, Inc. All Rights Reserved.

 THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND TREATIES.
 USE AND REDISTRIBUTION OF THIS WORK IS SUBJECT TO THE LICENSE AGREEMENT
 ACCOMPANYING THE SOFTWARE DEVELOPMENT KIT (SDK) THAT CONTAINS THIS WORK.
 PURSUANT TO THE SDK LICENSE AGREEMENT, NOVELL HEREBY GRANTS TO DEVELOPER A
 ROYALTY-FREE, NON-EXCLUSIVE LICENSE TO INCLUDE NOVELL'S SAMPLE CODE IN ITS
 PRODUCT. NOVELL GRANTS DEVELOPER WORLDWIDE DISTRIBUTION RIGHTS TO MARKET,
 DISTRIBUTE, OR SELL NOVELL'S SAMPLE CODE AS A COMPONENT OF DEVELOPER'S
 PRODUCTS. NOVELL SHALL HAVE NO OBLIGATIONS TO DEVELOPER OR DEVELOPER'S
 CUSTOMERS WITH RESPECT TO THIS CODE.
****************************************************************************/
#include <stdio.h>
#include <nwdsapi.h>
#include <nwnet.h>
#include <string.h>
#include <stdlib.h>
#include <nwmalloc.h>
#include <signal.h>
#include <nwthread.h>

void ModifyClass(NWDSContextHandle con);
void RemoveAttribute(NWDSContextHandle con);
void RemoveClass(NWDSContextHandle con);
void CreateClass(NWDSContextHandle con);
void CreateAttribute(NWDSContextHandle con);
void Login(NWDSContextHandle con);
NWDSContextHandle SetContext(char *c);
void GetPassword(char *password, int size);
void CreateObject(NWDSContextHandle con);
void RemoveObject(NWDSContextHandle con);
void ModifyObjectName(NWDSContextHandle con);
void MySignalHandler(int SigType);
void PollLoop(void *pointer);
void ModifyObject(NWDSContextHandle con);
void Search(NWDSContextHandle con);

nstr8	 *Names[5], *New[5];
nstr8	 strObjectContext[MAX_DN_CHARS+1];
int	 	 threadID;
int	 	 mainThread;
int	 	 ShutDownFlag = 0;
int	 	 dontCreate = 0;
NWDSContextHandle context;

void main()
{
	 int newThread;

	 threadID = GetThreadGroupID();
	 mainThread = GetThreadID();
	 signal(SIGTERM, MySignalHandler);

	 context = SetContext("[ROOT]");
	 Login(context);
	 CreateAttribute(context);
	 delay(2000);
	 CreateClass(context);
	 delay(2000);
	 ModifyClass(context);
	 delay(2000);
	 CreateObject(context);
	 delay(2000);
	 ModifyObjectName(context);
	 delay(2000);
	 ModifyObject(context);
	 newThread = BeginThread(PollLoop, NULL, 0, &context);
	 SuspendThread(mainThread);
}

// Gets a context handle and sets it to [ROOT]
NWDSContextHandle SetContext(char *c)
{
	 NWDSContextHandle con;
	 NWDSCCODE	 cCode;
	 char	 	 value[10];

	  if (NWDSCreateContextHandle (&con) != 0)
	  {
	  	 printf("Failed\n");
	  	 exit(-1);
	  }
	 if((cCode = NWDSSetContext(con, DCK_NAME_CONTEXT, c)) != 0)
	 {
	 	 printf("Set context failed. %d\n", cCode);
	 }
	 else
	 {
	 	 if((cCode = NWDSGetContext(con, DCK_NAME_CONTEXT, value)) == 0)
	 	 {
	 	 	 printf("Context = %s\n", value);
	 	 }
	 }
	 return(con);
}

// Login to NDS
void Login(NWDSContextHandle con)
{
	 nstr8   admin[MAX_DN_CHARS+1];         
	 nstr8   password[256];
	 NWDSCCODE	 cCode;

	 printf("Login to NDS\n------------\n");
	 printf("Enter Admin User (e.g. .admin.orgname)\nLogin: ");
	 gets(admin);
	 GetPassword(password, 255);

	 if((cCode = NWDSLogin(con, 0, admin, password, 0)) != 0)
	 {
	 	 printf("Login failed:%d\n", cCode);
	 	 NWDSFreeContext(con);
	 	 exit(-1);
	 }

}

void GetPassword(char *password, int size) {
	 int index=-1;
	 WORD  x,y;

	 printf("Password: ");
	 y=wherey();  // find current row 

	 do {
	 	 index++;
	 	 // find current column 
	 	 x=wherex();  
	 	 // make the input cursor visible
	 	 DisplayInputCursor();
	 	 // get a character
	 	 password[index]=(char)getch();

	 	 // if cr then null terminate it 
 	 	 if(password[index]==0x0D)
	 	 	 password[index]='\0';
	 	 // Backspace
  	 	 else if(password[index]==0x08)
  	 	 {
	 	 	 // if there are any characters left 
	 	 	 if (index > 0)
	 	 	 { 
	 	 	 	 index-=2;	 // backup BS and previous char
	 	 	 	 gotoxy((WORD)(x-1),y);	 // backup 
	 	 	 	 putch(' ');	 	 // clear character 
	 	 	 	 gotoxy((WORD)(x-1),y);	 // backup 
	 	 	 }
	 	 	 else
	 	 	 {  // at the start then reset index
	 	 	 	 index=-1;
	 	 	 }
	 	 }
	 	 // normal character
	 	 else
	 	 	 putch('*');
	 } // while not null terminated and the size is OK 
	 while(password[index] && index<size);

	 // if not null terminated, do it now 
	 if(password[index])
	 	 password[index]=NULL;
	 putch('\n');
}

// Creates three Attributes
void CreateAttribute(NWDSContextHandle con)
{
	 NWDSCCODE	 cCode;
	 Attr_Info_T	 	 attrInfo;

	 memset(&attrInfo, (int) '\0', sizeof(Attr_Info_T));
	 attrInfo.asn1ID.length = 0;
	 memset(attrInfo.asn1ID.data, 0, MAX_ASN1_NAME);
	 attrInfo.attrFlags|= DS_SINGLE_VALUED_ATTR;
	 attrInfo.attrFlags|= DS_STRING_ATTR;
	 attrInfo.attrSyntaxID = SYN_CI_STRING;
	 if(((cCode = NWDSDefineAttr(con, "Test:Profile Name", &attrInfo)) != 0)  && 
(cCode != ERR_ATTRIBUTE_ALREADY_EXISTS))
	 {
	 	 printf("%d\n", cCode);
	 }
	 else
	 {
	 	 printf("Test:Profile Name Attribute successfully created.\n");
	 }
	 memset(&attrInfo, (int) '\0', sizeof(Attr_Info_T));
	 attrInfo.asn1ID.length = 0;
	 memset(attrInfo.asn1ID.data, 0, MAX_ASN1_NAME);
	 attrInfo.attrFlags |= DS_SINGLE_VALUED_ATTR;
	 attrInfo.attrFlags|= DS_STRING_ATTR;
	 attrInfo.attrSyntaxID = SYN_CI_STRING;
	 if(((cCode = NWDSDefineAttr(con, "Test:Bookmarks", &attrInfo)) != 0) && (cCode 
!= ERR_ATTRIBUTE_ALREADY_EXISTS))
	 {
	 	 printf("%d\n", cCode);
	 }
	 else
	 {
	 	 printf("Test:Bookmarks Attribute successfully created.\n");
	 }
	 memset(&attrInfo, (int) '\0', sizeof(Attr_Info_T));
	 attrInfo.asn1ID.length = 0;
	 memset(attrInfo.asn1ID.data, 0, MAX_ASN1_NAME);
	 attrInfo.attrFlags |= DS_SINGLE_VALUED_ATTR;
	 attrInfo.attrFlags|= DS_STRING_ATTR;
	 attrInfo.attrSyntaxID = SYN_CI_STRING;
	 if(((cCode = NWDSDefineAttr(con, "Test:Modify Class", &attrInfo)) != 0) && 
(cCode != ERR_ATTRIBUTE_ALREADY_EXISTS))
	 {
	 	 printf("%d\n", cCode);
	 }
	 else
	 {
	 	 printf("Test:Modify Class Attribute successfully created.\n");
	 }
	 
}

// Creates a class using two of the new attributes
void CreateClass(NWDSContextHandle con)
{
	 NWDSCCODE	 cCode;
	 Class_Info_T	 	 classInfo;
	 pBuf_T	 	 	 classBuf;

	 printf("Creating Bookmark Class.\n");
	 //delay(5000);
	 memset(&classInfo, (int) '\0', sizeof(Class_Info_T));
	 if((cCode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN, &classBuf)) != 0)
	 {
	 	 printf("NWDSAllocBuf failed:%d\n", cCode);
	 }
	 else
	 {
	 	 if((cCode = NWDSInitBuf(con, DSV_DEFINE_CLASS, classBuf)) != 0)
	 	 {
	 	 	 printf("NWDSInitBuf failed:%d\n", cCode);
	 	 }
	 	 classInfo.classFlags |= DS_EFFECTIVE_CLASS;
	 	 if((cCode = NWDSBeginClassItem(con, classBuf)) != 0)
	 	 {
	 	 	 printf("NWDSBeginClassItem super failed:%d\n", cCode);
	 	 }
	 	 if((cCode = NWDSPutClassItem(con, classBuf, "Top")) != 0)
	 	 {
	 	 	 printf("NWDSPutClassItem super failed:%d\n", cCode);
	 	 }
	 	 if((cCode = NWDSBeginClassItem(con, classBuf)) != 0)
	 	 {
	 	 	 printf("NWDSBeginClassItem containment failed:%d\n", cCode);
	 	 }
	 	 if((cCode = NWDSPutClassItem(con, classBuf, "Organization")) != 0)
	 	 {
	 	 	 printf("NWDSPutClassItem containment failed:%d\n", cCode);
	 	 }
	 	 if((cCode = NWDSBeginClassItem(con, classBuf)) != 0)
	 	 {
	 	 	 printf("NWDSBeginClassItem naming failed:%d\n", cCode);
	 	 }
	 	 if((cCode = NWDSPutClassItem(con, classBuf, "CN")) != 0)
	 	 {
	 	 	 printf("NWDSPutClassItem naming failed:%d\n", cCode);
	 	 }
	 	 if((cCode = NWDSBeginClassItem(con, classBuf)) != 0)
	 	 {
	 	 	 printf("NWDSBeginClassItem mandatory failed:%d\n", cCode);
	 	 }
	 	 if((cCode = NWDSPutClassItem(con, classBuf, "CN")) != 0)
	 	 {
	 	 	 printf("NWDSPutClassItem mandatory failed:%d\n", cCode);
	 	 }
	 	 	 if((cCode = NWDSBeginClassItem(con, classBuf)) != 0)
	 	 {
	 	 	 printf("NWDSBeginClassItem optional failed:%d\n", cCode);
	 	 }
	 	 if((cCode = NWDSPutClassItem(con, classBuf, "Test:Profile Name")) != 0)
	 	 {
	 	 	 printf("NWDSPutClassItem optional failed:%d\n", cCode);
	 	 }
	 	 if((cCode = NWDSPutClassItem(con, classBuf, "Test:Bookmarks")) != 0)
	 	 {
	 	 	 printf("NWDSPutClassItem optional failed:%d\n", cCode);
	 	 }
	 
	 	 if(((cCode = NWDSDefineClass(con, "Test:Bookmark", &classInfo, classBuf)) != 0) 
&& (cCode != ERR_CLASS_ALREADY_EXISTS))
	 	 {
	 	 	 printf("NWDSDefineClass failed:%d\n", cCode);
	 	 }
	 	 else
	 	 {
	 	 	 printf("Bookmark Class added.\n");
	 	 }
	 
	 	 NWDSFreeBuf(classBuf);
	 }

}

// adds the third attribute to the existing class
void ModifyClass(NWDSContextHandle con)
{
	 NWDSCCODE	 cCode;
	 pBuf_T	 	 	 classBuf;
	 
	 printf("Modifying Class Definition.\n");
	 //delay(5000);
	 if((cCode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN, &classBuf)) != 0)
	 {
	 	 printf("NWDSAllocBuf failed:%d\n", cCode);
	 }
	 else
	 {
	 	 if((cCode = NWDSInitBuf(con, DSV_MODIFY_CLASS_DEF, classBuf)) != 0)
	 	 {
	 	 	 printf("NWDSInitBuf failed:%d\n", cCode);
	 	 }
	 	 if((cCode = NWDSPutAttrName(con, classBuf, "Test:Modify Class")) != 0)
	 	 {
	 	 	 printf("NWDSPutAttrName failed:%d\n", cCode);
	 	 }
	 	 if((cCode = NWDSModifyClassDef(con, "Test:Bookmark", classBuf)) != 0)
	 	 {
	 	 	 printf("Class Definition Modification failed:%d\n", cCode);
	 	 }
	 	 else
	 	 {
	 	 	 printf("Class Modification Successful.\n");
	 	 }
	 	 NWDSFreeBuf(classBuf);
	 }
}

void CreateObject(NWDSContextHandle con)
{
	 NWDSCCODE	 cCode;
	 pBuf_T	 inBuf = NULL;
	 nuint32	 syntaxID;
	 int x;
	 nstr8       strObjectName[MAX_DN_CHARS+1];
	  
	 printf("Creating Objects.\n");
	 if((cCode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN, &inBuf)) != 0)
	 {
	 	 printf("NWDSAllocBuf failed:%d\n", cCode);
	 	 dontCreate = 1;
	 	 ShutDownFlag = 1;
	 }
	 else
	 {
	 	 if((cCode = NWDSInitBuf(con, DSV_ADD_ENTRY, inBuf)) != 0)
	 	 {
	 	 	 printf("NWDSInitBuf failed:%d\n", cCode);
	 	 }
	 
	 	 if((cCode = NWDSPutAttrName(con, inBuf, "Object Class")) != 0)
	 	 {
	 	 	 printf("Put Name in buffer failed:%d.\n", cCode);
	 	 }
	 	 if((cCode = NWDSGetSyntaxID(con, "Object Class", &syntaxID)) != 0)
	 	 {
	 	 	 printf("Get Syntax ID class failed:%d\n", cCode);
	 	 }
	 	 if((cCode = NWDSPutAttrVal(con, inBuf, syntaxID, "Test:Bookmark")) != 0)
	 	 {
	 	 	 printf("NWDSPutAttrVal failed:%d\n", cCode);
	 	 }
	 	 if((cCode = NWDSPutAttrName(con, inBuf, "Test:Profile Name")) != 0)
	 	 {
	 	 	 printf("Put attribute name in buffer failed:%d\n", cCode);
	 	 }
	 	 if((cCode = NWDSGetSyntaxID(con, "Test:Profile Name", &syntaxID)) != 0)
	 	 {
	 	 	 printf("Get Syntax ID name failed:%d\n", cCode);
	 	 }
	 	 if((cCode = NWDSPutAttrVal(con, inBuf, syntaxID, "Rob")) != 0)
	 	 {
	 	 	 printf("NWDSPutAttrVal failed:%d\n", cCode);
	 	 }
	 	 printf("Enter Context for Objects (e.g.  Novell)\nContext: ");
	 	 gets(strObjectContext);
	 	 for(x = 0; x < 5; x++)
	 	 {
	 	 	 printf("Enter Object Name (e.g.  admin)\nName: ");
	 	 	 gets(strObjectName);
	 	 	 strcat(strObjectName, ".");
	 	 	 strcat(strObjectName, strObjectContext);
	 	 	 printf("%s\n", strObjectName);
	 	 	 if((Names[x] = malloc(strlen(strObjectName)+1)) == NULL)
	 	 	 {
	 	 	 	 printf("Memory allocation failed.\n");
	 	 	 	 break;
	 	 	 }
	 	 	 else
	 	 	 {
	 	 	 	 strcpy(Names[x], strObjectName);
	 	 	 	 printf("%s\n", Names[x]);
	 	 	 }
	 
	 	 	 if((cCode = NWDSAddObject(con, Names[x], NULL, 0, inBuf)) != 0)
	 	 	 {
	 	 	 	 printf("add Object failed:%d\n", cCode);
	 	 	 }
	 	 	 else
	 	 	 {
	 	 	 	 printf("Object Added.\n");
	 	 	 }
	 	 	 *strObjectName = '\0';
	 	 }
	 	 NWDSFreeBuf(inBuf);
	 }
}

void ModifyObjectName(NWDSContextHandle con)
{
	 int x;
	 NWDSCCODE	 cCode;
	 
	 if(dontCreate != 1)
	 {
	 	 printf("Modifying Objects Names.\n");
	 	 for(x = 0; x < 5; x++)
	 	 {
	 	 	 if((New[x] = malloc(50)) == NULL)
	 	 	 {
	 	 	 	 printf("Memory allocation failed.\n");
	 	 	 	 ShutDownFlag = 1;
	 	 	 	 break;
	 	 	 }
	 	 	 else
	 	 	 {
	 	 	 	 switch(x)
	 	 	 	 	 {
	 	 	 	 	 case 0:	 strcpy(New[x], "test");
	 	 	 	 	 	 	 break;
	 	 	 	 	 case 1:	 strcpy(New[x], "test2");
	 	 	 	 	 	 	 break;
	 	 	 	 	 case 2:	 strcpy(New[x], "test3");
	 	 	 	 	 	 	 break;
	 	 	 	 	 case 3:	 strcpy(New[x], "test4");
	 	 	 	 	 	 	 break;
	 	 	 	 	 case 4:	 strcpy(New[x], "test5");
	 	 	 	 	 	 	 break;
	 	 	 	 	 }
	 	 	 	 strcat(New[x], ".");
	 	 	 	 strcat(New[x], strObjectContext);
	 	 	 	 if((cCode = NWDSModifyRDN(con, Names[x], New[x], 1)) != 0)
	 	 	 	 {
	 	 	 	 	 printf("Change object name failed:%d\n", cCode);
	 	 	 	 }
	 	 	 	 else
	 	 	 	 {
	 	 	 	 	 printf("%s changed to %s.\n", Names[x], New[x]);
	 	 	 	 }
	 	 	 }
	 	 }
	 }
}

void ModifyObject(NWDSContextHandle con)
{
	 NWDSCCODE	 cCode;
	 int	 x;
	 pBuf_T	 inBuf, inBuf2, inBuf3, inBuf4;
	 nuint32	 syntaxID;
	 nint32	 iterHandle;

	 if(dontCreate != 1)
	 {
	 	 printf("Modifying Objects Values.\n");
	 	 if((cCode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN, &inBuf)) != 0)
	 	 {
	 	 	 printf("NWDSAllocBuf failed:%d\n", cCode);
	 	 }
	 	 else
	 	 {
	 	 	 if((cCode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN, &inBuf2)) != 0)
	 	 	 {
	 	 	 	 printf("NWDSAllocBuf failed:%d\n", cCode);
	 	 	 }
	 	 	 else
	 	 	 {
	 	 	 	 if((cCode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN, &inBuf3)) != 0)
	 	 	 	 {
	 	 	 	 	 printf("NWDSAllocBuf failed:%d\n", cCode);
	 	 	 	 }
	 	 	 	 else
	 	 	 	 {
	 	 	 	 	 if((cCode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN, &inBuf4)) != 0)
	 	 	 	 	 {
	 	 	 	 	 	 printf("NWDSAllocBuf failed:%d\n", cCode);
	 	 	 	 	 }
	 	 	 	 	 else
	 	 	 	 	 {
	 	 	 	 	 	 // add value for attribute Test:Bookmarks
	 	 	 	 	 	 if((cCode = NWDSInitBuf(con, DSV_MODIFY_ENTRY, inBuf)) != 0)
	 	 	 	 	 	 {
	 	 	 	 	 	 	 printf("NWDSInitBuf failed:%d\n", cCode);
	 	 	 	 	 	 }
	 	 	 	 	 	 if((cCode = NWDSGetSyntaxID(con, "Test:Bookmarks", &syntaxID)) != 0)
	 	 	 	 	 	 {
	 	 	 	 	 	 	 printf("Get Syntax ID class failed:%d\n", cCode);
	 	 	 	 	 	 }
	 	 	 	 	 	 if((cCode = NWDSPutChangeAndVal(con, inBuf, DS_ADD_ATTRIBUTE, "Test:Bookmarks", 
syntaxID, "Yahoo")) !=0 )
	 	 	 	 	 	 {
	 	 	 	 	 	 	 printf("Put Add Value in buffer failed:%d\n", cCode);
	 	 	 	 	 	 }
	 	 	 	 	 	 // add value for attribute Test:modify Class
	 	 	 	 	 	 if((cCode = NWDSInitBuf(con, DSV_MODIFY_ENTRY, inBuf3)) != 0)
	 	 	 	 	 	 {
	 	 	 	 	 	 	 printf("NWDSInitBuf failed:%d\n", cCode);
	 	 	 	 	 	 }
	 	 	 	 	 	 if((cCode = NWDSGetSyntaxID(con, "Test:Modify Class", &syntaxID)) != 0)
	 	 	 	 	 	 {
	 	 	 	 	 	 	 printf("Get Syntax ID class failed:%d\n", cCode);
	 	 	 	 	 	 }
	 	 	 	 	 	 if((cCode = NWDSPutChangeAndVal(con, inBuf, DS_ADD_ATTRIBUTE, "Test:Modify 
Class", syntaxID, "Netscape")) !=0 )
	 	 	 	 	 	 {
	 	 	 	 	 	 	 printf("Put Add Value in buffer failed:%d\n", cCode);
	 	 	 	 	 	 }
	 	 	 	 	 	 // modify Test:Profile name Value
	 	 	 	 	 	 if((cCode = NWDSInitBuf(con, DSV_MODIFY_ENTRY, inBuf2)) != 0)
	 	 	 	 	 	 {
	 	 	 	 	 	 	 printf("NWDSInitBuf failed:%d\n", cCode);
	 	 	 	 	 	 }
	 	 	 	 	 	 if((cCode = NWDSGetSyntaxID(con, "Test:Profile Name", &syntaxID)) != 0)
	 	 	 	 	 	 {
	 	 	 	 	 	 	 printf("Get Syntax ID class failed:%d\n", cCode);
	 	 	 	 	 	 }
	 	 	 	 	 	 if((cCode = NWDSPutChangeAndVal(con, inBuf, DS_OVERWRITE_VALUE, "Test:Profile 
Name", syntaxID, "Larry")) !=0 )
	 	 	 	 	 	 {
	 	 	 	 	 	 	 printf("Put Overwrite Value in buffer failed:%d\n", cCode);
	 	 	 	 	 	 }
	 	 	 	 	 	 // remove and then add new Test:Profile Name
	 	 	 	 	 	 if((cCode = NWDSInitBuf(con, DSV_MODIFY_ENTRY, inBuf4)) != 0)
	 	 	 	 	 	 {
	 	 	 	 	 	 	 printf("NWDSInitBuf failed:%d\n", cCode);
	 	 	 	 	 	 }
	 	 	 	 	 	 if((cCode = NWDSPutChangeAndVal(con, inBuf, DS_REMOVE_VALUE, "Test:Profile 
Name", syntaxID, "Larry")) !=0 )
	 	 	 	 	 	 {
	 	 	 	 	 	 	 printf("Put Remove Value in buffer failed:%d\n", cCode);
	 	 	 	 	 	 }
	 	 	 	 	 	 if((cCode = NWDSPutChangeAndVal(con, inBuf, DS_ADD_VALUE, "Test:Profile Name", 
syntaxID, "Superman")) !=0 )
	 	 	 	 	 	 {
	 	 	 	 	 	 	 printf("Put Add Value in buffer failed:%d\n", cCode);
	 	 	 	 	 	 }
	 
	 	 	 	 	 	 for(x = 0; x < 5; x++)
	 	 	 	 	 	 {
	 	 	 	 	 	 	 iterHandle = -1;
	 	 	 	 	 	 	 if((cCode = NWDSModifyObject(con, New[x], &iterHandle, 1, inBuf)) != 0)
	 	 	 	 	 	 	 {
	 	 	 	 	 	 	 	 printf("Add Attribute value failed:%d\n", cCode);
	 	 	 	 	 	 	 }
	 	 	 	 	 	 	 else
	 	 	 	 	 	 	 {
	 	 	 	 	 	 	 	 printf("Add Attribute Value successful on %s.\n", New[x]);
	 	 	 	 	 	 	 }
	 	 	 	 	 	 	 if((cCode = NWDSModifyObject(con, New[x], &iterHandle, 1, inBuf3)) != 0)
	 	 	 	 	 	 	 {
	 	 	 	 	 	 	 	 printf("Add Attribute value failed:%d\n", cCode);
	 	 	 	 	 	 	 }
	 	 	 	 	 	 	 else
	 	 	 	 	 	 	 {
	 	 	 	 	 	 	 	 printf("Add Attribute Value successful on %s.\n", New[x]);
	 	 	 	 	 	 	 }
	 	 	 	 	 	 	 if((cCode = NWDSModifyObject(con, New[x], &iterHandle, 1, inBuf2)) != 0)
	 	 	 	 	 	 	 {
	 	 	 	 	 	 	 	 printf("Modify Value failed:%d\n", cCode);
	 	 	 	 	 	 	 }
	 	 	 	 	 	 	 else
	 	 	 	 	 	 	 {
	 	 	 	 	 	 	 	 printf("Modify Value successful on %s.\n", New[x]);
	 	 	 	 	 	 	 }
	 	 	 	 	 	 	 if((cCode = NWDSModifyObject(con, New[x], &iterHandle, 0, inBuf4)) != 0)
	 	 	 	 	 	 	 {
	 	 	 	 	 	 	 	 printf("Add/Remove Value failed:%d\n", cCode);
	 	 	 	 	 	 	 }
	 	 	 	 	 	 	 else
	 	 	 	 	 	 	 {
	 	 	 	 	 	 	 	 printf("Add/Remove Value successful on %s.\n", New[x]);
	 	 	 	 	 	 	 }
	 
	 	 	 	 	 	 }
	 	 	 	 	 	 NWDSFreeBuf(inBuf4);
	 	 	 	 	 }
	 	 	 	 	 NWDSFreeBuf(inBuf3);
	 	 	 	 }
	 	 	 	 NWDSFreeBuf(inBuf2);
	 	 	 }
	 	 	 NWDSFreeBuf(inBuf);
	 	 }
	 }
}

void PollLoop(void *pointer)
{
	 NWDSCCODE	 cCode;
	 int	 x;
	 nint32	 iterHandle;
	 NWDSContextHandle *con = pointer;
	 pBuf_T	 objectInfo;

	 printf("Entering Poll Loop.\n");
	 while(ShutDownFlag != 1)
	 {
	 	 for(x = 0; x < 5; x++)
	 	 {
	 	 	 if((cCode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN, &objectInfo)) != 0)
	 	 	 {
	 	 	 	 printf("NWDSAllocBuf failed:%d\n", cCode);
	 	 	 	 break;
	 	 	 }
	 	 	 else
	 	 	 {
	 	 	 	 if((cCode = NWDSInitBuf(*con, DSV_READ, objectInfo)) != 0)
	 	 	 	 {
	 	 	 	 	 printf("NWDSInitBuf failed:%d\n", cCode);
	 	 	 	 }
	 	 	 	 else
	 	 	 	 {
	 	 	 	 	 iterHandle = NO_MORE_ITERATIONS;
	 	 	 	 	 if((cCode = NWDSRead(*con, New[x], DS_ATTRIBUTE_VALUES, 1, NULL, &iterHandle, 
objectInfo)) != 0)
	 	 	 	 	 {
	 	 	 	 	 	 printf("NWDSRead for %s failed:%d.\n", New[x], cCode);
	 	 	 	 	 }
	 	 	 	 	 else
	 	 	 	 	 {
	 	 	 	 	 	 printf("Object %s read.\n", New[x]);
	 	 	 	 	 }
	 	 	 	 	 NWDSFreeBuf(objectInfo);
	 	 	 	 }
	 	 	 }
	 	 }
	 	 Search(*con);
	 	 delay(30000);
	 };
}


void Search(NWDSContextHandle con)
{
	 NWDSCCODE	 cCode;
	 pBuf_T	 	 searchFilter, objectInfo;
	 Filter_Cursor_T	 *cur;
	 nint32	 iterHandle;

	 printf("Performing Search.\n");
	 if((cCode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN, &searchFilter)) != 0)
	 {
	 	 printf("buffer allocation failed:%d\n", cCode);
	 }
	 else
	 {
	 	 if((cCode = NWDSAllocFilter(&cur)) != 0)
	 	 {
	 	 	 printf("AllocFilter failed:%d\n", cCode);
	 	 }
	 	 else
	 	 {
	 	 	 if((cCode = NWDSInitBuf(con, DSV_SEARCH_FILTER, searchFilter)) != 0)
	 	 	 {
	 	 	 	 printf("InitBuf failed:%d\n", cCode);
	 	 	 }
	 	 	 if((cCode = NWDSAddFilterToken(cur, FTOK_ANAME, "Test:Modify Class", 0)) != 0)
	 	 	 {
	 	 	 	 printf("add token failed:%d\n", cCode);
	 	 	 }
	 	 	 if((cCode = NWDSAddFilterToken(cur, FTOK_EQ, NULL, 0)) != 0)
	 	 	 {
	 	 	 	 printf("add token failed:%d\n", cCode);
	 	 	 }
	 	 	 if((cCode = NWDSAddFilterToken(cur, FTOK_AVAL, "Netscape", SYN_CI_STRING)) != 0)
	 	 	 {
	 	 	 	 printf("add token failed:%d\n", cCode);
	 	 	 }
	 	 	 if((cCode = NWDSAddFilterToken(cur, FTOK_AND, NULL, 0)) != 0)
	 	 	 {
	 	 	 	 printf("add token failed:%d\n", cCode);
	 	 	 }
	 	 	 if((cCode = NWDSAddFilterToken(cur, FTOK_ANAME, "Test:Bookmarks", 0)) != 0)
	 	 	 {
	 	 	 	 printf("add token failed:%d\n", cCode);
	 	 	 }
	 	 	 if((cCode = NWDSAddFilterToken(cur, FTOK_EQ, NULL, 0)) != 0)
	 	 	 {
	 	 	 	 printf("add token failed:%d\n", cCode);
	 	 	 }
	 	 	 if((cCode = NWDSAddFilterToken(cur, FTOK_AVAL, "Yahoo", SYN_CI_STRING)) != 0)
	 	 	 {
	 	 	 	 printf("add token failed:%d\n", cCode);
	 	 	 }
	 	 	 if((cCode = NWDSAddFilterToken(cur, FTOK_END, NULL, 0)) != 0)
	 	 	 {
	 	 	 	 printf("add token failed:%d\n", cCode);
	 	 	 }
	 	 	 if((cCode = NWDSPutFilter(con, searchFilter, cur, NULL)) != 0)
	 	 	 {
	 	 	 	 printf("PutFilter failed:%d\n", cCode);
	 	 	 }
	 	 	 else
	 	 	 {
	 	 	 	 printf("Search Expression Tree defined.\n");
	 	 	 }
	 	 	 iterHandle = -1;
	 	 	 if((cCode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN, &objectInfo)) != 0)
	 	 	 {
	 	 	 	 printf("buffer allocation failed:%d\n", cCode);
	 	 	 }
	 	 	 else
	 	 	 {	 	 
	 	 	 	 if((cCode = NWDSSearch(con, "[ROOT]", DS_SEARCH_SUBTREE, 1, searchFilter, 
DS_ATTRIBUTE_VALUES, 1, NULL, &iterHandle, 0, 0, objectInfo)) != 0)
	 	 	 	 {
	 	 	 	 	 printf("Search failed:%d\n", cCode);
	 	 	 	 }
	 	 	 	 else
	 	 	 	 {
	 	 	 	 	 printf("Search successful.\n");
	 	 	 	 }
	 	 	 	 NWDSFreeBuf(objectInfo);
	 	 	 }
	 	 }
	 	 NWDSFreeBuf(searchFilter);
	 }
}

void RemoveObject(NWDSContextHandle con)
{
	 NWDSCCODE	 cCode;
	 int	 x;
	 
	 printf("Removing Objects.\n");
	 for(x = 0; x < 5; x++)
	 {
	 	 if(Names[x] != NULL)
	 	 {
	 	 	 if((cCode = NWDSRemoveObject(con, New[x])) != 0)
	 	 	 {
	 	 	 	 printf("Remove Object failed:%d\n", cCode);
	 	 	 }
	 	 	 else
	 	 	 {
	 	 	 	 printf("Object Removed.\n");
	 	 	 }
	 	 	 free(Names[x]);
	 	 	 free(New[x]);
	 	 }
	 }
}

// removes the new class
void RemoveClass(NWDSContextHandle con)
{
	 NWDSCCODE	 cCode;

	 printf("Removing Class.\n");
	 //delay(5000);
	 if((cCode = NWDSRemoveClassDef(con, "Test:Bookmark")) != 0)
	 {
	 	 printf("Error removing class:%d\n", cCode);
	 }
	 else
	 {
	 	 printf("Class removed successfully.\n");
	 }
}

//  removes the attributes
void RemoveAttribute(NWDSContextHandle con)
{
	 NWDSCCODE	 cCode;

	 printf("Removing Attribute Definitions.\n");
	 //delay(5000);
	 if((cCode = NWDSRemoveAttrDef(con, "Test:Profile Name")) != 0)
	 {
	 	 printf("Remove code:%d\n", cCode);
	 }
	 else
	 {
	 	 printf("Test:Profile Name successfully removed.\n");
	 }

	 if((cCode = NWDSRemoveAttrDef(con, "Test:Bookmarks")) != 0)
	 {
	 	 printf("Remove code:%d\n", cCode);
	 }
	 else
	 {
	 	 printf("Test:Bookmarks successfully removed.\n");
	 }
	 if((cCode = NWDSRemoveAttrDef(con, "Test:Modify Class")) != 0)
	 {
	 	 printf("Remove code:%d\n", cCode);
	 }
	 else
	 {
	 	 printf("Test:Modify Class successfully removed.\n");
	 }
	 
}

#pragma off(unreferenced);
void MySignalHandler(int SigType)
#pragma on(unreferenced);
{
	 int tmpThreadID, status = 0;

	 tmpThreadID = SetThreadGroupID(threadID);
	 ShutDownFlag = 1;
	 RemoveObject(context);
	 delay(2000);
	 RemoveClass(context);
	 delay(2000);
	 RemoveAttribute(context);
	 NWDSFreeContext(context);
	 SetThreadGroupID(tmpThreadID);
	 ResumeThread(mainThread);
}

You should have looked over the code at this point. I will start with the include files.


Last updated on:

Course Home Download NLM.exe 96KB