home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / nwgetp.exe / NWGETP.C next >
C/C++ Source or Header  |  1994-08-17  |  8KB  |  315 lines

  1. /****************************************************************************
  2. **    File:    NWGETP.C
  3. **
  4. **    Desc:    Example of how to get a directory path from a directory entry.
  5. **
  6. **        
  7. **            Usage: NWGETP <File Server Name>
  8. **              e.g: NWGETP FileServer
  9. **        
  10. **        
  11. **        
  12. **        
  13. **        
  14. **
  15. **        DISCLAIMER  
  16. **  
  17. **    Novell, Inc. makes no representations or warranties with respect to
  18. **    any NetWare software, and specifically disclaims any express or
  19. **    implied warranties of merchantability, title, or fitness for a
  20. **    particular purpose.  
  21. **
  22. **    Distribution of any NetWare software is forbidden without the
  23. **    express written consent of Novell, Inc.  Further, Novell reserves
  24. **    the right to discontinue distribution of any NetWare software.
  25. **    
  26. **    Novell is not responsible for lost profits or revenue, loss of use
  27. **    of the software, loss of data, costs of re-creating lost data, the
  28. **    cost of any substitute equipment or program, or claims by any party
  29. **    other than you.  Novell strongly recommends a backup be made before
  30. **    any software is installed.   Technical support for this software
  31. **    may be provided at the discretion of Novell.
  32. **
  33. **    Programmers:
  34. **
  35. **        Ini    Who                        Firm
  36. **        -----------------------------------------------------------------------
  37. **        KLB    Karl Bunnell                Novell Developer Support.
  38. **
  39. **    History:
  40. **
  41. **        When        Who    What
  42. **        -----------------------------------------------------------------------
  43. **        08-12-94    klb    First code.
  44. **        08-16-94 kbl   Added the NWSubmitRequest() function. This function
  45. **                            returns the amount of actual data received back from
  46. **                            from the Server if the VLMs are used.
  47. */
  48.  
  49. /****************************************************************************
  50. **    Include headers, macros, function prototypes, etc.
  51. */
  52.  
  53.     /*------------------------------------------------------------------------
  54.     **    Macros
  55.     */
  56.     #define NWDOS
  57.     #define VLM_ID_TRAN     0x0020
  58.     #define TRAN_REQ         6
  59.     #define SET_PREFERRED 0xF000
  60.  
  61.     /*------------------------------------------------------------------------
  62.     **    ANSI
  63.     */
  64.     #include <stdio.h>
  65.     #include <string.h>
  66.  
  67.  
  68.     /*------------------------------------------------------------------------
  69.     **    NetWare
  70.     */
  71.     #include <nwcalls.h>
  72.     #include <nwmisc.h>
  73.  
  74.     /*------------------------------------------------------------------------
  75.     **    Structure typedef's
  76.     */
  77.  
  78.     typedef struct
  79.     {
  80.         WORD                bufLen;
  81.         BYTE                subFunctionCode;
  82.         BYTE                volumeNumber;
  83.         NWDIR_ENTRY        dirEntry;
  84.         NWNAME_SPACE     nameSpace;
  85.     } REQBUFFER;
  86.  
  87.     typedef struct
  88.     {
  89.         char                path[256];
  90.     } REPLYBUFFER;
  91.  
  92.  
  93. /****************************************************************************
  94. **    This program demonstrates the proper use of NWGetPathFromDirEntry.
  95. **
  96. */
  97.  
  98.  
  99.  
  100. NWCCODE NWSubmitRequest(
  101.               NWCONN_HANDLE     conn,
  102.               WORD                 function,
  103.               WORD                 numReqFrags,
  104.               NW_FRAGMENT     *reqFrags,
  105.               WORD                 numReplyFrags,
  106.               NW_FRAGMENT     *replyFrags,
  107.               WORD                 *actualReplyLen)
  108. {
  109. WORD i;
  110. NWCCODE ccode;
  111. REGISTERS regs;
  112.  
  113.    if(conn && !NWIsIDInUse(conn))
  114.       return(INVALID_CONNECTION);
  115.  
  116.  
  117.    if(conn > 8)
  118.    {
  119.       regs.w.ax = function;
  120.       regs.w.bx = numReqFrags;
  121.       regs.w.cx = conn;
  122.       regs.w.dx = 1;
  123.       regs.p.requestBuffer = reqFrags;
  124.       regs.p.replyBuffer   = replyFrags;
  125.  
  126.       ccode = NWVLMRequest(0, VLM_ID_TRAN, TRAN_REQ, ®s, USE_DS | USE_ES);
  127.       
  128.       *actualReplyLen = regs.w.dx;
  129.    }
  130.    else
  131.    {
  132.       regs.w.ax = SET_PREFERRED;  /* Set Preferred Connection ID (0xf000) */
  133.       regs.w.dx = conn;
  134.       NWShellRequest(®s, 0);
  135.  
  136.       regs.p.requestBuffer = reqFrags[0].fragAddress;
  137.       regs.w.cx = reqFrags[0].fragSize;
  138.  
  139.       regs.w.ax = (function & 0x00ff) | 0xf200;
  140.       regs.p.replyBuffer = replyFrags[0].fragAddress;
  141.       regs.w.dx = replyFrags[0].fragSize;
  142.  
  143.       NWShellRequest(®s, USE_DS | USE_ES);
  144.       ccode = regs.b.al ? (WORD)regs.b.al | 0x8900 : 0;
  145.  
  146.       *actualReplyLen = replyFrags[0].fragSize;
  147.  
  148.    }
  149.  
  150.  
  151.    return ccode;
  152. }
  153.  
  154.  
  155.  
  156. NWCCODE NWGetPathFromDirEntry(
  157.               NWCONN_HANDLE connHandle,
  158.               BYTE              volumeNumber,
  159.               NWDIR_ENTRY   dirEntry,
  160.               NWNAME_SPACE  nameSpace,
  161.               char             *path)
  162. {
  163.     int            totalLen = 0;
  164.     NWCCODE        cCode;
  165.     REQBUFFER    reqBuffer;
  166.     NW_FRAGMENT    reqFrag[1],
  167.                     replyFrag[1];
  168.     REPLYBUFFER    replyBuffer;
  169.     char            *ptr;
  170.     WORD            actualDataSize;
  171.  
  172.     memset(&replyBuffer, 0, 256);
  173.     reqBuffer.bufLen = NWWordSwap(7);
  174.     reqBuffer.subFunctionCode = 243;
  175.     reqBuffer.volumeNumber = volumeNumber;
  176.     reqBuffer.dirEntry  = dirEntry;
  177.     reqBuffer.nameSpace = nameSpace;
  178.     reqFrag[0].fragAddress = &reqBuffer;
  179.     reqFrag[0].fragSize      = sizeof(reqBuffer);
  180.     replyFrag[0].fragAddress = &replyBuffer;
  181.     replyFrag[0].fragSize    = sizeof(replyBuffer);
  182.  
  183.     cCode = NWSubmitRequest(
  184.                 /* > Conn Handle  */ connHandle,
  185.                 /* > Function code*/ 23,
  186.                 /* > Num Req Frags*/ 1,
  187.                 /* > Request Frag */ reqFrag,
  188.                 /* > Num Reply Frg*/ 1,
  189.                 /* > reply Frag   */ replyFrag,
  190.                 /* < Size of Data */ &actualDataSize
  191.                 );
  192.  
  193.     if (cCode)
  194.         return(cCode);
  195.  
  196.     memset(path, 0, 256);
  197.  
  198.     ptr = replyBuffer.path;
  199.  
  200.     while ((*ptr != '\0') || (totalLen < actualDataSize))
  201.         {
  202.         totalLen = (totalLen + *ptr);
  203.         strncat(path, ptr+1, *ptr);
  204.         path[totalLen] = '\\';
  205.         ++ totalLen;
  206.         ptr = (ptr + *ptr) + 1;
  207.         }
  208.  
  209.     path[totalLen-1] = '\0';
  210.     return(cCode);
  211. }
  212.  
  213. void main(int argC, char *argV[])
  214. {
  215.     NWCCODE            cCode,cCode2;
  216.     NWCONN_HANDLE        connHandle;
  217.     NWCONN_NUM        connNumber;
  218.     NWLAST_RECORD         lastRec = 0;
  219.     OPEN_FILE_CONN_CTRL    openCtrl;
  220.     OPEN_FILE_CONN        openFile;
  221.     NWNUMBER        connInUse;
  222.     NWNUMBER         maxConnections;
  223.     char            *ptr;
  224.     NWNAME_LEN        pLength;
  225.     char            volumeName[16+1];
  226.     char            path[256];
  227.     int            i;
  228.  
  229.     cCode = NWCallsInit(NULL, NULL);
  230.  
  231.     printf("\nNWCallsInit returned: %04X", cCode);
  232.     ptr = strupr(argV[1]);  /* Convert Server Name to upper case */
  233.  
  234.     cCode = NWGetConnectionHandle(ptr, 0, &connHandle, 0);
  235.     printf("\nNWGetConnectionHandle returned: %04X", cCode);
  236.  
  237.     cCode = NWGetFileServerInformation(
  238.                 /* Connection Handle    */ connHandle,
  239.                 /* Server name          */ NULL,
  240.                 /* Major Version        */ NULL,
  241.                 /* Minor Version        */ NULL,
  242.                 /* Revision             */ NULL,
  243.                 /* Max Connections      */ NULL,
  244.                 /* Max Connection Used  */ &maxConnections,
  245.                 /* Connections in use   */ &connInUse,
  246.                 /* Number of Volumes    */ NULL,
  247.                 /* SFT Level            */ NULL,
  248.                 /* TTS Level            */ NULL
  249.                 );
  250.  
  251.     if (cCode)
  252.         {
  253.         printf("NWGetFileServerInformation returned: %04X", cCode);
  254.         exit(1);
  255.         }
  256.  
  257.     for (i=1; i<maxConnections; ++i)
  258.     {
  259.     printf("\n\nConnection: %d\n", i);
  260.  
  261.     lastRec = 0;
  262.     connNumber = i;
  263.  
  264.     while(lastRec != -1)
  265.         {
  266.         cCode = NWScanOpenFilesByConn2(
  267.                     /* Connection Handle */ connHandle,
  268.                     /* Connection Number */ connNumber,
  269.                     /* Last Record       */ &lastRec,
  270.                     /* Open Control      */ &openCtrl,
  271.                     /* Open File struc   */ &openFile
  272.                     );
  273.  
  274.  
  275.         if((cCode != 0) && (cCode != 0x88FF))
  276.             {
  277.             printf("\nNWScanOpenFilesByConn2 returned %04X", cCode);
  278.             exit(1);
  279.             }
  280.  
  281.         if(!cCode)
  282.             {
  283.  
  284.             cCode2 = NWGetPathFromDirEntry(
  285.                         /* > Connection Handle */ connHandle,
  286.                         /* > Volume Number      */ openFile.volNumber,
  287.                         /* > Direct. Entry     */ openFile.dirEntry,
  288.                         /* > Name Space        */ openFile.nameSpace,
  289.                         /* < Path              */ path
  290.                         );
  291.  
  292.  
  293.             if(cCode2)
  294.                 {
  295.                 printf("\nNWGetPathFromDirEntry returned %04X", cCode2);
  296.                 exit(1);
  297.                 }
  298.  
  299.             NWGetVolumeName(
  300.                 /* > Conn Handle */ connHandle,
  301.                 /* > volume Num  */ openFile.volNumber,
  302.                 /* < volume Name */ volumeName
  303.                 );
  304.  
  305.  
  306.             printf("\nComplete Path: %s:%s", volumeName, path);
  307.  
  308.             }
  309.  
  310.             if (cCode == 0x88FF)
  311.                 break;
  312.         }
  313.     }
  314. }
  315.