home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / clipper / nettos11.zip / BINDERY / NWRDPROP.PRG < prev    next >
Text File  |  1993-07-23  |  7KB  |  223 lines

  1. /*
  2.  * File......: NWRDPROP.PRG
  3.  * Author....: Kevin Maher/Steve Tyrakowski
  4.  * CIS ID....: 73766,1224
  5.  * Date......: $Date$
  6.  * Revision..: $Revision$
  7.  * Log file..: $Logfile$
  8.  *
  9.  * This is an original work by Kevin Maher and Steve Tyrakowski
  10.  * and is placed in the public domain.
  11.  *
  12.  * Modification history:
  13.  * ---------------------
  14.  *
  15.  * $Log$
  16.  *
  17.  */
  18.  
  19.  
  20. /*  $DOC$
  21.  *  $FUNCNAME$
  22.  *     FN_rdProVa()
  23.  *  $CATEGORY$
  24.  *     Bindery
  25.  *  $ONELINER$
  26.  *     Read property value
  27.  *  $SYNTAX$
  28.  *
  29.  *     FN_rdProVal(cObjectName, nObjectType, cPropertyName, lKeepNulls) =>
  30.  *       aSetInformation | cPropertyValue
  31.  *
  32.  *  $ARGUMENTS$
  33.  *
  34.  *     <cObjectName> is the name of the Object that you are trying
  35.  *             to read the property info for. Max Length = 47
  36.  *
  37.  *     <nObjectType> is the Bindery Object Type.  Manifest constants
  38.  *             describing the defined types are included in the
  39.  *             NETTO.CH header file.
  40.  *
  41.  *     <cPropertyName> is the name of the Property that you are looking up.
  42.  *               Max Length = 15
  43.  *
  44.  *     <lKeepNulls> is an optional parameter that allows you to receive
  45.  *            the entire 128 byte field returned for an ITEM property.  By
  46.  *            default, the string returned for an ITEM property is
  47.  *            truncated at the first NULL character to simplify use.
  48.  *
  49.  *            Note that up to 255 segments of 128 bytes may be used to
  50.  *            store the value, so the return string could be as long
  51.  *            as 32,640 bytes.  The practical Max length s/b 128.
  52.  *
  53.  *  $RETURNS$
  54.  *
  55.  *     <aSetInformation>
  56.  *
  57.  *     If the Property being read is a SET property (i.e. a list of multiple
  58.  *     entries), then the return value is a multidimensional array containing
  59.  *     three values for each item in the SET.
  60.  *
  61.  *      aReturn[x,1] is the ObjectId which is used as a parameter
  62.  *               for other Bindery Functions
  63.  *
  64.  *      aReturn[x,2] is the Object Name from the Bindery that corresponds
  65.  *               to the ObjectId (i.e. the return value from the
  66.  *               GetBinderyObjectName call)
  67.  *
  68.  *      aReturn[x,3] is the Object Type for this element in the SET.
  69.  *               see the OT_????? definitions in the NFNET.CH
  70.  *               for more info about what types have been defined.
  71.  *
  72.  *     <cPropertyValue>
  73.  *
  74.  *     IF the property being read is not a SET property, then the return
  75.  *     value is a character string that contains the info supplied by the
  76.  *     bindery.  Only info up to, but not including the first null found
  77.  *     is returned. i.e. the string is "cleaned up" before the function
  78.  *     sends it to you.  The lKeepNulls optional parameter allows you
  79.  *     to override the null-stripping and receive the full 128 byte value.
  80.  *
  81.  *     An Item property can have a value of any data type.  It is defined
  82.  *     by the application using the bindery, not in the bindery itself.  
  83.  *     As such, an Item property can only be returned as a character string,
  84.  *     this function cannot assume any data type so the value in the bindery
  85.  *     is returned without modicication.  It is up to the programmer to know
  86.  *     the format of the data that they are trying to inspect.
  87.  *
  88.  *     Completion status is set internally and may be inspected by the
  89.  *     FN_Error() function.  A status code of 0 signifies Success.
  90.  *
  91.  *     If an error occured the function will return a nil.
  92.  *
  93.  *  $DESCRIPTION$
  94.  *
  95.  *     This function allows you to find the property value for an object
  96.  *     that is contained in the Bindery.  A set Property is returned as
  97.  *     an array to simplify using it in your code.
  98.  *
  99.  *  $SEEALSO$
  100.  *     fn_wrProVal() fn_adBndO() fn_dBndOSe()
  101.  *
  102.  *  $EXAMPLES$
  103.  *
  104.  *     #include netto.ch
  105.  *
  106.  *     // this will return the value of a item property
  107.  *     cPropertyValue :=  FN_rdProVal("GUEST",OT_USER,"IDENTIFICATION")
  108.  *
  109.  *     // this will return the values of a set property as an array
  110.  *     aSetInfo := FN_rdProVal("EVERYONE",OT_USER_GROUP,"GROUP_MEMBERS")
  111.  *
  112.  *
  113.  *  $END$
  114.  */
  115.  
  116. #include "ftint86.ch"
  117. #include "netto.ch"
  118.  
  119. #xcommand DEFAULT <v1> TO <x1> [, <vN> TO <xN> ];
  120.       => IIF((<v1>)=NIL,<v1>:=<x1>,NIL) [; IF((<vN>)=NIL,<vN>:=<xN>,NIL)]
  121.  
  122. #define NW_LOG     227
  123.  
  124. #ifdef FT_TEST
  125.   FUNCTION MAIN(cObject, nType, cProp)
  126.  
  127.     LOCAL nError   := nil
  128.     LOCAL xReturn
  129.  
  130.     DEFAULT cObject  TO "EVERYONE"
  131.     DEFAULT cProp    TO "GROUP_MEMBERS"
  132.     DEFAULT nType    TO OT_USER_GROUP
  133.  
  134.     IF ValType(nType) == "C"  ;  nType := Val(nType)   ; ENDIF
  135.  
  136.     Qout(Replicate("─",80))
  137.     Qout("Testing:",cObject,nType,cProp)
  138.     Qout()
  139.  
  140.     xReturn := FN_rdprova(cObject, nType, cProp)
  141.     IF Valtype(xReturn) == "A"
  142.       QOut(" Type    Name                  nId")
  143.       Aeval(xReturn,{|aArray|Qout(aArray[3],"    ",aArray[2],"   ",aArray[1])})
  144.     ELSE
  145.       QOut(xreturn)
  146.     ENDIF
  147.     QOut("Nanfor Return Code:")
  148.     QQOut(fn_Error())
  149.     QOut(Replicate("─",80))
  150.  
  151.  
  152.   RETURN ( nil )
  153.  
  154. #endif
  155.  
  156. FUNCTION FN_rdProVa(cObject, nType, cProperty, lKeepNulls)
  157.   LOCAL cSend
  158.   LOCAL cReceive
  159.   LOCAL acReturn
  160.   LOCAL nSegment := 1
  161.   LOCAL nPos
  162.   LOCAL cName,nObjType
  163.   LOCAL cID
  164.  
  165.   DEFAULT lKeepNulls TO .F.
  166.  
  167.   ///////////////// Set up request packet  /////////////////////////////////
  168.  
  169.     cSend := I2BYTE(61);        // 3Dh    API Function Request Code
  170.        + W2HILO(nType);        // Object Type as NW int
  171.        + FN_NameL(cObject,48);    // Length encoded Object Name String
  172.        + I2BYTE(nSegment);        // Segment number
  173.        + FN_NameL(Upper(cProperty),16)     // Length encoded PropertyName String
  174.  
  175.     // See    crtprop.prg for Upper(cProperty) discussion
  176.  
  177.  
  178.   ///////////////// Set up reply packet    /////////////////////////////////
  179.  
  180.     cReceive := Space(130)
  181.  
  182.  
  183.   DO WHILE _fnReq(NW_LOG, cSend, @cReceive) == ESUCCESS
  184.  
  185.        /////////////////// SET Properties ///////////////////
  186.  
  187.     IF FT_ISBIT(Substr(cReceive,130,1), 1) // Check the SET indicator
  188.       IF nSegment == 1 ; acReturn := {} ; ENDIF
  189.       nPos := 1
  190.  
  191.       DO WHILE nPos < 128
  192.         cId := Substr(cReceive, nPos, 4)  // Read bindery ID
  193.         IF HILO2L(cId) == 0         // Check for end of segment
  194.           EXIT
  195.         ENDIF
  196.         cName := FN_BndOName(cId, @nObjType)    // Lookup Name & Type
  197.         Aadd(acReturn, {HILO2L(cId), cName, nObjType }) // and put in Return Array
  198.         nPos += 4           // then point to next ID
  199.       ENDDO
  200.  
  201.        ////////////////// ITEM Properties ///////////////////
  202.     ELSE
  203.       IF nSegment == 1 ; acReturn := "" ; ENDIF
  204.       acReturn += Left(cReceive, 128)
  205.  
  206.     ENDIF
  207.  
  208.     cSend := Stuff(cSend,53,1,I2BYTE(++nSegment))  // point to next segment
  209.  
  210.   ENDDO
  211.  
  212.   IF FN_Error() == NO_SUCH_SEGMENT .AND. !Empty(acReturn)  // 236
  213.     _fnSetErr(ESUCCESS)
  214.   ELSE
  215.     acReturn := nil
  216.   ENDIF
  217.  
  218.   IF !lKeepNulls .AND. ValType(acReturn) == "C"
  219.     acReturn := fn_noNull(acReturn)
  220.   ENDIF
  221.  
  222. RETURN (acReturn)
  223.