Exemplo n.º 1
0
dsmStatus_t
dsmBlobDmp(
    dsmContext_t        *pcontext,      /* IN database context */
    dsmBlob_t           *pBlob,         /* IN blob descriptor */
    GBOOL                 silent)        /* IN silent except if an error */
{
    dsmStatus_t   returnCode;
    dbcontext_t  *pdbcontext;
    xDbkey_t      xDbkey;        /* extended dbkey (area & recid) */
    LONG          recordSize, segRC;
    LONG          maxRecordSize;
    dsmBuffer_t *pRecord;       /* With the 1 byte indicator */
    dsmBuffer_t *pSegTab;       /* With the 1 byte indicator */
    dsmBuffer_t *pST;           /* within pSegTab */
    LONG          nent;          /* number seg tab entries */
    LONG          segLen;
    LONG          i;
    LONG         remainder;
    long	 tl;
    LONG          n_ds = 0, n_ss = 0;
    dsmBuffer_t  pName [] = "bozo";
    void         printf (...);

    TRACE_CB(pcontext, "dsmBlobDmp");

    pdbcontext = pcontext->pdbcontext;
    if (pdbcontext->usertype & SELFSERVE) 
    {
	if (pdbcontext->resyncing || lkservcon(pcontext))
	    return DSM_S_CTRLC;                  /* Self-service only */
    }

    xDbkey.dbkey = pBlob->blobId;

    if (!silent)
        printf ("\nBlobId: %10ld ", xDbkey.dbkey);

    returnCode = omIdToArea (pcontext, DSMOBJECT_BLOB, 
                             (COUNT)pBlob->blobObjNo, &(xDbkey.area));

    if (returnCode) {
        if (!silent)
            printf ("omIdToArea for object Type: %ld blobObjNo: %ld returned %ld <--\n",
                    DSMOBJECT_BLOB, pBlob->blobObjNo, returnCode);
        return returnCode;
    }

    pdbcontext->inservice++;
    
    maxRecordSize = DSMBLOBMAXLEN + 1;

    pRecord = (dsmBuffer_t *)utmalloc (maxRecordSize);
    if (!pRecord)
    {
        pdbcontext->inservice--;
        returnCode = DSM_S_BLOBNOMEMORY;
        return returnCode;
    }

    /* returns size of record if record is found.  Returns
     * a negative number if record is not found.
     */
    recordSize = rmFetchRecord(pcontext, xDbkey.area, xDbkey.dbkey, pRecord,
                            (COUNT)maxRecordSize, 0 /* not continuation */);
    if (recordSize == 4 && xlng (pRecord) == 0) 
    {
        pBlob->segLength = 0;
        returnCode = DSM_S_BLOBDNE;
        if (!silent)
            printf ("D.N.E. recordSize: 4, record: 0 0 0 0 <--\n");
    }
    else if (recordSize < 0) 
    {
        pBlob->segLength = 0;
	returnCode = (dsmStatus_t) recordSize;
        if (!silent)
            printf ("returnCode: %ld <--\n", returnCode);
    }
    else
    {
        returnCode =  DSM_S_BLOBOK;

        /* Set the total length of the blob */

        if (*pRecord == DSMBLOBDATA) 
        {
            n_ds++;
            pBlob->totLength = recordSize - 1;
        } else if (recordSize > 10)
            pBlob->totLength = xlng (pRecord + 7);
        else {
            pBlob->totLength = 0;
            returnCode = DSM_S_BLOBBAD;
        }

        if (!silent)
            printf ("Length: %10ld Type: %s\n", pBlob->totLength,
                    (char *) ((*pRecord == DSMBLOBDATA) ? "Direct" :
                              (*pRecord == DSMBLOBSEG) ? "Segmented" : "Bad <--"));
        tl = remainder = pBlob->totLength;

        if (returnCode == DSM_S_BLOBOK && *pRecord != DSMBLOBDATA) {
            if (xlng(pRecord+3) == 0)       /* Only 1 seg table */
                pSegTab = utmalloc (recordSize);
            else
                pSegTab = utmalloc (BLOBMAXSEGTAB);
            if (!pSegTab) 
            {
               utfree (pRecord);
               pdbcontext->inservice--;
               returnCode = DSM_S_BLOBNOMEMORY;
               return returnCode;
            }

            bufcop (pSegTab, pRecord, recordSize);

            while (returnCode == DSM_S_BLOBOK) 
            {
                n_ss++;
                pST = pSegTab + SEGHDR_LEN;
                nent = xct (pSegTab + 1);
                if (!silent) 
                    printf (" SegTab: %10ld number entries: %d %s\n", 
                            xDbkey.dbkey, nent, ((nent < 1 || nent > MAXSEGENT) ?
                                                 "<--" : ""));

                if (nent < 1 || nent > MAXSEGENT) 
                {
                    returnCode = DSM_S_BLOBBAD;
                    break;
                }
 
                for (i = 0; i < nent; i++, pST += SEGENT_LEN)
                {
                    segLen = xct (pST);
                    xDbkey.dbkey = xlng (pST + 2);
                    segRC = rmFetchRecord(pcontext, xDbkey.area,
                                       xDbkey.dbkey, pRecord,
                                       (COUNT)maxRecordSize, 0);
                    if (segRC <= 0) 
                    {
                        printf (" Seg%3d: %10ld returnCode: %d <--\n", i, 
                                xDbkey.dbkey, segRC);
                        returnCode = (dsmStatus_t)
                            (segRC ? segRC : DSM_S_BLOBBAD);
                        break;
                    }
                    if (segRC - 1 != xct (pST) || 
                        *pRecord != DSMBLOBDATA) 
                    {
                        printf (" Seg%3d: %10ld Len: %d ActualLen: %d type: %d <--\n",
                                i, xDbkey.dbkey, xct (pST), segRC - 1, *pRecord);
                        returnCode = DSM_S_BLOBBAD;
                        break;
                    }
                    if (!silent)
                         printf (" Seg%3d: %10ld Len: %d\n", i, xDbkey.dbkey, xct (pST));
                    n_ds++;
                    remainder -= xct (pST);
                } /* for i ... < nent */

                if (returnCode != DSM_S_BLOBOK)
                    break;

                xDbkey.dbkey = xlng (pSegTab + 3);

                if (!silent)
                    printf ("  N Seg: %10ld\n", xDbkey.dbkey);

                if (!xDbkey.dbkey) {
                    break;
                }
                returnCode = dbBlobFetch (pcontext, &xDbkey, pSegTab,
                                           BLOBMAXSEGTAB, 
                                           DSMBLOBSEG, pName);
            } /* while remainder */

            if (remainder)
                printf ("Length error: remainder: %10ld <--\n", remainder);

            utfree (pSegTab);

        } /* inital blob segemnt ok */
    } /* initial rmfetch ok */

    utfree (pRecord);

    pdbcontext->inservice--;
    if (!silent)
         printf ("tl: %10ld ds: %4d ss: %4d\n", tl, n_ds, n_ss);
    return returnCode;
}
Exemplo n.º 2
0
/* PROGRAM: recPutBYTES - Update a Field of a type byte_t (TEXT)
 *
 * RETURNS: RECSUCCESS
 *          RECTOOSMALL
 *          RECFLDNOTFOUND
 */
recStatus_t
recPutBYTES(
        TEXT            *precordBuffer, /* IN/OUT record buffer */
        ULONG            maxSize,       /* IN  size of input buffer */
        ULONG           *precSize,      /* OUT size of new rec or size needed */
        ULONG            fieldNumber,   /* IN  number of field within record */
        ULONG          arrayIndex,    /* IN  index in the array for array filed
                                             NULL for regular field  */
        svcByteString_t *pfieldValue,   /* IN  value to assign to the field */
        ULONG            indicator)     /* IN  indicator flag */
{
    /*** General steps to update a field in a record buffer ***/
    /* 1. Position to the field in the record.
     * 2. Convert data value to storage format.
     * 3. Call record manager to update the record.
     * 4. Update size with current record size or size of record needed.
     * 5. return pass or fail.
     */

    TEXT  *pfieldBuffer = (TEXT *)utmalloc(MAXRECSZ);
    TEXT  *pfield;                     /* Pointer to field within record */
    TEXT  *pArray;   /* ptr to begining of array within record */
    int    rc = RECSUCCESS;

    pfield = recFindField(precordBuffer, fieldNumber);
    if (pfield == NULL)
    {
        rc =  RECFLDNOTFOUND;
        goto done;
    }

    recFormatBYTES(pfieldBuffer, MAXRECSZ, pfieldValue->pbyte,
                                pfieldValue->length, indicator);

    if (*pfield == VECTOR)
    {
        pArray = pfield;
        pfield = recFindArrayElement(pfield, arrayIndex);
        if (pfield == NULL)
        {
            rc =  RECFLDNOTFOUND;
            goto done;
        }
        *precSize = recUpdateArray(precordBuffer, pArray,  *precSize,
                          maxSize, pfield, pfieldBuffer);
    }
    else
        *precSize = recUpdate(precordBuffer, *precSize, maxSize, pfield,
                          pfieldBuffer);

    if (*precSize > maxSize)
    {
        rc =  RECTOOSMALL;  /* no space or template requested */
        goto done;
    }

done:
    utfree(pfieldBuffer);
    return rc;

}  /* end recPutBYTES */