Ignore:
Timestamp:
Jan 7, 2009 9:31:14 AM (14 years ago)
Author:
dkearney
Message:

fixing rp library's get() function for retrieving encoded data. if the data is encoded there is no need to do xml entity translation. adding a function rappture's encode class for checking to see if a string has a proper header encode header. adding corresponding tcl functions and tests. also adjusting some of the int declarations to size_t.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/RpEncode.cc

    r1051 r1264  
    3434isbinary(const char* buf, int size)
    3535{
     36    if (buf == NULL) {
     37        return 0;
     38    }
     39
    3640    if (size < 0) {
    3741        size = strlen(buf);
     
    5155}
    5256
    53 
    54 
    55 
     57/**********************************************************************/
     58// FUNCTION: Rappture::encoding::isencoded()
     59/// checks header of given string to determine if it was encoded by rappture.
     60/**
     61 * Checks to see if the string buf was encoded by rappture
     62 * and contains the proper "@@RP-ENC:" header.
     63 * rappture encoded strings start with the string "@@RP-ENC:X\n"
     64 * where X is one of z, b64, zb64
     65 * This function will not work for strings that do not have the header.
     66 * Full function call:
     67 * Rappture::encoding::isencoded(buf,size);
     68 *
     69 */
     70
     71size_t
     72isencoded(const char* buf, int size)
     73{
     74    size_t flags = 0;
     75    size_t len = 0;
     76
     77    if (buf == NULL) {
     78        return flags;
     79    }
     80
     81    if (size < 0) {
     82        len = strlen(buf);
     83    } else {
     84        len = size;
     85    }
     86
     87    // check the following for valid rappture encoded string:
     88    // all strings encoded by rappture are at least 11 characters
     89    // rappture encoded strings start with the '@' character
     90    // rappture encoded strings start with the string "@@RP-ENC:X\n"
     91    // where X is one of z, b64, zb64
     92    if (    (len >= 11)
     93        &&  ('@' == *buf)
     94        &&  (strncmp("@@RP-ENC:",buf,9) == 0) ) {
     95
     96        size_t idx = 9;
     97
     98        // check the string length and if the z flag was specified
     99        // add 1 for \n
     100        if (    (len >= (idx + 1))
     101            &&  (buf[idx] == 'z') ) {
     102            flags |= RPENC_Z;
     103            ++idx;
     104        }
     105        // check the string length and if the b64 flag was specified
     106        // add 1 for \n
     107        if (    (len >= (idx + 2 + 1))
     108            &&  (buf[idx]   == 'b')
     109            &&  (buf[idx+1] == '6')
     110            &&  (buf[idx+2] == '4') ) {
     111            flags |= RPENC_B64;
     112            idx += 3;
     113        }
     114        // check for the '\n' at the end of the header
     115        if (buf[idx] != '\n') {
     116            flags = 0;
     117        }
     118    }
     119
     120    return flags;
     121}
    56122
    57123/**********************************************************************/
     
    66132
    67133Rappture::Outcome
    68 encode (Rappture::Buffer& buf, int flags)
     134encode (Rappture::Buffer& buf, size_t flags)
    69135{
    70136
     
    125191
    126192Rappture::Outcome
    127 decode (Rappture::Buffer& buf, int flags)
     193decode (Rappture::Buffer& buf, size_t flags)
    128194{
    129195
Note: See TracChangeset for help on using the changeset viewer.