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

  1. /*-------------------------------------------------------------------------*/
  2. /* snapattr.c                                                              */
  3. /*                                                                         */
  4. /* (c) Copyright 1992-1995 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 "snapattr.h"
  25.  
  26. /*------------------------------------------------------------------------*/
  27. /*  Function Prototypes                                                   */
  28. /*------------------------------------------------------------------------*/
  29.  
  30. #ifdef __cplusplus
  31. extern "C"
  32. {
  33. #endif
  34.  
  35. N_EXTERN_LIBRARY (NWRCODE)
  36. SnapinUserProc (pnstr8 name, nuint16 msg, nparam p1, nparam p2);
  37.  
  38. N_EXTERN_LIBRARY (nuint32) 
  39. DSFlatBrowserLaunchProc (nuint32 userParam, nuint16 uMsg, 
  40.                          nparam param1, nparam param2) ;
  41.  
  42. N_EXTERN_LIBRARY (nuint32) 
  43. MvedProc (nuint32 userParam, nuint16 uMsg, nparam param1, nparam param2) ;
  44.  
  45. BOOL _export FAR PASCAL UserPhotoPageDlg (HWND hwnd, UINT message, 
  46.                                           WPARAM wParam, LPARAM lParam);
  47. BOOL _export FAR PASCAL UserRelativesPageDlg (HWND hwnd, UINT message, 
  48.                                               WPARAM wParam, LPARAM lParam);
  49. BOOL _export FAR PASCAL MvedExampleDlg (HWND hwnd, UINT message, 
  50.                                         WPARAM wParam, LPARAM lParam);
  51. int ReadUserData (void);
  52. int ModifyUserData (char *name);
  53.  
  54. #ifdef __cplusplus
  55. }
  56. #endif
  57.  
  58. /*------------------------------------------------------------------------*/
  59. /*  Type Definitions And MACROS                                           */
  60. /*------------------------------------------------------------------------*/
  61. typedef struct tagUserObjData
  62. {
  63.   HWND hDialogRelatives;
  64.   char name[256];
  65.   char spouse[256];
  66.   char spouseChange[256];
  67.   int  nParentCount;
  68.   int  nParentChangeCount;
  69.   char parentList[5][MAX_DN_BYTES];
  70.   char parentChanges[5][MAX_DN_BYTES];
  71.   int  bPhotoDefined;
  72.   char photo[17];
  73.   char photoChange[17];
  74. } TUserObject;
  75.  
  76. #define NUM_USER_PAGES  2
  77.  
  78. /*------------------------------------------------------------------------*/
  79. /*  Global Used in the Test Object                                        */
  80. /*------------------------------------------------------------------------*/
  81. NWAPageStruct UserPages[NUM_USER_PAGES];
  82. static TUserObject userObjData;
  83. HINSTANCE hDLL;
  84. BOOL bChangePhoto; 
  85.  
  86. /*-------------------------------------------------------------------------*/
  87. /*    DLL Entry Point                                                      */
  88. /*-------------------------------------------------------------------------*/
  89. int FAR PASCAL LibMain (HINSTANCE hInstance, WORD wDataSeg, 
  90.                         WORD cbHeapSize, LPSTR lpCmdLine)
  91. {
  92.    hDLL = hInstance;
  93.    if (cbHeapSize != 0)
  94.      UnlockData (0);
  95.    return 1;
  96. };
  97.  
  98. /*-------------------------------------------------------------------------*/
  99. /* Function : InitSnapin (void)                                            */
  100. /* Description :                                                           */
  101. /*    Every Snapin DLL must provide this function. In this function,       */
  102. /*    snapin menu items (under Tools) are registered. Also, object procs   */
  103. /*    are registered.                                                      */
  104. /*                                                                         */
  105. /*-------------------------------------------------------------------------*/
  106. int _export FAR PASCAL InitSnapin ()                              /*   #   */
  107. {                                                                 /*  # #  */
  108.    /*----------------------------------------------------------*/ /* #   # */
  109.    /* Registering User Object Class Proc                       */ /* ##### */
  110.    /*----------------------------------------------------------*/ /* #   # */
  111.  
  112.    NWARegisterObjectProc (NWA_DS_OBJECT_TYPE,                     /* ####  */
  113.                           "User",                                 /* #   # */
  114.                           "Novell, Inc. (C) All rights reserved.",/* ####  */
  115.                            hDLL,                                  /* #   # */
  116.                            (NWASnapinObjectProc) SnapinUserProc,  /* ####  */
  117.                            NWA_SNAPIN_VERSION);
  118.  
  119.    return NWA_RET_SUCCESS;
  120. }
  121.  
  122. /*-------------------------------------------------------------------------*/
  123. /* Function : ShutDown (void)                                              */
  124. /* Description :                                                           */
  125. /*   Free up muscroll.dll                                                  */
  126. /*-------------------------------------------------------------------------*/
  127. void FAR PASCAL ShutDown (void)
  128. {
  129. }
  130.  
  131.  
  132. /*-------------------------------------------------------------------------*/
  133. /* Function : SnapinUserProc                                               */
  134. /* Description :                                                           */
  135. /*   Snapin User Object Class Proc                                         */
  136. /*-------------------------------------------------------------------------*/
  137. N_GLOBAL_LIBRARY (NWRCODE) _export
  138. SnapinUserProc (pnstr8 name, nuint16 msg, nparam p1, nparam p2)
  139. {
  140.    switch (msg)
  141.    {
  142.       case NWA_MSG_INITSNAPIN:
  143.            {
  144.              /*-------------------------------------------------*/
  145.              /*           initialize pages                      */
  146.              /*-------------------------------------------------*/
  147.                  UserPages[0].dlgProc = (DLGPROC)UserPhotoPageDlg;
  148.                  UserPages[0].resName = "UserPhotograph";
  149.                  UserPages[0].pageTitle = "Photograph";
  150.  
  151.                  UserPages[1].dlgProc = (DLGPROC)UserRelativesPageDlg;
  152.              UserPages[1].resName = "UserRelatives";
  153.              UserPages[1].pageTitle = "Relatives";
  154.  
  155.              NWAAddPropertyNameTranslation ("Photograph",         /*  #### */
  156.                                             "User",               /* #     */
  157.                                             "Fotograf");          /* #     */
  158.                                                                   /* #     */
  159.              return NWA_RET_SUCCESS;                              /*  #### */
  160.            }
  161.  
  162.       case NWA_MSG_GETPAGECOUNT:                                  /* ####  */
  163.            {                                                      /* #   # */
  164.              lstrcpy (userObjData.name, name);                    /* #   # */
  165.              userObjData.spouse[0]='\0';                          /* #   # */
  166.              userObjData.spouseChange[0]='\0';                    /* ####  */
  167.              userObjData.nParentCount=0;
  168.              userObjData.nParentChangeCount=0;
  169.              ReadUserData ();
  170.              return NUM_USER_PAGES;
  171.            }
  172.   
  173.       case NWA_MSG_REGISTERPAGE:                                  /* ##### */
  174.            {                                                      /* #     */
  175.              NWAPageStruct  *pageInfo =   (NWAPageStruct *)p2;    /* ####  */
  176.              pageInfo->dlgProc    = UserPages[p1].dlgProc;        /* #     */
  177.              pageInfo->resName    = UserPages[p1].resName;        /* ##### */
  178.              pageInfo->pageTitle  = UserPages[p1].pageTitle;
  179.              pageInfo->hDLL = hDLL;
  180.              pageInfo->initParam = 0;
  181.              return NWA_RET_SUCCESS;
  182.            }
  183.  
  184.       case NWA_MSG_MODIFY:                                        /* #   # */
  185.            {                                                      /* #   # */
  186.              MessageBox (NULL, "NWA_MSG_MODIFY received",         /* ##### */
  187.                          name, MB_OK);                            /* #   # */
  188.              ModifyUserData (name);                               /* #   # */
  189.              return NWA_RET_SUCCESS;
  190.            }
  191.  
  192.       case NWA_MSG_CLOSESNAPIN:
  193.            {
  194.              /*-------------------------------------------------*/
  195.              /*      unregister bitmaps and delete them         */
  196.              /*-------------------------------------------------*/
  197.              MessageBox (NULL, "NWA_MSG_CLOSESNAPIN received", 
  198.                          "User proc", MB_OK);
  199.              return NWA_RET_SUCCESS;
  200.            }
  201.  
  202.       default:
  203.            break;
  204.    }
  205.    return NWA_RET_SUCCESS;
  206. }
  207.  
  208. /*-------------------------------------------------------------------------*/
  209. /* Function : UserPhotoPageDlg                                             */
  210. /* Description :                                                           */
  211. /*   Page dialog to enhance User Details.                                  */
  212. /*-------------------------------------------------------------------------*/
  213. BOOL _export FAR PASCAL UserPhotoPageDlg (HWND hwnd, UINT message, 
  214.                                           WPARAM wParam, LPARAM lParam)
  215. {
  216.    switch (message)
  217.    {
  218.  
  219.       case WM_INITDIALOG:
  220.         {
  221.           bChangePhoto = 0;
  222.           SetDlgItemText (hwnd, IDC_PHOTO, userObjData.photo);
  223.  
  224.           SendDlgItemMessage (hwnd, IDC_PHOTO, EM_LIMITTEXT, 5, 0L);
  225.  
  226.           return TRUE;
  227.         }
  228.  
  229.       case WM_COMMAND:
  230.              switch (wParam)
  231.            {
  232.              case IDC_PHOTO:
  233.                 if (HIWORD (lParam) == EN_CHANGE)
  234.                 {
  235.                    SendMessage (hwnd,                             /* ##### */
  236.                                 NWA_WM_SETPAGEMODIFY,             /* #     */
  237.                                 (WORD)hwnd,                       /* ####  */
  238.                                 MAKELONG (0,TRUE));               /* #     */
  239.                    GetDlgItemText (hwnd,                          /* #     */
  240.                                    IDC_PHOTO,                              
  241.                                    userObjData.photoChange,              
  242.                                    1024);                                 
  243.                 }   
  244.                 break;
  245.           }
  246.         break;
  247.  
  248.       case NWA_WM_CANCLOSE:                                       /*  #### */
  249.         {                                                         /* #     */
  250.           if (stricmp (userObjData.photo,                         /* #  ## */
  251.                        userObjData.photoChange) == 0)             /* #   # */
  252.           {                                                       /*  ###  */
  253.               bChangePhoto = 1;
  254.           }
  255.           return TRUE;
  256.         }
  257.  
  258.       case NWA_WM_F1HELP:                                         /*  ###  */
  259.            {                                                      /*   #   */
  260.              MessageBox (NULL, "Draw a picture using keyboard",   /*   #   */
  261.                          "Snapin Help", MB_OK);                   /*   #   */
  262.              return TRUE;                                         /*  ###  */
  263.            }
  264.    }
  265.    return FALSE ;
  266. }
  267.  
  268.  
  269. /*-------------------------------------------------------------------------*/
  270. /* Function : UserRelativesPageDlg                                         */
  271. /* Description :                                                           */
  272. /*   Page dialog to enhance User Details.                                  */
  273. /*-------------------------------------------------------------------------*/
  274. BOOL _export FAR PASCAL UserRelativesPageDlg (HWND hwnd, UINT message, 
  275.                                           WPARAM wParam, LPARAM lParam)
  276. {
  277.    switch (message)
  278.    {
  279.  
  280.       case WM_INITDIALOG:
  281.         {
  282.           userObjData.hDialogRelatives = hwnd;
  283.           SendDlgItemMessage (hwnd, IDC_SPOUSE, EM_LIMITTEXT, 255, 0L);
  284.           SetDlgItemText (hwnd, IDC_SPOUSE, userObjData.spouse);
  285.           NWACreateMved (hwnd,                                    /*  ###  */
  286.                          1,                                       /*   #   */
  287.                          IDD_EDIT_DN,                             /*   #   */
  288.                          IDD_SPIN_DN,                             /* # #   */
  289.                          IDD_BUTTON_DN,                           /* ###   */
  290.                          NWA_MVED_VALUE_DISTNAME,
  291.                          32,
  292.                          "Mved Example",
  293.                          DS_ROOT_NAME,
  294.                          0,
  295.                          MvedProc) ;
  296.  
  297.           return TRUE;
  298.         }
  299.  
  300.       case NWA_WM_F1HELP:
  301.         {
  302.              MessageBox (NULL, "Fill in the info by clicking browse buttons",
  303.                                "Snapin Help", MB_OK);
  304.              return TRUE;
  305.         }
  306.       case NWA_WM_CANCLOSE:
  307.         {
  308.           int i;
  309.  
  310.           GetDlgItemText (hwnd, IDC_SPOUSE, userObjData.spouseChange, 
  311.                           127);
  312.           NWAGetMvedCount (hwnd, IDD_EDIT_DN, (pnuint16)          /* #     */
  313.                            &(userObjData.nParentChangeCount));    /* #     */
  314.           for (i=0; i<userObjData.nParentChangeCount; i++)        /* #     */
  315.           {                                                       /* #     */
  316.             NWAGetMvedValue (hwnd, IDD_EDIT_DN, i, MAX_DN_BYTES,  /* ##### */
  317.                              userObjData.parentChanges[i]);
  318.           }
  319.           return TRUE;
  320.         }
  321.       case WM_COMMAND:
  322.              switch (wParam)
  323.         {
  324.              case IDC_SPOUSE:
  325.                 if (HIWORD (lParam) == EN_CHANGE)
  326.                 {
  327.                    SendMessage (hwnd, NWA_WM_SETPAGEMODIFY, (WORD)hwnd, 
  328.                                 MAKELONG (0,TRUE));
  329.                    GetDlgItemText (hwnd, IDC_SPOUSE, 
  330.                                    userObjData.spouseChange, 255);
  331.                 }   
  332.                 break;
  333.              case IDD_BBSPOUSE_DN:
  334.                 {
  335.                   char contextStr[256];
  336.                   strcpy(contextStr, "");
  337.                   NWALaunchDSFlatBrowser(hwnd,                    /* #   # */
  338.                                          (long) &userObjData,     /* ## ## */
  339.                                          contextStr,              /* # # # */
  340.                                          NULL,                    /* #   # */
  341.                                          NULL,                    /* #   # */
  342.                                          "Selected Object",
  343.                                          NWA_FB_SINGLE_SELECT,
  344.                                          DSFlatBrowserLaunchProc);
  345.                 }
  346.                 break;
  347.         }
  348.         break;
  349.  
  350.    }
  351.    return FALSE ;
  352. }
  353.  
  354.  
  355. /*-------------------------------------------------------------------------*/
  356. /* Function : MvedProc                                                     */
  357. /* Description :                                                           */
  358. /*  Mved Callback Proc                                                     */
  359. /*-------------------------------------------------------------------------*/
  360. N_EXTERN_LIBRARY (nuint32)  _export
  361. MvedProc
  362.  (
  363.   nuint32 userParam, 
  364.   nuint16 msg, 
  365.   nparam param1, 
  366.   nparam param2 
  367. )
  368. {
  369.   switch (msg) 
  370.   {
  371.     case NWA_MSG_MVED_INITCOUNT :                                 /* #   # */
  372.       {                                                           /* #  #  */
  373.         /*-------------------------------------------------*/     /* ###   */
  374.         /* Return the number of values to initialize the   */     /* #  #  */
  375.         /* MVED with.                                      */     /* #   # */
  376.         /*-------------------------------------------------*/
  377.         *((int *)param1) = userObjData.nParentCount;
  378.         break;
  379.       }
  380.  
  381.     case NWA_MSG_MVED_INITVALUE :
  382.       {
  383.         /*-------------------------------------------------*/
  384.         /* Return the Nth value to initialize the MVED     */
  385.         /* with, as specified in param1.                   */
  386.         /*-------------------------------------------------*/
  387.         strcpy ((char *) param2, userObjData.parentList[param1]);
  388.         break;
  389.       }
  390.  
  391.     case NWA_MSG_FBFILTER_COUNT :
  392.       {
  393.         /*-------------------------------------------------*/
  394.         /* Return the number of DS classes that will be    */
  395.         /* allowed to be shown in the flat browser when    */
  396.         /* adding a value to the MVED.                     */
  397.         /* This message is only received if the MVED is    */
  398.         /* created for distinguished names or filenames.   */
  399.         /*-------------------------------------------------*/
  400.         *((int *)param1) = 1;
  401.         break;
  402.       }
  403.  
  404.     case NWA_MSG_FBFILTER_VALUE :
  405.       {
  406.         /*-------------------------------------------------*/
  407.         /* Return the Nth DS class name that will be       */
  408.         /* allowed to be shown in the flat browser, as     */
  409.         /* specified in param1.                            */
  410.         /* This message is only received if the MVED is    */
  411.         /* created for distinguished names or filenames.   */
  412.         /*-------------------------------------------------*/
  413.         switch (param1) 
  414.         {
  415.           case 0L:
  416.             strcpy ((char *) param2, "User");
  417.             break;
  418.         }
  419.         break;
  420.       }
  421.   }   
  422.    return (0);
  423. }
  424.  
  425.  
  426. /*-------------------------------------------------------------------------*/
  427. /* Function : DSFlatBrowserLaunchProc                                      */
  428. /* Description :                                                           */
  429. /*  DSFlat Browser Callback Proc                                           */
  430. /*-------------------------------------------------------------------------*/
  431. N_EXTERN_LIBRARY (nuint32)  _export
  432. DSFlatBrowserLaunchProc
  433.  (
  434.   nuint32 userParam, 
  435.   nuint16 msg, 
  436.   nparam param1, 
  437.   nparam param2 
  438. )
  439. {
  440.    int fltCount;
  441.    NWASelObject *pObj;
  442.    char tmpBuf[512];
  443.    TUserObject * puData;
  444.  
  445.    fltCount=1;
  446.  
  447.    switch (msg) 
  448.    {
  449.      case NWA_MSG_FBFILTER_COUNT :                                /* #   # */
  450.        {                                                          /* ##  # */
  451.          /*-------------------------------------------------*/    /* # # # */
  452.          /* Return the number of classes that will be used  */    /* #  ## */
  453.          /* to filter the types of objects that may appear  */    /* #   # */
  454.          /* in the flat browser.                            */
  455.          /*-------------------------------------------------*/
  456.          *((int *)param1) = fltCount;
  457.          break;
  458.        }
  459.  
  460.      case NWA_MSG_FBFILTER_VALUE :                                /*  ###  */
  461.        {                                                          /* #   # */
  462.          /*-------------------------------------------------*/    /* #   # */
  463.          /* Return the Nth filter class (i.e. "User"), used */    /* #   # */
  464.          /* to filter the types of objects that may appear  */    /*  ###  */
  465.          /* in the flat browser.                            */
  466.          /*-------------------------------------------------*/
  467.          switch (param1) 
  468.          {
  469.            case 0L:
  470.              strcpy ((char *) param2, "User");
  471.              break;
  472.          }
  473.          break;
  474.        }
  475.  
  476.      case NWA_MSG_FBOBJECT_COUNT :                                /* ####  */
  477.        {                                                          /* #   # */
  478.          /*-------------------------------------------------*/    /* ####  */
  479.          /* Upon exit, the flat browser tells us how many   */    /* #     */
  480.          /* objects are selected, via param1.  Since we're  */    /* #     */
  481.          /* updating a single-valued attribute, and thus    */
  482.          /* launched the flat browser as single-select, we  */
  483.          /* don't care how many objects are selected.       */
  484.          /* We do, however, use this notification message   */
  485.          /* to set the Identification page as modified.     */
  486.          /*-------------------------------------------------*/
  487.          puData = (TUserObject *) userParam;
  488.          SendMessage (puData->hDialogRelatives, 
  489.                      NWA_WM_SETPAGEMODIFY, 
  490.                      (WORD)puData->hDialogRelatives, 
  491.                      MAKELONG (0,TRUE));
  492.          break;
  493.        }
  494.  
  495.      case NWA_MSG_FBOBJECT_VALUE :                                /*  ###  */
  496.        {                                                          /* #   # */
  497.          /*-------------------------------------------------*/    /* #   # */
  498.          /* Fetch the single value that was selected in the */    /* #  ## */
  499.          /* flat browser when its OK button was pressed.    */    /*  #### */
  500.          /* Put that value both in the edit control next to */
  501.          /* the flat browser's launch button (spouse), and  */
  502.          /* in the global data area's spouseChange string.  */
  503.          /*-------------------------------------------------*/
  504.          pObj=  (NWASelObject *)  param2;
  505.          puData = (TUserObject *) userParam;
  506.  
  507.          SetDlgItemText (puData->hDialogRelatives, IDC_SPOUSE, 
  508.                          (LPSTR) pObj->objName);
  509.          strcpy (puData->spouseChange, (LPSTR) pObj->objName);
  510.          break;
  511.        }
  512.    }
  513.    return (0);
  514. }
  515.  
  516. /*-------------------------------------------------------------------------*/
  517. /* Function : ReadUserData                                                 */
  518. /* Description :                                                           */
  519. /*   Function for reading / modifying object data in DS                    */
  520. /*-------------------------------------------------------------------------*/
  521. int ReadUserData ()
  522. {
  523.   NWDSContextHandle context;
  524.   int               err = 0, i, j;
  525.   int32             iterHandle = -1L;
  526.   Buf_T             *resBuf, *nameBuf;
  527.   char              *attributes[] = {"Photograph"
  528.                                      "Spouse", 
  529.                                      "Parents"};
  530.   uint32            totAttr, valCount, synID;
  531.   char              attrName[MAX_DN_CHARS+1];
  532.   uint32            flags;
  533.  
  534.   totAttr = sizeof (attributes)/sizeof (attributes[0]);
  535.   context = NWDSCreateContext ();
  536.   if (context == (NWDSContextHandle) ERR_CONTEXT_CREATION)
  537.     return ((int) context);
  538.  
  539.   err = NWDSSetContext (context, DCK_NAME_CONTEXT, DS_ROOT_NAME);
  540.   if (err < 0)
  541.   {
  542.     NWDSFreeContext (context);
  543.     return err;
  544.   }
  545.  
  546.   err = NWDSGetContext (context, DCK_FLAGS, (void *)&flags);
  547.   if (err < 0)
  548.   {
  549.     NWDSFreeContext (context);
  550.     return err;
  551.   }
  552.  
  553.   flags |= DCV_TYPELESS_NAMES;
  554.   flags |= DCV_XLATE_STRINGS;
  555.   flags |= DCV_DEREF_ALIASES;
  556.   flags |= DCV_DEREF_BASE_CLASS;
  557.  
  558.   err   = NWDSSetContext (context, DCK_FLAGS, (void *)&flags);
  559.   if (err < 0)
  560.   {
  561.     NWDSFreeContext (context);
  562.     return err;
  563.   }
  564.  
  565.  
  566.   err = NWDSAllocBuf (DEFAULT_MESSAGE_LEN, &resBuf);
  567.   if (err < 0)
  568.   {
  569.     NWDSFreeContext (context);
  570.     return err;
  571.   }
  572.  
  573.   err = NWDSAllocBuf (DEFAULT_MESSAGE_LEN, &nameBuf);
  574.   if (err < 0)
  575.   {
  576.     NWDSFreeContext (context);
  577.     NWDSFreeBuf (resBuf);
  578.     return err;
  579.   }
  580.   
  581.   /*----------------------------------------------------------------------*/
  582.   /* Initialize input buffer and check for errors. The output buffer does */
  583.   /* not need to be initialized. This buffer will be initialized to       */
  584.   /* DSV_READ operations                                                  */
  585.   /*----------------------------------------------------------------------*/
  586.  
  587.   err = NWDSInitBuf (context, DSV_READ, nameBuf);
  588.   if (err < 0)
  589.   {
  590.     NWDSFreeContext (context);
  591.     NWDSFreeBuf (resBuf);
  592.     NWDSFreeBuf (nameBuf);
  593.     return err;
  594.   }
  595.  
  596.   /*----------------------------------------------------------------------*/
  597.   /* Put object attributes that are to be read into input buffer.         */
  598.   /* Check for errors.                                                    */
  599.   /*----------------------------------------------------------------------*/
  600.   for (i = 0; i < totAttr; i++)
  601.   {
  602.     err = NWDSPutAttrName (context, nameBuf, attributes[i]);
  603.     if (err < 0)
  604.     {
  605.       NWDSFreeContext (context);
  606.       NWDSFreeBuf (resBuf);
  607.       NWDSFreeBuf (nameBuf);
  608.       return err;
  609.     }
  610.   }
  611.  
  612.   /*----------------------------------------------------------------------*/
  613.   /* Read the data.                                                       */
  614.   /*----------------------------------------------------------------------*/
  615.  
  616.   userObjData.bPhotoDefined = 0;
  617.   iterHandle = NO_MORE_ITERATIONS;
  618.   do
  619.   {
  620.     err = NWDSRead (context, userObjData.name, DS_ATTRIBUTE_VALUES,
  621.                     FALSE, nameBuf, &iterHandle, resBuf);
  622.     if (err < 0)
  623.     {
  624.       NWDSFreeContext (context);
  625.       NWDSFreeBuf (resBuf);
  626.       NWDSFreeBuf (nameBuf);
  627.       return err;
  628.     }
  629.     
  630.     /*--------------------------------------------------------------------*/
  631.     /* pull stuff out of the output buffer, checking for errors.          */
  632.     /* First, get total no of attributes in the buffer.                   */
  633.     /*--------------------------------------------------------------------*/
  634.     err = NWDSGetAttrCount (context, resBuf, &totAttr);
  635.     if (err < 0)
  636.     {
  637.       NWDSFreeContext (context);
  638.       NWDSFreeBuf (resBuf);
  639.       NWDSFreeBuf (nameBuf);
  640.       return err;
  641.     }
  642.  
  643.     for (i = 0; i< totAttr; i++)
  644.     {
  645.       err = NWDSGetAttrName (context, resBuf, attrName, &valCount, &synID);
  646.       if (err < 0)
  647.       {
  648.         NWDSFreeContext (context);
  649.         NWDSFreeBuf (resBuf);
  650.         NWDSFreeBuf (nameBuf);
  651.         return err;
  652.       }
  653.  
  654.       if (lstrcmp (attrName, "Photograph") == 0)
  655.       {
  656.         userObjData.bPhotoDefined = 1;
  657.         err = NWDSGetAttrVal (context, resBuf, synID, userObjData.photo);
  658.         if (err < 0)
  659.         {
  660.           NWDSFreeContext (context);
  661.           NWDSFreeBuf (resBuf);
  662.           NWDSFreeBuf (nameBuf);
  663.           return err;
  664.         }
  665.       }
  666.       else if  (lstrcmp (attrName, "Spouse") == 0) 
  667.       {
  668.         err=NWDSGetAttrVal (context, resBuf, synID, userObjData.spouse);
  669.         if  (err < 0) 
  670.         {
  671.           NWDSFreeContext (context);
  672.           NWDSFreeBuf (resBuf);
  673.           NWDSFreeBuf (nameBuf);
  674.           return err;
  675.         }
  676.       }
  677.       else if  (lstrcmp (attrName, "Parents") == 0) 
  678.       {
  679.         userObjData.nParentCount = valCount;
  680.         for  (j=0; j<valCount; j++) // multi-valued: fetch each one
  681.         {
  682.           err=NWDSGetAttrVal (context, resBuf, synID, 
  683.                              userObjData.parentList[j]);
  684.           if  (err < 0) 
  685.           {
  686.             NWDSFreeContext (context);
  687.             NWDSFreeBuf (resBuf);
  688.             NWDSFreeBuf (nameBuf);
  689.             return err;
  690.           }
  691.         }
  692.       }
  693.     }
  694.   } while (iterHandle != NO_MORE_ITERATIONS);
  695.  
  696.   NWDSFreeContext (context);
  697.   NWDSFreeBuf (resBuf);
  698.   NWDSFreeBuf (nameBuf);
  699.   return 0;
  700. }
  701.  
  702.  
  703.  
  704. /*-------------------------------------------------------------------------*/
  705. /* Function : ModifyUserData (void)                                        */
  706. /* Description :                                                           */
  707. /*  Modifies a User Object's Attribute Values                              */
  708. /*-------------------------------------------------------------------------*/
  709. int ModifyUserData (char *name)
  710. {
  711.   NWDSContextHandle context;
  712.   int               err = 0, i, j;
  713.   Buf_T             *inpBuf;
  714.   uint32            flags;
  715.   uint32            syntaxID;
  716.  
  717.   context = NWDSCreateContext ();
  718.   if (context == (NWDSContextHandle) ERR_CONTEXT_CREATION)
  719.     return ((int) context);
  720.  
  721.   err = NWDSSetContext (context, DCK_NAME_CONTEXT, DS_ROOT_NAME);
  722.   if (err < 0)
  723.   {
  724.     NWDSFreeContext (context);
  725.     return err;
  726.   }
  727.   
  728.   err = NWDSGetContext (context, DCK_FLAGS, (void *)&flags);
  729.  
  730.   flags |= DCV_TYPELESS_NAMES;
  731.   flags |= DCV_XLATE_STRINGS;
  732.   flags |= DCV_DEREF_ALIASES;
  733.   flags |= DCV_DEREF_BASE_CLASS;
  734.  
  735.   err   = NWDSSetContext (context, DCK_FLAGS, (void *)&flags);
  736.  
  737.   err = NWDSAllocBuf (DEFAULT_MESSAGE_LEN, &inpBuf);
  738.   if (err < 0)
  739.   {
  740.     NWDSFreeContext (context);
  741.     return err;
  742.   }
  743.  
  744.   err = NWDSInitBuf (context, DSV_MODIFY_ENTRY, inpBuf);
  745.   if (err < 0)
  746.   {
  747.     NWDSFreeContext (context);
  748.     NWDSFreeBuf (inpBuf);
  749.     return err;
  750.   }
  751.  
  752.   /*------------------------------------------------------------*/
  753.   /* Handle modifications of the Parents attribute              */
  754.   /*------------------------------------------------------------*/
  755.   err = NWDSGetSyntaxID (context, "Parents", &syntaxID);
  756.   if  (err < 0) 
  757.   {
  758.     NWDSFreeContext (context);
  759.     NWDSFreeBuf (inpBuf);
  760.     return err;
  761.   }
  762.  
  763.   /*-------------------------------------------------------*/
  764.   /* Modify Parents Attribute values                       */
  765.   /* (This isn't really the way to do it, but the built-in */
  766.   /* MVED has no mechanism for informing you that the      */
  767.   /* attribute has changed, or which values were changed.) */
  768.   /*-------------------------------------------------------*/
  769.   if (userObjData.nParentCount != userObjData.nParentChangeCount)    
  770.   {
  771.     if  (userObjData.nParentCount) 
  772.     {
  773.       /*---------------------------------------------------*/
  774.       /* There were some Parents in the object;            */
  775.       /* remove all of them first (brute force method).    */
  776.       /*---------------------------------------------------*/
  777.       err = NWDSPutChange (context, inpBuf, DS_REMOVE_VALUE, "Parents");
  778.       if  (err < 0) 
  779.       {
  780.         NWDSFreeContext (context);
  781.         NWDSFreeBuf (inpBuf);
  782.         return err;
  783.       }
  784.  
  785.       for (j=0; j<userObjData.nParentCount; j++)
  786.       {
  787.         err = NWDSPutAttrVal (context, inpBuf, syntaxID, 
  788.                              userObjData.parentList[j]);
  789.         if  (err < 0) 
  790.         {
  791.           NWDSFreeContext (context);
  792.           NWDSFreeBuf (inpBuf);
  793.           return err;
  794.         }
  795.       }
  796.     }
  797.  
  798.     /*---------------------------------------------------*/
  799.     /* Now, add all of the ones that were found at the   */
  800.     /* time the OK button was pressed.  This includes    */
  801.     /* even those that were in the original list that    */
  802.     /* weren't deleted (continuation of brute force...)  */
  803.     /*---------------------------------------------------*/
  804.     if  (userObjData.nParentChangeCount) 
  805.     {
  806.       err = NWDSPutChange (context, inpBuf, DS_ADD_VALUE, 
  807.                            "Parents");
  808.       if  (err < 0) 
  809.       {
  810.         NWDSFreeContext (context);
  811.         NWDSFreeBuf (inpBuf);
  812.         return err;
  813.       }
  814.  
  815.       for (j=0; j<userObjData.nParentChangeCount; j++)
  816.       {
  817.         err = NWDSPutAttrVal (context, inpBuf, syntaxID, 
  818.                               userObjData.parentChanges[j]);
  819.         if  (err < 0) 
  820.         {
  821.           NWDSFreeContext (context);
  822.           NWDSFreeBuf (inpBuf);
  823.           return err;
  824.         }
  825.       }
  826.     }
  827.   }
  828.  
  829.   /*------------------------------------------------------------*/
  830.   /* Handle modifications of the Spouse attribute               */
  831.   /*------------------------------------------------------------*/
  832.   if (strcmp (userObjData.spouse, userObjData.spouseChange) != 0)
  833.   {
  834.     if  (userObjData.spouse[0]) 
  835.     {
  836.       err = NWDSPutChange (context, inpBuf, DS_REMOVE_VALUE, "Spouse");
  837.       if  (err < 0) 
  838.       {
  839.         NWDSFreeContext (context);
  840.         NWDSFreeBuf (inpBuf);
  841.         return err;
  842.       }
  843.  
  844.       err = NWDSPutAttrVal (context, inpBuf, SYN_DIST_NAME, 
  845.                             userObjData.spouse);
  846.       if  (err < 0) 
  847.       {
  848.         NWDSFreeContext (context);
  849.         NWDSFreeBuf (inpBuf);
  850.         return err;
  851.       }
  852.     }
  853.     err = NWDSPutChange (context, inpBuf, DS_ADD_VALUE, "Spouse");
  854.     if  (err < 0) 
  855.     {
  856.       NWDSFreeContext (context);
  857.       NWDSFreeBuf (inpBuf);
  858.       return err;
  859.     }
  860.  
  861.     err = NWDSPutAttrVal (context, inpBuf, SYN_DIST_NAME, 
  862.                           userObjData.spouseChange);
  863.     if  (err < 0) 
  864.     {
  865.       NWDSFreeContext (context);
  866.       NWDSFreeBuf (inpBuf);
  867.       return err;
  868.     }
  869.   }
  870.  
  871.   /*---------------------------------------------------------------*/
  872.   /* Modify Photograph Attribute                                   */
  873.   /*---------------------------------------------------------------*/
  874.   if (bChangePhoto)
  875.   {
  876.     if (userObjData.bPhotoDefined)
  877.     {
  878.       err = NWDSPutChange (context, inpBuf, DS_REMOVE_VALUE, "Photograph");
  879.       if (err < 0)
  880.       {
  881.         NWDSFreeContext (context);
  882.         NWDSFreeBuf (inpBuf);
  883.         return err;
  884.       }
  885.  
  886.       err = NWDSPutAttrVal (context, inpBuf, SYN_CI_STRING, 
  887.                             userObjData.photo);
  888.       if (err < 0)
  889.       {
  890.         NWDSFreeContext (context);
  891.         NWDSFreeBuf (inpBuf);
  892.         return err;
  893.       }
  894.     }
  895.     err = NWDSPutChange (context, inpBuf, DS_ADD_VALUE, "Photograph");
  896.     if (err < 0)
  897.     {
  898.       NWDSFreeContext (context);
  899.       NWDSFreeBuf (inpBuf);
  900.       return err;
  901.     }
  902.  
  903.     err = NWDSPutAttrVal (context, inpBuf, SYN_CI_STRING, 
  904.                           userObjData.photoChange);
  905.     if (err < 0)
  906.     {
  907.       NWDSFreeContext (context);
  908.       NWDSFreeBuf (inpBuf);
  909.       return err;
  910.     }
  911.   }
  912.   err = NWDSModifyObject (context, name, NULL, 0, inpBuf);
  913.  
  914.   NWDSFreeContext (context);
  915.   NWDSFreeBuf (inpBuf);
  916.   return err;
  917. }
  918.  
  919.