home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / snapx2.exe / SPCLAS.EXE / SNAPCLAS.C next >
C/C++ Source or Header  |  1995-02-15  |  57KB  |  1,487 lines

  1. /*-------------------------------------------------------------------------*/
  2. /* snapclas.c                                                              */
  3. /*                                                                         */
  4. /* (c) Copyright 1992-1994 Novell, Inc.  All rights reserved.              */
  5. /*                                                                         */
  6. /* The following source code is provided to aid in the development of      */
  7. /* NetWare (TM) compatible products and is provided "AS IS" AND WITHOUT    */
  8. /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING WITHOUT LIMITATION ANY     */
  9. /* IMPLIED WARRANTIES OF MERCHANTABILITY, TITLE AND FITNESS FOR A          */
  10. /* PARTICULAR PURPOSE.  Some states do not allow limitations on how long   */
  11. /* an implied warranty lasts, so the above limitation may not apply to     */
  12. /* You.  This warranty gives you specific legal rights which vary from     */
  13. /* state to state.  Some states do not allow the exclusion or limitation   */
  14. /* of incidental or consequential damages, so the above limitation or      */
  15. /* exclusion may not apply to You.                                         */
  16. /*                                                                         */
  17. /*-------------------------------------------------------------------------*/
  18. #include <windows.h>
  19. #include <toolhelp.h>
  20. #include <string.h>
  21. #include <stdio.h>
  22. #include <nwnet.h>
  23. #include <nwsnapin.h>
  24. #include "snapclas.h"
  25.  
  26. /*------------------------------------------------------------------------*/
  27. /*  Function Prototypes                                                   */
  28. /*------------------------------------------------------------------------*/
  29.  
  30. #ifdef __cplusplus
  31. extern "C"
  32. {
  33. #endif
  34.  
  35. N_EXTERN_LIBRARY (NWRCODE) 
  36. SnapinSoldierProc (pnstr8 name, nuint16 msg, nparam p1, nparam p2);
  37.  
  38. N_EXTERN_LIBRARY (void) 
  39. ShowInfoMenuAction (void) ;
  40.  
  41. N_EXTERN_LIBRARY (void) 
  42. ShowInfoMenuValid (pnuint16 pFlags) ;
  43.  
  44. N_EXTERN_LIBRARY (void) 
  45. DefineClassMenuAction (void) ;
  46.  
  47. N_EXTERN_LIBRARY (void) 
  48. DefineClassMenuValid (pnuint16 pFlags) ;
  49.  
  50. N_EXTERN_LIBRARY (void) 
  51. RemoveClassMenuAction (void) ;
  52.  
  53. N_EXTERN_LIBRARY (void) 
  54. RemoveClassMenuValid (pnuint16 pFlags) ;
  55.  
  56. BOOL _export FAR PASCAL AddSoldierObjectDialogProc (HWND hwnd, UINT message, 
  57.                                              WPARAM wParam, LPARAM lParam);
  58. BOOL _export FAR PASCAL SoldierIdentificationDlg (HWND hwnd, UINT message, 
  59.                                              WPARAM wParam, LPARAM lParam);
  60. BOOL AddSoldierObject (char *strName, char *spouseDN);
  61. NWRCODE AddSoldierClassDefinition (void);
  62. NWRCODE RemoveSoldierClassDefinition (void);
  63. int ReadObjectData (void);
  64. int ModifyObjectData (char *name);
  65.  
  66. #ifdef __cplusplus
  67. }
  68. #endif
  69.  
  70. /*------------------------------------------------------------------------*/
  71. /*  Type Definitions And MACROS                                           */
  72. /*  -- This is where original DS attributes and updates are stored        */
  73. /*------------------------------------------------------------------------*/
  74. typedef struct tagSoldierObjData
  75. {
  76.   HWND hDialogIdent;
  77.   char name[256];
  78.   char surname[256];
  79.   char surnameChange[256];
  80.   char rank[64];
  81.   char rankChange[64];
  82.   char serialNo[64];
  83.   char serialNoChange[64];
  84. } TSoldierObject;
  85.  
  86. #define NUM_SOLDIER_PAGES   1
  87.  
  88. /*------------------------------------------------------------------------*/
  89. /*  Global Used for this snapin's handling of Soldier objects             */
  90. /*------------------------------------------------------------------------*/
  91. NWAPageStruct soldierPages[NUM_SOLDIER_PAGES];
  92. static int classDefinedFlag=0;
  93. static int createAnotherFlag=0;
  94. static int showDetailsFlag=0;
  95. static char nameBuf[256];
  96. static char theSurname[MAX_DN_BYTES];
  97. static TSoldierObject soldierObjData;
  98. HINSTANCE hDLL;
  99. HINSTANCE hCtrlDLL;
  100.  
  101. /*-------------------------------------------------------------------------*/
  102. /*  DLL Entry Point                                                        */
  103. /*-------------------------------------------------------------------------*/
  104. int FAR PASCAL LibMain (HINSTANCE hInstance, WORD wDataSeg, 
  105.                         WORD cbHeapSize, LPSTR lpCmdLine)
  106. {
  107.    hDLL = hInstance;
  108.    if (cbHeapSize != 0)
  109.       UnlockData (0);
  110.    return 1;
  111. };
  112.  
  113. /*-------------------------------------------------------------------------*/
  114. /* Function : InitSnapin (void)                                            */
  115. /* Description :                                                           */
  116. /*    Every Snapin DLL must provide this function. In this function,       */
  117. /*    snapin menu items (under Tools) may be registered. Also, object      */
  118. /*    procs, which handle object-level events, are registered.             */
  119. /*                                                                         */
  120. /*-------------------------------------------------------------------------*/
  121. int _export FAR PASCAL InitSnapin()
  122. {
  123.    nuint16 menuIDShowInfo=0;
  124.    nuint16 menuIDAddClassDefs=0;
  125.    nuint16 menuIDRemClassDefs=0;
  126.  
  127.    /*----------------------------------------------------------*/
  128.    /* Load MUSCROLL.DLL                                        */
  129.    /* MUSCROLL support is needed in MVED control.              */
  130.    /*----------------------------------------------------------*/
  131.    hCtrlDLL = LoadLibrary ("muscroll.dll");
  132.  
  133.    /*----------------------------------------------------------*/
  134.    /* Registering Soldier Object Class Proc                    */
  135.    /*----------------------------------------------------------*/
  136.    NWARegisterObjectProc (NWA_DS_OBJECT_TYPE, 
  137.                           "Soldier", 
  138.                           "Novell, Inc. (C) All rights reserved.", 
  139.                           hDLL, 
  140.                           (NWASnapinObjectProc) SnapinSoldierProc, 
  141.                           NWA_SNAPIN_VERSION);
  142.  
  143.    /*----------------------------------------------------------*/
  144.    /* Registering Menu Items                                   */
  145.    /* -- These are used for creating and removing the Soldier  */
  146.    /* -- class in the NDS Schema, so that the rest of the demo */
  147.    /* -- makes sense.  Schema extension is usually done in an  */
  148.    /* -- installation NLM on the application's server side.    */
  149.    /*----------------------------------------------------------*/
  150.    NWARegisterMenu (NWA_VIEW_CONSOLE, 
  151.                     0,
  152.                     NULL,
  153.                     MF_STRING, 
  154.                     &menuIDShowInfo, 
  155.                     "NWAdmin Info...",
  156.                     "Display info obtained through the Snapin interface.", 
  157.                     ShowInfoMenuAction, ShowInfoMenuValid, 
  158.                     NWA_SNAPIN_VERSION);
  159.  
  160.    NWARegisterMenu (NWA_VIEW_CONSOLE, 
  161.                     0,
  162.                     NULL,
  163.                     MF_STRING, 
  164.                     &menuIDAddClassDefs, 
  165.                     "Define Class",
  166.                     "Add the Soldier class definition in DS database.", 
  167.                     DefineClassMenuAction, DefineClassMenuValid, 
  168.                     NWA_SNAPIN_VERSION);
  169.  
  170.    NWARegisterMenu (NWA_VIEW_CONSOLE, 
  171.                     0,
  172.                     NULL, 
  173.                     MF_STRING, 
  174.                     &menuIDRemClassDefs, 
  175.                     "Remove Class",
  176.                     "Removes the Soldier class definition in DS database.", 
  177.                     RemoveClassMenuAction, RemoveClassMenuValid, 
  178.                     NWA_SNAPIN_VERSION);
  179.  
  180.    return NWA_RET_SUCCESS;
  181. }
  182.  
  183. /*-------------------------------------------------------------------------*/
  184. /* Function : ShutDown (void)                                              */
  185. /* Description :                                                           */
  186. /*   Free up muscroll.dll                                                  */
  187. /*-------------------------------------------------------------------------*/
  188. void FAR PASCAL ShutDown (void) 
  189. {
  190.   FreeLibrary (hCtrlDLL);
  191. }
  192.  
  193.  
  194. /*-------------------------------------------------------------------------*/
  195. /* Function : ShowInfoMenuAction (void)                                    */
  196. /* Description :                                                           */
  197. /*   Menu Action Callback Proc for ShowInfo Menu                           */
  198. /*   This function is executed when the "Define Class" menu item is        */
  199. /*   clicked on.                                                           */
  200. /*-------------------------------------------------------------------------*/
  201. N_GLOBAL_LIBRARY (void)  _export
  202. ShowInfoMenuAction
  203. (
  204.   void 
  205. )
  206. {
  207.   int err;
  208.   UINT32  nwaVersion;
  209.   UINT8   nwaVerMajor;
  210.   UINT8   nwaVerMinor;
  211.   UINT8   nwaVerRevision;
  212.   INT32  selObjectCount;
  213.   NWASelObject selectedObject;
  214.   char    selectedObjectClass[255];
  215.   char    selectedObjectName[255];
  216.   char    xlatedClassName[255];
  217.   char    xlatedPropName[255];
  218.   char buf[1024];
  219.  
  220.   {
  221.     err = NWAGetNWAdminVersion(&nwaVersion);                      /* ##### */
  222.     if (err != NWA_RET_SUCCESS)                                   /* #     */
  223.       return;                                                     /* ####  */
  224.     nwaVerMajor = (BYTE)(nwaVersion >> 24 & 0xff);                /* #     */
  225.     nwaVerMinor = (BYTE)(nwaVersion >> 16 & 0xff);                /* ##### */
  226.     nwaVerRevision = (BYTE)(nwaVersion & 0xff);
  227.     err = NWAGetSelObjectCount((pnint32)&selObjectCount);         /* ##### */
  228.     if (err != NWA_RET_SUCCESS)                                   /* #     */
  229.       return;                                                     /* ####  */
  230.     if (selObjectCount)                                           /* #     */
  231.       err = NWAGetSelObject(0, &selectedObject);                  /* #     */
  232.     if (err != NWA_RET_SUCCESS)
  233.       return;
  234.     strcpy (selectedObjectName, selectedObject.objName);
  235.     strcpy (selectedObjectClass, selectedObject.objClass);
  236.     err = NWAGetTranslatedClassName("Soldier",                    /*  #### */
  237.                                     xlatedClassName, 254);        /* #     */
  238.     if (err != NWA_RET_SUCCESS)                                   /* #  ## */
  239.       return;                                                     /* #   # */
  240.     xlatedPropName[0] = '\0';                                     /*  ###  */
  241.     err = NWAGetTranslatedPropertyName("Rank", "Soldier", 
  242.                                        xlatedPropName, 254);
  243.     if (err != NWA_RET_SUCCESS)
  244.       return;
  245.     wsprintf (buf, 
  246.               "Info retrieved:\n"
  247.               "     Version=%d.%d rev%d\n"
  248.               "     Selected Object Count=%d\n"
  249.               "     First Selected Object='", 
  250.               nwaVerMajor, nwaVerMinor, nwaVerRevision,
  251.               selObjectCount);
  252.     strcat (buf, selectedObjectName);
  253.     strcat (buf, "' of class '");
  254.     strcat (buf, selectedObjectClass);
  255.     strcat (buf, "'\n     Soldier's Translated Class Name='");
  256.     strcat (buf, xlatedClassName);
  257.     strcat (buf, "'\n     Translated Prop Name of Rank='");
  258.     strcat (buf, xlatedPropName);
  259.     strcat (buf, "'");
  260.     MessageBox (NULL, buf, "Information from NWAdmin", MB_OK);
  261.   }
  262. }
  263.  
  264. /*-------------------------------------------------------------------------*/
  265. /* Function : ShowInfoMenuValid (void)                                     */
  266. /* Description :                                                           */
  267. /*   Menu Valid Callback Proc for ShowInfo Menu                            */
  268. /*   -- This function is called to determine whether or not to inactivate  */
  269. /*   -- (gray out) the menu item                                           */
  270. /*-------------------------------------------------------------------------*/
  271. N_GLOBAL_LIBRARY (void)  _export
  272. ShowInfoMenuValid (pnuint16 pFlags)
  273. {
  274.     *pFlags=MF_ENABLED;
  275. }
  276.  
  277. /*-------------------------------------------------------------------------*/
  278. /* Function : DefineClassMenuAction (void)                                 */
  279. /* Description :                                                           */
  280. /*   Menu Action Callback Proc for DefineClass Menu                        */
  281. /*   This function is executed when the "Define Class" menu item is        */
  282. /*   clicked on.                                                           */
  283. /*-------------------------------------------------------------------------*/
  284. N_GLOBAL_LIBRARY (void)  _export
  285. DefineClassMenuAction
  286. (
  287.   void 
  288. )
  289. {
  290.   int err;
  291.   char buf[128];
  292.  
  293.   if  (!classDefinedFlag) 
  294.   {
  295.     err =  (int)  AddSoldierClassDefinition();
  296.     wsprintf (buf, " AddSoldierClassDefinition() returned = %d", err);
  297.     MessageBox (NULL, buf, "Add Class Definition", MB_OK);
  298.     classDefinedFlag=1;
  299.   }
  300.   else
  301.   {
  302.     MessageBox (NULL, "Class definition for Soldier already exist.\n", 
  303.                 "Add Class Definition", MB_OK);
  304.   }
  305. }
  306.  
  307. /*-------------------------------------------------------------------------*/
  308. /* Function : DefineClassMenuValid (void)                                  */
  309. /* Description :                                                           */
  310. /*   Menu Valid Callback Proc for DefineClass Menu                         */
  311. /*   -- This function is called to determine whether or not to inactivate  */
  312. /*   -- (gray out) the menu item                                           */
  313. /*-------------------------------------------------------------------------*/
  314. N_GLOBAL_LIBRARY (void)  _export
  315. DefineClassMenuValid (pnuint16 pFlags)
  316. {
  317.   if  (!classDefinedFlag) 
  318.   {
  319.     *pFlags=FALSE;
  320.   }
  321.   else
  322.   {
  323.     *pFlags=TRUE;
  324.   }
  325. }
  326.  
  327. /*-------------------------------------------------------------------------*/
  328. /* Function : RemoveClassMenuAction (void)                                 */
  329. /* Description :                                                           */
  330. /*   Menu Action Callback Proc for RemoveClass Menu                        */
  331. /*   -- This function is executed when the menu item is clicked on         */
  332. /*-------------------------------------------------------------------------*/
  333. N_GLOBAL_LIBRARY (void)  _export
  334. RemoveClassMenuAction
  335. (
  336.   void 
  337. )
  338. {
  339.   int err;
  340.   char buf[128];
  341.  
  342.   if  (classDefinedFlag) 
  343.   {
  344.     err =  (int)  RemoveSoldierClassDefinition();
  345.     wsprintf (buf, " RemoveSoldierClassDefinition() returned = %d", err);
  346.     MessageBox (NULL, buf, "Remove Class Definition", MB_OK);
  347.     classDefinedFlag=0;
  348.   }
  349.   else
  350.   {
  351.     MessageBox (NULL, "Class definition for Soldier does not exist.\n", 
  352.                "Add Class Definition", MB_OK);
  353.   }
  354. }
  355.  
  356. /*-------------------------------------------------------------------------*/
  357. /* Function : RemoveClassMenuValid (void)                                  */
  358. /* Description :                                                           */
  359. /*   Menu Valid Callback Proc for RemoveClass Menu                         */
  360. /*   -- This function is called to determine whether or not to inactivate  */
  361. /*   -- (gray out) the menu item                                           */
  362. /*-------------------------------------------------------------------------*/
  363. N_GLOBAL_LIBRARY (void)  _export
  364. RemoveClassMenuValid (pnuint16 pFlags)
  365. {
  366.   if  (classDefinedFlag) 
  367.   {
  368.     *pFlags=FALSE;
  369.   }
  370.   else
  371.   {
  372.     *pFlags=TRUE;
  373.   }
  374. }
  375.  
  376. /*-------------------------------------------------------------------------*/
  377. /* Function : SnapinSoldierProc (void)                                     */
  378. /* Description :                                                           */
  379. /*   Soldier Snapin Callback Proc                                          */
  380. /*-------------------------------------------------------------------------*/
  381. N_GLOBAL_LIBRARY (NWRCODE)  _export
  382. SnapinSoldierProc (pnstr8 name, nuint16 msg, nparam p1, nparam p2)
  383. {
  384.    static HBITMAP hBitmap;
  385.    static HBITMAP hAlias; 
  386.    static HBITMAP hReadOnly;
  387.    char   translatedName[MAX_SCHEMA_NAME_BYTES];
  388.  
  389.    switch (msg)
  390.    {
  391.       case NWA_MSG_INITSNAPIN:
  392.            {
  393.              /*-------------------------------------------------*/
  394.              /*           initialize pages                      */
  395.                  /*-------------------------------------------------*/
  396.                  soldierPages[0].dlgProc = (DLGPROC)SoldierIdentificationDlg;
  397.                  soldierPages[0].resName = "SOLDIER_IDENTIFICATION";
  398.                  soldierPages[0].pageTitle = "Identification";
  399.                  
  400.                  /*-------------------------------------------------*/
  401.                  /*            Register bitmaps here                */
  402.                  /*-------------------------------------------------*/
  403.                  hBitmap   = LoadBitmap (hDLL, "Soldier");
  404.              hAlias    = LoadBitmap (hDLL, "SoldierAlias");
  405.              hReadOnly = LoadBitmap (hDLL, "SoldierRO");
  406.    
  407.              LoadString (hDLL, IDS_SOLDIER, translatedName, 
  408.                          MAX_SCHEMA_NAME_BYTES-1);          
  409.              NWAAddClassData ("Soldier", translatedName, hBitmap, /*   #   */
  410.                               hAlias, hReadOnly);                 /*  # #  */
  411.                                                                   /* #   # */
  412.              LoadString (hDLL, IDS_RANK, translatedName,          /* ##### */
  413.                          MAX_SCHEMA_NAME_BYTES-1);                /* #   # */
  414.              NWAAddPropertyNameTranslation ("Rank",
  415.                                             "Soldier",         
  416.                                                translatedName); 
  417.  
  418.              // The following calls are for demonstration only--  /* ####  */
  419.              // They are NOT required at this point.              /* #   # */
  420.              NWAGetClassBitmap("Soldier", &hBitmap);              /* ####  */
  421.              NWAGetClassAliasBitmap("Soldier", &hBitmap);         /* #   # */
  422.              NWAGetClassReadOnlyBitmap("Soldier", &hBitmap);      /* ####  */
  423.  
  424.              return NWA_RET_SUCCESS;                   
  425.            }
  426.  
  427.       case NWA_MSG_GETVALIDOPERATIONS :                           /*  #### */
  428.            {                                                      /* #     */
  429.              /*------------------------------------------------*/ /* #     */
  430.              /* These are operations that are allowed on the   */ /* #     */
  431.              /* objects of Soldier class in the browser: the   */ /*  #### */
  432.              /* object may have details shown on it, it may be */
  433.              /* renamed, it may be deleted, DS rights may be   */
  434.              /* established and/or modified on it, and objects */
  435.              /* of the Soldier class may be created.           */
  436.              /*------------------------------------------------*/
  437.              return  (NWA_OP_DETAILS | NWA_OP_RENAME | NWA_OP_DELETE |
  438.                       NWA_OP_DSTYPE | NWA_OP_CREATE) ;
  439.            }
  440.  
  441.       case NWA_MSG_CREATEOBJECT:                                  /* ####  */
  442.            {                                                      /* #   # */
  443.              /*------------------------------------------------*/ /* #   # */
  444.              /* The Create dialog was just executed, and the   */ /* #   # */
  445.              /* Soldier icon was selected: put up a dialog for */ /* ####  */
  446.              /* entering the CN of a new Soldier object, then  */
  447.              /* create it using DS calls in AddSoldierObject().*/
  448.              /*------------------------------------------------*/
  449.              int      rcode;
  450.              int      retValue;
  451.  
  452.                  retValue = DialogBox (hDLL,  "DIALOG_SOLDIER_ADD", 
  453.                                               NULL, (DLGPROC)AddSoldierObjectDialogProc) ;
  454.              if  (retValue) 
  455.              {
  456.                lstrcat (nameBuf, ".");
  457.                lstrcat (nameBuf, name);
  458.                rcode = AddSoldierObject (nameBuf, theSurname);
  459.                if  (rcode) 
  460.                {
  461.                  //successfully added
  462.                  lstrcpy ((char*)p1, nameBuf);
  463.                  if  (createAnotherFlag) 
  464.                    return NWA_RET_CREATEANOTHER;
  465.                  else if  (showDetailsFlag) 
  466.                  {  
  467.                    showDetailsFlag=0;
  468.                    return NWA_RET_SHOWDETAILS;
  469.                  }
  470.                }
  471.                else
  472.                  return NWA_ERR_ERROR;
  473.              }
  474.              return NWA_RET_SUCCESS;
  475.            
  476.            }
  477.  
  478.       case NWA_MSG_GETPAGECOUNT:
  479.            {
  480.              /*------------------------------------------------*/
  481.              /* Initialize Soldier Data by reading it from NDS */
  482.              /*------------------------------------------------*/
  483.              lstrcpy (soldierObjData.name, name);
  484.              soldierObjData.surname[0]='\0';
  485.              soldierObjData.surnameChange[0]='\0';
  486.              soldierObjData.rank[0]='\0';
  487.              soldierObjData.rankChange[0]='\0';
  488.              soldierObjData.serialNo[0]='\0';
  489.              soldierObjData.serialNoChange[0]='\0';
  490.              
  491.              ReadObjectData();
  492.              return NUM_SOLDIER_PAGES;
  493.            }
  494.  
  495.       case NWA_MSG_REGISTERPAGE:
  496.            {
  497.              /*------------------------------------------------*/
  498.              /* Register the Nth page, as specified in p1, by  */
  499.              /* specifying its dialog procedure name, its      */
  500.              /* dialog resource name, and the page's title.    */
  501.              /*------------------------------------------------*/
  502.              NWAPageStruct  *pageInfo =   (NWAPageStruct *)p2;
  503.              pageInfo->dlgProc    = soldierPages[p1].dlgProc;
  504.              pageInfo->resName    = soldierPages[p1].resName;
  505.              pageInfo->pageTitle  = soldierPages[p1].pageTitle;
  506.              pageInfo->hDLL = hDLL;
  507.              pageInfo->initParam = 0;
  508.              return NWA_RET_SUCCESS;
  509.            }
  510.  
  511.       case NWA_MSG_MODIFY:
  512.            {
  513.              /*------------------------------------------------*/
  514.              /* The OK button was clicked on, and info on the  */
  515.              /* object was modified.  The DS is updated with   */
  516.              /* the changes in the function ModifyObjectData() */
  517.              /*------------------------------------------------*/
  518.              MessageBox (NULL, "NWA_MSG_MODIFY received", 
  519.                          "Soldier proc", MB_OK);
  520.              ModifyObjectData (name);
  521.              return NWA_RET_SUCCESS;
  522.            }
  523.  
  524.       case NWA_MSG_QUERYCOPY:                                     /* #   # */
  525.            {                                                      /* #   # */
  526.              /*------------------------------------------------*/ /* ##### */
  527.              /* Return NWA_RET_SUCCESS if you want the object  */ /* #   # */
  528.              /* copied; otherwise return NWA_ERR_ERROR.        */ /* #   # */
  529.              /*------------------------------------------------*/
  530.              MessageBox (NULL, "Copy the object.", 
  531.                          "Copy Object", MB_OK);
  532.              return NWA_RET_SUCCESS;
  533.            }
  534.  
  535.       case NWA_MSG_QUERYDELETE:                                   /*  ###  */
  536.            {                                                      /*   #   */
  537.              /*------------------------------------------------*/ /*   #   */
  538.              /* Return TRUE if you want the object deleted;    */ /*   #   */
  539.              /* otherwise return FALSE.                        */ /*  ###  */
  540.              /*------------------------------------------------*/
  541.              MessageBox (NULL, "Delete the object.", 
  542.                          "Delete Object", MB_OK);
  543.              return TRUE;
  544.            }
  545.  
  546.       case NWA_MSG_QUERYMOVE:                                     /*  ###  */
  547.            {                                                      /*   #   */
  548.              /*------------------------------------------------*/ /*   #   */
  549.              /* Return NWA_RET_SUCCESS if you want the object  */ /* # #   */
  550.              /* moved; otherwise return NWA_ERR_ERROR.         */ /* ###   */
  551.              /*------------------------------------------------*/
  552.              MessageBox (NULL, "Move the object.", 
  553.                          "Move Object", MB_OK);
  554.              return TRUE;
  555.            }
  556.  
  557.       case NWA_MSG_RENAME:                                        /* #   # */
  558.            {                                                      /* #  #  */
  559.              /*------------------------------------------------*/ /* ###   */
  560.              /* Just do the default DS renaming operation, with*/ /* #  #  */
  561.              /* no side-effects or application-specific        */ /* #   # */
  562.              /* validation                                     */
  563.              /*------------------------------------------------*/
  564.              MessageBox (NULL, "NWA_MSG_RENAME received", 
  565.                          "Rename Object", MB_OK);
  566.              return NWA_RET_DODEFAULT;
  567.            }
  568.  
  569.       case NWA_MSG_CLOSESNAPIN:
  570.            {
  571.              /*------------------------------------------------*/
  572.              /*      unregister bitmaps and delete them        */
  573.              /*------------------------------------------------*/
  574.                                                                
  575.              NWARemoveClassData ("Soldier", &hBitmap,             /* #     */
  576.                                  &hAlias, &hReadOnly);            /* #     */
  577.              if (hBitmap)                                         /* #     */
  578.                DeleteObject (hBitmap);                            /* #     */
  579.              if (hAlias)                                          /* ##### */
  580.                DeleteObject (hAlias);
  581.              if (hReadOnly)
  582.                DeleteObject (hReadOnly);
  583.              NWARemovePropertyNameTranslation("Rank", "Soldier"); /* #   # */
  584.              MessageBox (NULL, "NWA_MSG_CLOSESNAPIN received",    /* ## ## */
  585.                               "Soldier proc", MB_OK);             /* # # # */
  586.              return NWA_RET_SUCCESS;                              /* #   # */
  587.            }                                                      /* #   # */
  588.  
  589.       default:
  590.            break;
  591.    }
  592.    return NWA_RET_SUCCESS;
  593. }
  594.  
  595. /*-------------------------------------------------------------------------*/
  596. /* Function : AddSoldierObject (objectName, spouseDN)                      */
  597. /* Description :                                                           */
  598. /*   The Create dialog was just executed.  Create a new object of class    */
  599. /*   Soldier in DS with the name specified.                                */
  600. /*-------------------------------------------------------------------------*/
  601. BOOL AddSoldierObject (char *objName, char *surname)
  602. {
  603.    UINT                dsErr=0;
  604.    Buf_T              *ObjectInfo;
  605.    NWDSContextHandle   context;
  606.    uint32              flags;
  607.  
  608.    context = NWDSCreateContext();
  609.    dsErr = NWDSSetContext (context, DCK_NAME_CONTEXT, DS_ROOT_NAME);
  610.    dsErr = NWDSGetContext (context, DCK_FLAGS, (void *)&flags);
  611.  
  612.    flags |= DCV_TYPELESS_NAMES;
  613.    flags |= DCV_XLATE_STRINGS;
  614.    flags |= DCV_DEREF_ALIASES;
  615.    flags |= DCV_DEREF_BASE_CLASS;
  616.  
  617.    dsErr   = NWDSSetContext (context, DCK_FLAGS, (void *)&flags) ;
  618.  
  619.    dsErr = NWDSAllocBuf (DEFAULT_MESSAGE_LEN, &ObjectInfo);
  620.    dsErr = NWDSInitBuf (context, DSV_ADD_ENTRY, ObjectInfo);
  621.    if (ObjectInfo)
  622.    {
  623.       dsErr = NWDSPutAttrName (context, ObjectInfo, "Object Class");                                                                              
  624.       dsErr = NWDSPutAttrVal (context, ObjectInfo, SYN_CLASS_NAME, 
  625.                               "Soldier");
  626.       dsErr = NWDSPutAttrName (context, ObjectInfo, "Surname");                                                                              
  627.       dsErr = NWDSPutAttrVal (context, ObjectInfo, SYN_CI_STRING, surname);
  628.       dsErr = NWDSAddObject (context, objName, NULL, 0, ObjectInfo);
  629.       NWDSFreeBuf (ObjectInfo);
  630.    }
  631.    NWDSFreeContext (context);
  632.    if (dsErr)
  633.       return FALSE;
  634.    else
  635.       return TRUE;
  636. }
  637. /*-------------------------------------------------------------------------*/
  638. /* Function : AddSoldierObjectDialogProc (void)                            */
  639. /* Description :                                                           */
  640. /*    Dialog Procedure for the Create Soldier object dialog                */
  641. /*-------------------------------------------------------------------------*/
  642. BOOL _export FAR PASCAL AddSoldierObjectDialogProc (HWND hwnd, UINT message, 
  643.                                         WPARAM wParam, LPARAM lParam)
  644. {
  645.    int state;
  646.    switch (message)
  647.    {
  648.       case WM_INITDIALOG:
  649.         {
  650.           nameBuf[0]='\0';
  651.           SendDlgItemMessage (hwnd, IDC_ADD_ANOTHER, BM_SETCHECK,
  652.                              createAnotherFlag, 0L);
  653.           SendDlgItemMessage (hwnd, IDC_ADD_DETAILS, BM_SETCHECK,
  654.                              showDetailsFlag, 0L);
  655.           return TRUE;
  656.         }
  657.  
  658.       case WM_COMMAND:
  659.         {
  660.           switch (wParam) 
  661.           {
  662.             case IDC_CREATE :
  663.               GetDlgItemText (hwnd, IDC_SOLDIER_NAME, nameBuf, 255);
  664.               GetDlgItemText (hwnd, IDC_SURNAME, theSurname, 255);
  665.               createAnotherFlag=(int)SendDlgItemMessage (hwnd, 
  666.                                                         IDC_ADD_ANOTHER, 
  667.                                                         BM_GETCHECK, 0, 0L);
  668.               showDetailsFlag=(int)SendDlgItemMessage (hwnd, IDC_ADD_DETAILS, 
  669.                                                       BM_GETCHECK, 0, 0L);
  670.               EndDialog (hwnd, TRUE);
  671.               return TRUE;
  672.  
  673.             case IDC_CANCEL :
  674.               createAnotherFlag=0;
  675.               showDetailsFlag=0;
  676.               EndDialog (hwnd, FALSE);
  677.               return TRUE;
  678.  
  679.             case IDC_ADD_DETAILS :
  680.               /*-------------------------------------------------*/
  681.               /* Automatically brings up details on the newly    */
  682.               /* created object once created, if checked         */
  683.               /*-------------------------------------------------*/
  684.               state =(int)  SendDlgItemMessage (hwnd, IDC_ADD_DETAILS, 
  685.                                          BM_GETCHECK, 0, 0L);
  686.               SendDlgItemMessage (hwnd, IDC_ADD_DETAILS, BM_SETCHECK,
  687.                                  !state, 0L);
  688.               if  (!state) 
  689.                 SendDlgItemMessage (hwnd, IDC_ADD_ANOTHER, BM_SETCHECK,
  690.                                    state, 0L);
  691.               EnableWindow (GetDlgItem (hwnd, IDC_ADD_ANOTHER), state);
  692.               break;
  693.  
  694.             case IDC_ADD_ANOTHER :
  695.               /*-------------------------------------------------*/
  696.               /* Automatically brings up this create dialog      */
  697.               /* again once this object is created, allowing the */
  698.               /* administrator to add many objects of one class  */
  699.               /* until the "add another" checkbox is unchecked.  */
  700.               /*-------------------------------------------------*/
  701.               state =  (int)  SendDlgItemMessage (hwnd, IDC_ADD_ANOTHER, 
  702.                                          BM_GETCHECK, 0, 0L);
  703.               SendDlgItemMessage (hwnd, IDC_ADD_ANOTHER, BM_SETCHECK,
  704.                                  !state, 0L);
  705.               EnableWindow (GetDlgItem (hwnd, IDC_ADD_DETAILS), state);
  706.               break;
  707.           }
  708.         }
  709.  
  710.         return TRUE;
  711.  
  712.    }
  713.    return FALSE ;
  714. }
  715.  
  716. /*-------------------------------------------------------------------------*/
  717. /* Function : SoldierIdentificationDlg                                     */
  718. /* Description :                                                           */
  719. /*  Identification Page Dialog Proc                                        */
  720. /*-------------------------------------------------------------------------*/
  721. BOOL _export FAR PASCAL SoldierIdentificationDlg (HWND hwnd, UINT message, 
  722.                                         WPARAM wParam, LPARAM lParam)
  723. {
  724.    switch (message)
  725.    {
  726.       case WM_INITDIALOG:
  727.         {
  728.           /*-------------------------------------------------*/
  729.           /* Initialize the dialog by inserting current DS   */
  730.           /* values into the controls on the identification  */
  731.           /* page.  These values were previously fetched     */
  732.           /* from DS by the ReadData() function.             */
  733.           /*-------------------------------------------------*/
  734.           soldierObjData.hDialogIdent = hwnd;
  735.           SetDlgItemText (hwnd, IDC_NAME, soldierObjData.name);
  736.           SendDlgItemMessage (hwnd, IDC_SURNAME, EM_LIMITTEXT, 255, 0L);
  737.           SetDlgItemText (hwnd, IDC_SURNAME, soldierObjData.surname);
  738.           SendDlgItemMessage (hwnd, IDC_RANK, EM_LIMITTEXT, 63, 0L);
  739.           SetDlgItemText (hwnd, IDC_RANK, soldierObjData.rank);
  740.           SendDlgItemMessage (hwnd, IDC_SERIALNO, EM_LIMITTEXT, 63, 0L);
  741.           SetDlgItemText (hwnd, IDC_SERIALNO, soldierObjData.serialNo);
  742.           return TRUE;
  743.         }
  744.  
  745.       case NWA_WM_F1HELP:
  746.         {
  747.           MessageBox (NULL, "Identification Page help", "Snapin Help", 
  748.                       MB_OK);
  749.           return TRUE;
  750.         }
  751.  
  752.       case WM_COMMAND:
  753.           switch (wParam)
  754.           {
  755.            /*-------------------------------------------------*/
  756.            /* Handle messages from the controls on the page.  */
  757.            /* If any of the edit controls is changed, flag    */
  758.            /* the page as modified (which shows as a black    */
  759.            /* corner on the page icon, and enabling of the OK */
  760.            /* button, if not already enabled.                 */
  761.            /* The MVED control is already inextricably linked */
  762.            /* to the page, and does its message interaction   */
  763.            /* with the page automatically.                    */
  764.            /*-------------------------------------------------*/
  765.            case IDC_SURNAME:
  766.                 if (HIWORD (lParam) == EN_CHANGE)
  767.                 {
  768.                    SendMessage (hwnd, NWA_WM_SETPAGEMODIFY, (WORD)hwnd, 
  769.                                 MAKELONG (0,TRUE));
  770.                    GetDlgItemText (hwnd, IDC_SURNAME, 
  771.                                    soldierObjData.surnameChange, 255);
  772.                 }   
  773.                 break;
  774.            case IDC_RANK:
  775.                 if (HIWORD (lParam) == EN_CHANGE)
  776.                 {
  777.                    SendMessage (hwnd, NWA_WM_SETPAGEMODIFY, (WORD)hwnd, 
  778.                                 MAKELONG (0,TRUE));
  779.                    GetDlgItemText (hwnd, IDC_RANK, 
  780.                                    soldierObjData.rankChange, 63);
  781.                 }   
  782.                 break;
  783.            case IDC_SERIALNO:
  784.                 if (HIWORD (lParam) == EN_CHANGE)
  785.                 {
  786.                    SendMessage (hwnd, NWA_WM_SETPAGEMODIFY, (WORD)hwnd, 
  787.                                 MAKELONG (0,TRUE));
  788.                    GetDlgItemText (hwnd, IDC_SERIALNO, 
  789.                                    soldierObjData.serialNoChange, 63);
  790.                 }   
  791.                 break;
  792.           }
  793.         break;
  794.  
  795.       case NWA_WM_CANCLOSE:
  796.         {
  797.            /*-------------------------------------------------*/
  798.            /* Transfer modified data from the dialog's        */
  799.            /* controls to a global data structure, before the */
  800.            /* page dialog goes away.                          */
  801.            /*-------------------------------------------------*/
  802.           int i;
  803.           GetDlgItemText (hwnd, IDC_SURNAME, soldierObjData.surnameChange, 
  804.                           127);
  805.           GetDlgItemText (hwnd, IDC_RANK, soldierObjData.rankChange, 127);
  806.           GetDlgItemText (hwnd, IDC_SERIALNO, soldierObjData.serialNoChange, 
  807.                           127);
  808.           return TRUE;
  809.         }
  810.    }
  811.    return FALSE ;
  812. }
  813.  
  814. /*------------------------------------------------------------------------*/
  815. /* Function : AddSoldierClassDefinition                                   */
  816. /* Description :                                                          */
  817. /*   Adds the Soldier object class in the DS schema                       */
  818. /*   class Name  : Soldier                                                */
  819. /*   super class : Person                                                 */
  820. /*                                                                        */
  821. /*   Optional Attributes Added :                                          */
  822. /*       Spouse                 : SYN_DIST_NAME        (single-valued)    */
  823. /*       Rank                   : SYN_CI_STRING        (single-valued)    */
  824. /*       Military Serial Number : SYN_CI_STRING        (single-valued)    */
  825. /*       Commanding Officer     : SYN_DIST_NAME        (multi-valued)     */
  826. /*------------------------------------------------------------------------*/
  827. NWRCODE AddSoldierClassDefinition()
  828. {
  829.   NWDSContextHandle context;
  830.   int               err=0;
  831.   Class_Info_T      classInfo;
  832.   Attr_Info_T       attrInfo;
  833.   Buf_T             *classBuf;
  834.   char              attrName[MAX_SCHEMA_NAME_CHARS+2];   
  835.   char              className[MAX_SCHEMA_NAME_CHARS+2];
  836.   char              superClass[MAX_SCHEMA_NAME_CHARS+2];
  837.   char              contClass[MAX_SCHEMA_NAME_CHARS+2];
  838.   char              nameAttr[MAX_SCHEMA_NAME_CHARS+2];
  839.   char              manAttr[MAX_SCHEMA_NAME_CHARS+2];
  840.   char              optAttr[MAX_SCHEMA_NAME_CHARS+2];
  841.  
  842.  
  843.   context = NWDSCreateContext();
  844.   if  (context == (NWDSContextHandle) ERR_CONTEXT_CREATION) 
  845.     return  ((NWRCODE) context) ;
  846.  
  847.   memset (&attrInfo, (int) '\0', sizeof (Attr_Info_T));
  848.   attrInfo.asn1ID.length = 0;
  849.   memset (attrInfo.asn1ID.data, 0, MAX_ASN1_NAME);
  850.  
  851.   /*-------------------------------------------------*/
  852.   /* Add the Spouse attribute to the schema          */
  853.   /*-------------------------------------------------*/
  854.   attrInfo.attrFlags = DS_SINGLE_VALUED_ATTR;
  855.   attrInfo.attrSyntaxID = SYN_DIST_NAME;
  856.   strcpy (attrName, "Spouse");
  857.  
  858.   err = NWDSDefineAttr (context, attrName, &attrInfo);
  859.   if (err < 0) 
  860.   {
  861.     return ((NWRCODE) err) ;
  862.   }
  863.  
  864.   /*-------------------------------------------------*/
  865.   /* Add the Rank attribute to the schema            */
  866.   /*-------------------------------------------------*/
  867.   attrInfo.attrFlags = DS_SINGLE_VALUED_ATTR;
  868.   attrInfo.attrSyntaxID = SYN_CI_STRING;
  869.   strcpy (attrName, "Rank");
  870.  
  871.   err = NWDSDefineAttr (context, attrName, &attrInfo);
  872.   if (err < 0) 
  873.   {
  874.     return ((NWRCODE) err) ;
  875.   }
  876.  
  877.   /*-------------------------------------------------*/
  878.   /* Add the Military Serial Number attribute to the */
  879.   /* schema                                          */
  880.   /*-------------------------------------------------*/
  881.   attrInfo.attrFlags = DS_SINGLE_VALUED_ATTR;
  882.   attrInfo.attrSyntaxID = SYN_CI_STRING;
  883.   strcpy (attrName, "Military Serial Number");
  884.  
  885.   err = NWDSDefineAttr (context, attrName, &attrInfo);
  886.   if (err < 0) 
  887.   {
  888.     return ((NWRCODE) err) ;
  889.   }
  890.  
  891.   /*-------------------------------------------------*/
  892.   /* Add the Commanding Officer attribute to the     */
  893.   /* schema                                          */
  894.   /*-------------------------------------------------*/
  895.   attrInfo.attrFlags = 0;   // (default is multi-valued)
  896.   attrInfo.attrSyntaxID = SYN_DIST_NAME;
  897.   strcpy (attrName, "Commanding Officer");
  898.  
  899.   err = NWDSDefineAttr (context, attrName, &attrInfo);
  900.   if (err < 0) 
  901.   {
  902.     return ((NWRCODE) err) ;
  903.   }
  904.  
  905.   /*-------------------------------------------------*/
  906.   /* Now, define the Soldier class in the schema.    */
  907.   /* The buffer is built in five "string arrays":    */
  908.   /* 1. Super Class names                            */
  909.   /* 2. Containment Class names                      */
  910.   /* 3. Naming Attribute names                       */
  911.   /* 4. Mandatory Attribute names                    */
  912.   /* 5. Optional Attribute names                     */
  913.   /* But first, get the DS buffer allocated, etc.    */
  914.   /*-------------------------------------------------*/
  915.   strcpy (className, "Soldier");
  916.   strcpy (superClass, "Person");
  917.  
  918.   classInfo.classFlags = 2;
  919.   classInfo.asn1ID.length = 32;
  920.   memset (&classInfo.asn1ID, 0x00, sizeof (Asn1ID_T));
  921.  
  922.   err = NWDSAllocBuf (DEFAULT_MESSAGE_LEN, &classBuf);
  923.   if (err < 0) 
  924.   {
  925.     return  ( (NWRCODE)  err) ;
  926.   }
  927.  
  928.   err = NWDSInitBuf (context, DSV_DEFINE_CLASS, classBuf);
  929.   if (err < 0) 
  930.   {
  931.    return  ( (NWRCODE)  err) ;
  932.   }
  933.   
  934.   /*-------------------------------------------------*/
  935.   /* 1. entries for super class names                */
  936.   /*-------------------------------------------------*/
  937.   err = NWDSBeginClassItem (context, classBuf);
  938.   if (err < 0) 
  939.   {
  940.     return  ( (NWRCODE)  err) ;
  941.   }
  942.  
  943.   err = NWDSPutClassItem (context, classBuf, superClass);
  944.   if (err < 0) 
  945.   {
  946.     return  ( (NWRCODE)  err) ;
  947.   }
  948.  
  949.   /*-------------------------------------------------*/
  950.   /* 2. entries for containment class names          */
  951.   /*-------------------------------------------------*/
  952.   err = NWDSBeginClassItem (context, classBuf);
  953.   if (err < 0) 
  954.   {
  955.     return  ( (NWRCODE)  err) ;
  956.   }
  957.  
  958.   strcpy (contClass, "Organization");
  959.   err = NWDSPutClassItem (context, classBuf, contClass);
  960.   if (err < 0) 
  961.   {
  962.     return  ( (NWRCODE)  err) ;
  963.   }
  964.  
  965.   strcpy (contClass, "Organizational Unit");
  966.   err = NWDSPutClassItem (context, classBuf, contClass);
  967.   if (err < 0) 
  968.   {
  969.     return  ( (NWRCODE)  err) ;
  970.   }
  971.  
  972.   /*-------------------------------------------------*/
  973.   /* 3. entries for naming attribute names           */
  974.   /*-------------------------------------------------*/
  975.   err = NWDSBeginClassItem (context, classBuf);
  976.   if (err < 0) 
  977.   {
  978.     return  ( (NWRCODE)  err) ;
  979.   }
  980.  
  981.   strcpy (nameAttr, "CN");
  982.   err = NWDSPutClassItem (context, classBuf, nameAttr);
  983.   if (err < 0) 
  984.   {
  985.     return  ( (NWRCODE)  err) ;
  986.   }
  987.  
  988.   /*-------------------------------------------------*/
  989.   /* 4. entries for mandatory attribute names        */
  990.   /*    (no additional mandatory attributes)         */
  991.   /*-------------------------------------------------*/
  992.   err = NWDSBeginClassItem (context, classBuf);
  993.   if (err < 0) 
  994.   {
  995.     return  ( (NWRCODE)  err) ;
  996.   }
  997.  
  998.   /*-------------------------------------------------*/
  999.   /* 5. entries for optional attribute names         */
  1000.   /*    (four of them)                               */
  1001.   /*-------------------------------------------------*/
  1002.   err = NWDSBeginClassItem (context, classBuf);
  1003.   if (err < 0) 
  1004.   {
  1005.     return  ( (NWRCODE)  err) ;
  1006.   }
  1007.  
  1008.   strcpy (optAttr, "Spouse");
  1009.   err = NWDSPutClassItem (context, classBuf, optAttr);
  1010.   if (err < 0) 
  1011.   {
  1012.     return  ( (NWRCODE)  err) ;
  1013.   }
  1014.  
  1015.   strcpy (optAttr, "Rank");
  1016.   err = NWDSPutClassItem (context, classBuf, optAttr);
  1017.   if (err < 0) 
  1018.   {
  1019.     return  ( (NWRCODE)  err) ;
  1020.   }
  1021.  
  1022.   strcpy (optAttr, "Military Serial Number");
  1023.   err = NWDSPutClassItem (context, classBuf, optAttr);
  1024.   if (err < 0) 
  1025.   {
  1026.     return  ( (NWRCODE)  err) ;
  1027.   }
  1028.  
  1029.   strcpy (optAttr, "Commanding Officer");
  1030.   err = NWDSPutClassItem (context, classBuf, optAttr);
  1031.   if (err < 0) 
  1032.   {
  1033.     return  ( (NWRCODE)  err) ;
  1034.   }
  1035.  
  1036.   /*-------------------------------------------------*/
  1037.   /* Now, define the class in the schema, now that   */
  1038.   /* buffer is completed.                            */
  1039.   /*-------------------------------------------------*/
  1040.   err = NWDSDefineClass (context, className, &classInfo, classBuf);
  1041.   if (err < 0) 
  1042.   {
  1043.     return  ( (NWRCODE)  err) ;
  1044.   }
  1045.  
  1046.   NWDSFreeBuf (classBuf);
  1047.   NWDSFreeContext (context);
  1048.   return (err);
  1049. }
  1050.  
  1051. /*-------------------------------------------------------------------------*/
  1052. /* Function : RemoveSoldierClassDefinition                                 */
  1053. /* Description :                                                           */
  1054. /*  Removes the class definition from the DS schema                        */
  1055. /*-------------------------------------------------------------------------*/
  1056. NWRCODE RemoveSoldierClassDefinition()
  1057. {
  1058.   NWDSContextHandle context;
  1059.   int               err=0;
  1060.   char className[MAX_SCHEMA_NAME_CHARS+2];
  1061.   char attrName[MAX_SCHEMA_NAME_CHARS+2];
  1062.  
  1063.   context = NWDSCreateContext();
  1064.   if  (context == (NWDSContextHandle) ERR_CONTEXT_CREATION) 
  1065.     return  ((NWRCODE) context) ;
  1066.  
  1067.   /*-------------------------------------------------*/
  1068.   /* First, remove the Soldier class definition from */
  1069.   /* the schema.                                     */
  1070.   /*-------------------------------------------------*/
  1071.   strcpy (className, "Soldier");
  1072.  
  1073.   err = NWDSRemoveClassDef (context, className);
  1074.   if (err < 0) 
  1075.   {
  1076.     return  ( (NWRCODE)  err) ;
  1077.   }
  1078.  
  1079.   /*-------------------------------------------------*/
  1080.   /* Now, remove all of the attributes that we       */
  1081.   /* defined when we defined the Soldier class       */
  1082.   /*-------------------------------------------------*/
  1083.   strcpy (attrName, "Spouse");
  1084.   err = NWDSRemoveAttrDef (context, attrName);
  1085.   if (err < 0) 
  1086.   {
  1087.     return  ( (NWRCODE)  err) ;
  1088.   }
  1089.  
  1090.   strcpy (attrName, "Rank");
  1091.   err = NWDSRemoveAttrDef (context, attrName);
  1092.   if (err < 0) 
  1093.   {
  1094.     return  ( (NWRCODE)  err) ;
  1095.   }
  1096.  
  1097.   strcpy (attrName, "Military Serial Number");
  1098.   err = NWDSRemoveAttrDef (context, attrName);
  1099.   if (err < 0) 
  1100.   {
  1101.     return  ( (NWRCODE)  err) ;
  1102.   }
  1103.  
  1104.   strcpy (attrName, "Commanding Officer");
  1105.   err = NWDSRemoveAttrDef (context, attrName);
  1106.   if (err < 0) 
  1107.   {
  1108.     return  ( (NWRCODE)  err) ;
  1109.   }
  1110.  
  1111.   NWDSFreeContext (context);
  1112.   return (err);
  1113. }
  1114.  
  1115. /*-------------------------------------------------------------------------*/
  1116. /* Function : ReadObjectData                                               */
  1117. /* Description :                                                           */
  1118. /*   Function for reading / modifying object data in DS                    */
  1119. /*-------------------------------------------------------------------------*/
  1120. int ReadObjectData()
  1121. {
  1122.   NWDSContextHandle context;
  1123.   int               err=0, i, j;
  1124.   int32             iterHandle=-1L;
  1125.   Buf_T             *resBuf, *nameBuf;
  1126.   char              *attributes[]={"Surname",
  1127.                                    "Rank", 
  1128.                                    "Military Serial Number"};
  1129.   uint32            totAttr, valCount, synID;
  1130.   char              attrName[MAX_DN_CHARS+1];
  1131.   uint32            flags;
  1132.  
  1133.   totAttr = sizeof (attributes) / sizeof (attributes[0]);
  1134.   context = NWDSCreateContext();
  1135.   if  (context == (NWDSContextHandle) ERR_CONTEXT_CREATION) 
  1136.     return  ((int) context) ;
  1137.  
  1138.   err=NWDSSetContext (context, DCK_NAME_CONTEXT, DS_ROOT_NAME);
  1139.   if  (err < 0) 
  1140.   {
  1141.     NWDSFreeContext (context);
  1142.     return err;
  1143.   }
  1144.  
  1145.   err = NWDSGetContext (context, DCK_FLAGS, (void *)&flags);
  1146.   if  (err < 0) 
  1147.   {
  1148.     NWDSFreeContext (context);
  1149.     return err;
  1150.   }
  1151.  
  1152.   flags |= DCV_TYPELESS_NAMES;
  1153.   flags |= DCV_XLATE_STRINGS;
  1154.   flags |= DCV_DEREF_ALIASES;
  1155.   flags |= DCV_DEREF_BASE_CLASS;
  1156.  
  1157.   err   = NWDSSetContext (context, DCK_FLAGS, (void *)&flags) ;
  1158.   if  (err < 0) 
  1159.   {
  1160.     NWDSFreeContext (context);
  1161.     return err;
  1162.   }
  1163.  
  1164.   /*-------------------------------------------------------*/
  1165.   /* There are two buffers: one used to send the names of  */
  1166.   /* attributes we are interested in, and the other to     */
  1167.   /* receive the values of those attributes for the        */
  1168.   /* specified Soldier object.                             */
  1169.   /*-------------------------------------------------------*/
  1170.   err=NWDSAllocBuf (DEFAULT_MESSAGE_LEN, &resBuf);
  1171.   if  (err < 0) 
  1172.   {
  1173.     NWDSFreeContext (context);
  1174.     return err;
  1175.   }
  1176.  
  1177.   err=NWDSAllocBuf (DEFAULT_MESSAGE_LEN, &nameBuf);
  1178.   if  (err < 0) 
  1179.   {
  1180.     NWDSFreeContext (context);
  1181.     NWDSFreeBuf (resBuf);
  1182.     return err;
  1183.   }
  1184.   
  1185.   /*-------------------------------------------------------*/
  1186.   /* Initialize input buffer and check for errors. The     */
  1187.   /* output buffer does not need to be initialized. This   */
  1188.   /* buffer will be initialized to DSV_READ operations.    */
  1189.   /*-------------------------------------------------------*/
  1190.  
  1191.   err=NWDSInitBuf (context, DSV_READ, nameBuf);
  1192.   if  (err < 0) 
  1193.   {
  1194.     NWDSFreeContext (context);
  1195.     NWDSFreeBuf (resBuf);
  1196.     NWDSFreeBuf (nameBuf);
  1197.     return err;
  1198.   }
  1199.  
  1200.   /*-------------------------------------------------------*/
  1201.   /* Put object attributes that are to be read into the    */
  1202.   /* input buffer.                                         */
  1203.   /*-------------------------------------------------------*/
  1204.   for (i=0; i < totAttr; i++)
  1205.   {
  1206.     err= NWDSPutAttrName (context, nameBuf, attributes[i]);
  1207.     if  (err < 0) 
  1208.     {
  1209.       NWDSFreeContext (context);
  1210.       NWDSFreeBuf (resBuf);
  1211.       NWDSFreeBuf (nameBuf);
  1212.       return err;
  1213.     }
  1214.   }
  1215.  
  1216.   /*-------------------------------------------------------*/
  1217.   /* Read the data.                                        */
  1218.   /*-------------------------------------------------------*/
  1219.  
  1220.   iterHandle=NO_MORE_ITERATIONS;
  1221.   do
  1222.   {
  1223.     err=NWDSRead (context, soldierObjData.name, DS_ATTRIBUTE_VALUES,
  1224.                  FALSE, nameBuf, &iterHandle, resBuf);
  1225.     if  (err < 0) 
  1226.     {
  1227.       NWDSFreeContext (context);
  1228.       NWDSFreeBuf (resBuf);
  1229.       NWDSFreeBuf (nameBuf);
  1230.       return err;
  1231.     }
  1232.     
  1233.     /*-----------------------------------------------------*/
  1234.     /* pull stuff out of the output buffer, checking for   */
  1235.     /* errors.  First, get total number of attributes in   */
  1236.     /* the buffer.                                         */
  1237.     /*-----------------------------------------------------*/
  1238.     err=NWDSGetAttrCount (context, resBuf, &totAttr);
  1239.     if  (err < 0) 
  1240.     {
  1241.       NWDSFreeContext (context);
  1242.       NWDSFreeBuf (resBuf);
  1243.       NWDSFreeBuf (nameBuf);
  1244.       return err;
  1245.     }
  1246.  
  1247.     for (i=0; i< totAttr; i++)
  1248.     {
  1249.       err=NWDSGetAttrName (context, resBuf, attrName, &valCount, &synID);
  1250.       if  (err < 0) 
  1251.       {
  1252.         NWDSFreeContext (context);
  1253.         NWDSFreeBuf (resBuf);
  1254.         NWDSFreeBuf (nameBuf);
  1255.         return err;
  1256.       }
  1257.  
  1258.       if  (lstrcmp (attrName, "Surname") == 0) 
  1259.       {
  1260.         err=NWDSGetAttrVal (context, resBuf, synID, soldierObjData.surname);
  1261.         if  (err < 0) 
  1262.         {
  1263.           NWDSFreeContext (context);
  1264.           NWDSFreeBuf (resBuf);
  1265.           NWDSFreeBuf (nameBuf);
  1266.           return err;
  1267.         }
  1268.       }
  1269.       else if  (lstrcmp (attrName, "Rank") == 0) 
  1270.       {
  1271.         err=NWDSGetAttrVal (context, resBuf, synID, soldierObjData.rank);
  1272.         if  (err < 0) 
  1273.         {
  1274.           NWDSFreeContext (context);
  1275.           NWDSFreeBuf (resBuf);
  1276.           NWDSFreeBuf (nameBuf);
  1277.           return err;
  1278.         }
  1279.       }
  1280.       else if  (lstrcmp (attrName, "Military Serial Number") == 0) 
  1281.       {
  1282.         err=NWDSGetAttrVal (context, resBuf, synID, soldierObjData.serialNo);
  1283.         if  (err < 0) 
  1284.         {
  1285.           NWDSFreeContext (context);
  1286.           NWDSFreeBuf (resBuf);
  1287.           NWDSFreeBuf (nameBuf);
  1288.           return err;
  1289.         }
  1290.       }
  1291.     }
  1292.   } while  (iterHandle != NO_MORE_ITERATIONS) ;
  1293.  
  1294.   NWDSFreeContext (context);
  1295.   NWDSFreeBuf (resBuf);
  1296.   NWDSFreeBuf (nameBuf);
  1297.   return 0;
  1298. }
  1299.  
  1300.  
  1301. /*-------------------------------------------------------------------------*/
  1302. /* Function : ModifyObjectData (void)                                      */
  1303. /* Description :                                                           */
  1304. /*  Modifies a Soldier Object's Attribute Values                           */
  1305. /*-------------------------------------------------------------------------*/
  1306. int ModifyObjectData (char *name)
  1307. {
  1308.   NWDSContextHandle context;
  1309.   int               err=0, i, j;
  1310.   Buf_T             *inpBuf;
  1311.   uint32            flags;
  1312.   uint32            syntaxID;
  1313.  
  1314.   context = NWDSCreateContext();
  1315.   if  (context == (NWDSContextHandle) ERR_CONTEXT_CREATION) 
  1316.     return ((int) context);
  1317.  
  1318.   err=NWDSSetContext (context, DCK_NAME_CONTEXT, DS_ROOT_NAME);
  1319.   if  (err < 0) 
  1320.   {
  1321.     NWDSFreeContext (context);
  1322.     return err;
  1323.   }
  1324.   
  1325.   err = NWDSGetContext (context, DCK_FLAGS, (void *)&flags);
  1326.  
  1327.   flags |= DCV_TYPELESS_NAMES;
  1328.   flags |= DCV_XLATE_STRINGS;
  1329.   flags |= DCV_DEREF_ALIASES;
  1330.   flags |= DCV_DEREF_BASE_CLASS;
  1331.  
  1332.   err   = NWDSSetContext (context, DCK_FLAGS, (void *)&flags) ;
  1333.  
  1334.   err=NWDSAllocBuf (DEFAULT_MESSAGE_LEN, &inpBuf);
  1335.   if  (err < 0) 
  1336.   {
  1337.     NWDSFreeContext (context);
  1338.     return err;
  1339.   }
  1340.  
  1341.   err=NWDSInitBuf (context, DSV_MODIFY_ENTRY, inpBuf);
  1342.   if  (err < 0) 
  1343.   {
  1344.     NWDSFreeContext (context);
  1345.     NWDSFreeBuf (inpBuf);
  1346.     return err;
  1347.   }
  1348.  
  1349.   /*------------------------------------------------------------*/
  1350.   /* Handle modifications of the Surname attribute              */
  1351.   /*------------------------------------------------------------*/
  1352.   if (strcmp (soldierObjData.surname, soldierObjData.surnameChange) != 0)
  1353.   {
  1354.     if  (soldierObjData.surname[0]) 
  1355.     {
  1356.       err = NWDSPutChange (context, inpBuf, DS_REMOVE_VALUE, "Surname");
  1357.       if  (err < 0) 
  1358.       {
  1359.         NWDSFreeContext (context);
  1360.         NWDSFreeBuf (inpBuf);
  1361.         return err;
  1362.       }
  1363.  
  1364.       err = NWDSPutAttrVal (context, inpBuf, SYN_CI_STRING, 
  1365.                             soldierObjData.surname);
  1366.       if  (err < 0) 
  1367.       {
  1368.         NWDSFreeContext (context);
  1369.         NWDSFreeBuf (inpBuf);
  1370.         return err;
  1371.       }
  1372.     }
  1373.     err = NWDSPutChange (context, inpBuf, DS_ADD_VALUE, "Surname");
  1374.     if  (err < 0) 
  1375.     {
  1376.       NWDSFreeContext (context);
  1377.       NWDSFreeBuf (inpBuf);
  1378.       return err;
  1379.     }
  1380.  
  1381.     err = NWDSPutAttrVal (context, inpBuf, SYN_CI_STRING, 
  1382.                           soldierObjData.surnameChange);
  1383.     if  (err < 0) 
  1384.     {
  1385.       NWDSFreeContext (context);
  1386.       NWDSFreeBuf (inpBuf);
  1387.       return err;
  1388.     }
  1389.   }
  1390.  
  1391.   /*------------------------------------------------------------*/
  1392.   /* Handle modifications of the Rank attribute                 */
  1393.   /*------------------------------------------------------------*/
  1394.   if (strcmp (soldierObjData.rank, soldierObjData.rankChange) != 0)
  1395.   {
  1396.     if  (soldierObjData.rank[0]) 
  1397.     {
  1398.       err = NWDSPutChange (context, inpBuf, DS_REMOVE_VALUE, "Rank");
  1399.       if  (err < 0) 
  1400.       {
  1401.         NWDSFreeContext (context);
  1402.         NWDSFreeBuf (inpBuf);
  1403.         return err;
  1404.       }
  1405.  
  1406.       err = NWDSPutAttrVal (context, inpBuf, SYN_CI_STRING, 
  1407.                             soldierObjData.rank);
  1408.       if  (err < 0) 
  1409.       {
  1410.         NWDSFreeContext (context);
  1411.         NWDSFreeBuf (inpBuf);
  1412.         return err;
  1413.       }
  1414.     }
  1415.     err = NWDSPutChange (context, inpBuf, DS_ADD_VALUE, "Rank");
  1416.     if  (err < 0) 
  1417.     {
  1418.       NWDSFreeContext (context);
  1419.       NWDSFreeBuf (inpBuf);
  1420.       return err;
  1421.     }
  1422.  
  1423.     err = NWDSPutAttrVal (context, inpBuf, SYN_CI_STRING, 
  1424.                           soldierObjData.rankChange);
  1425.     if  (err < 0) 
  1426.     {
  1427.       NWDSFreeContext (context);
  1428.       NWDSFreeBuf (inpBuf);
  1429.       return err;
  1430.     }
  1431.   }
  1432.  
  1433.   /*------------------------------------------------------------*/
  1434.   /* Handle modifications of the Military Serial Number attr    */
  1435.   /*------------------------------------------------------------*/
  1436.   if (strcmp (soldierObjData.serialNo, soldierObjData.serialNoChange) != 0)
  1437.   {
  1438.     if  (soldierObjData.serialNo[0]) 
  1439.     {
  1440.       err = NWDSPutChange (context, inpBuf, DS_REMOVE_VALUE, 
  1441.                            "Military Serial Number");
  1442.       if  (err < 0) 
  1443.       {
  1444.         NWDSFreeContext (context);
  1445.         NWDSFreeBuf (inpBuf);
  1446.         return err;
  1447.       }
  1448.  
  1449.       err = NWDSPutAttrVal (context, inpBuf, SYN_CI_STRING, 
  1450.                             soldierObjData.serialNo);
  1451.       if  (err < 0) 
  1452.       {
  1453.         NWDSFreeContext (context);
  1454.         NWDSFreeBuf (inpBuf);
  1455.         return err;
  1456.       }
  1457.     }
  1458.     err = NWDSPutChange (context, inpBuf, DS_ADD_VALUE, 
  1459.                          "Military Serial Number");
  1460.     if  (err < 0) 
  1461.     {
  1462.       NWDSFreeContext (context);
  1463.       NWDSFreeBuf (inpBuf);
  1464.       return err;
  1465.     }
  1466.  
  1467.     err = NWDSPutAttrVal (context, inpBuf, SYN_CI_STRING, 
  1468.                           soldierObjData.serialNoChange);
  1469.     if  (err < 0) 
  1470.     {
  1471.       NWDSFreeContext (context);
  1472.       NWDSFreeBuf (inpBuf);
  1473.       return err;
  1474.     }
  1475.   }
  1476.  
  1477.   /*---------------------------------------------------------------*/
  1478.   /* Finally, send the buffer with modification requests to DS     */
  1479.   /*---------------------------------------------------------------*/
  1480.   err= NWDSModifyObject (context, name, NULL, 0, inpBuf);
  1481.  
  1482.   NWDSFreeContext (context);
  1483.   NWDSFreeBuf (inpBuf);
  1484.   return err;
  1485. }
  1486.  
  1487.