Changeset 652


Ignore:
Timestamp:
Mar 30, 2007, 2:23:39 PM (18 years ago)
Author:
dkearney
Message:

adding @@RP-ENC back to the encoded string so we can better tell how we changed the data
added the zb64 flag
updated buffer code to better handle the case when encode and decode are called,
but the user does not specify what they want done, now the default is to do nothing
instead of erasing the data.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/tcl/src/RpEncodeTclInterface.cc

    r650 r652  
    162162 *
    163163 * Full function call:
    164  * ::Rappture::encoding::encode ?-as z|b64? <string>
     164 * ::Rappture::encoding::encode ?-as z|b64|zb64? <string>
    165165 */
    166166
     
    194194        Tcl_AppendResult(interp,
    195195                "wrong # args: should be \"", cmdName,
    196                 " ?-as z|b64? <string>\"", (char*)NULL);
     196                " ?-as z|b64|zb64? <string>\"", (char*)NULL);
    197197        return TCL_ERROR;
    198198    }
     
    210210                        (strncmp(encodeType,"z",typeLen) == 0) ) {
    211211                compress = 1;
    212                 base64 = 1;
     212                base64 = 0;
    213213            }
    214214            else if (   (typeLen == 3) &&
    215215                        (strncmp(encodeType,"b64",typeLen) == 0) ) {
    216216                compress = 0;
     217                base64 = 1;
     218            }
     219            else if (   (typeLen == 4) &&
     220                        (strncmp(encodeType,"zb64",typeLen) == 0) ) {
     221                compress = 1;
    217222                base64 = 1;
    218223            }
     
    224229                }
    225230                Tcl_AppendResult(interp,
    226                         "\": should be one of z, b64",
     231                        "\": should be one of z, b64, zb64",
    227232                        (char*)NULL);
    228233                return TCL_ERROR;
     
    241246        Tcl_AppendResult(interp,
    242247                "wrong # args: should be \"", cmdName,
    243                 " ?-as z|b64? <string>\"", (char*)NULL);
     248                " ?-as z|b64|zb64? <string>\"", (char*)NULL);
    244249        return TCL_ERROR;
    245250    }
    246251
    247252    option = Tcl_GetStringFromObj(objv[nextarg++], &optionLen);
    248     buf = Rappture::Buffer(option,optionLen);
     253
     254    if (strncmp(option,"@@RP-ENC:z\n",11) == 0) {
     255        buf = Rappture::Buffer(option+11,optionLen-11);
     256        buf.decode(1,0);
     257    }
     258    else if (strncmp(option,"@@RP-ENC:b64\n",13) == 0) {
     259        buf = Rappture::Buffer(option+13,optionLen-13);
     260        buf.decode(0,1);
     261    }
     262    else if (strncmp(option,"@@RP-ENC:zb64\n",14) == 0) {
     263        buf = Rappture::Buffer(option+14,optionLen-14);
     264        buf.decode(1,1);
     265    }
     266    else {
     267        // no special recognized tags
     268        buf = Rappture::Buffer(option,optionLen);
     269    }
    249270
    250271    buf.encode(compress,base64);
    251272    result = Tcl_GetObjResult(interp);
     273
     274    if ((compress == 1) && (base64 == 0)) {
     275        Tcl_AppendToObj(result,"@@RP-ENC:z\n",11);
     276    }
     277    else if ((compress == 0) && (base64 == 1)) {
     278        Tcl_AppendToObj(result,"@@RP-ENC:b64\n",13);
     279    }
     280    else if ((compress == 1) && (base64 == 1)) {
     281        Tcl_AppendToObj(result,"@@RP-ENC:zb64\n",14);
     282    }
     283    else {
     284        // do nothing
     285    }
     286
    252287    Tcl_AppendToObj(result,buf.bytes(),buf.size());
    253288
     
    264299 *
    265300 * Full function call:
    266  * ::Rappture::encoding::decode ?-as z|b64? <string>
     301 * ::Rappture::encoding::decode ?-as z|b64|zb64? <string>
    267302 */
    268303
     
    296331        Tcl_AppendResult(interp,
    297332                "wrong # args: should be \"", cmdName,
    298                 " ?-as z|b64? <string>\"", (char*)NULL);
     333                " ?-as z|b64|zb64? <string>\"", (char*)NULL);
    299334        return TCL_ERROR;
    300335    }
     
    312347                        (strncmp(encodeType,"z",typeLen) == 0) ) {
    313348                decompress = 1;
    314                 base64 = 1;
     349                base64 = 0;
    315350            }
    316351            else if (   (typeLen == 3) &&
    317352                        (strncmp(encodeType,"b64",typeLen) == 0) ) {
    318353                decompress = 0;
     354                base64 = 1;
     355            }
     356            else if (   (typeLen == 4) &&
     357                        (strncmp(encodeType,"zb64",typeLen) == 0) ) {
     358                decompress = 1;
    319359                base64 = 1;
    320360            }
     
    326366                }
    327367                Tcl_AppendResult(interp,
    328                         "\": should be one of z, b64",
     368                        "\": should be one of z, b64, zb64",
    329369                        (char*)NULL);
    330370                return TCL_ERROR;
     
    343383        Tcl_AppendResult(interp,
    344384                "wrong # args: should be \"", cmdName,
    345                 " ?-as z|b64? <string>\"", (char*)NULL);
     385                " ?-as z|b64|zb64? <string>\"", (char*)NULL);
    346386        return TCL_ERROR;
    347387    }
    348388
    349389    option = Tcl_GetStringFromObj(objv[nextarg++], &optionLen);
    350     if (encodeType == NULL) {
    351         if (strncmp(option,"H4sI",4) == 0) {
    352             decompress = 1;
    353             base64 = 1;
    354         }
    355         else {
    356             // user did not specify how to treat data
    357             // and we cannot guess based on the header.
    358             // return data
    359             Tcl_AppendResult(interp,option,(char*)NULL);
    360             return TCL_OK;
    361         }
    362     }
    363 
    364     buf = Rappture::Buffer(option,optionLen);
    365     buf.decode(decompress,base64);
    366 
     390
     391    if (strncmp(option,"@@RP-ENC:z\n",11) == 0) {
     392        buf = Rappture::Buffer(option+11,optionLen-11);
     393        buf.decode(1,0);
     394    }
     395    else if (strncmp(option,"@@RP-ENC:b64\n",13) == 0) {
     396        buf = Rappture::Buffer(option+13,optionLen-13);
     397        buf.decode(0,1);
     398    }
     399    else if (strncmp(option,"@@RP-ENC:zb64\n",14) == 0) {
     400        buf = Rappture::Buffer(option+14,optionLen-14);
     401        buf.decode(1,1);
     402    }
     403    else {
     404        // no special recognized tags
     405        buf = Rappture::Buffer(option,optionLen);
     406        buf.decode(decompress,base64);
     407    }
     408
     409    // buf.decode(decompress,base64);
    367410    result = Tcl_GetObjResult(interp);
     411
     412    /*
     413    if ((decompress == 1) && (base64 == 0)) {
     414        Tcl_AppendToObj(result,"@@RP-ENC:z\n",11);
     415        buf.encode(0,1);
     416    }
     417    else if ((decompress == 0) && (base64 == 1)) {
     418        Tcl_AppendToObj(result,"@@RP-ENC:b64\n",13);
     419    }
     420    else if ((decompress == 1) && (base64 == 1)) {
     421        Tcl_AppendToObj(result,"@@RP-ENC:zb64\n",14);
     422    }
     423    else {
     424        // do nothing
     425    }
     426    */
     427
    368428    Tcl_AppendToObj(result,buf.bytes(),buf.size());
    369429
  • trunk/src/tcl/tests/encode.test

    r649 r652  
    6161test encode-2.0.0 {Rappture::encoding::encode, 0 arguments} {
    6262    list [catch {Rappture::encoding::encode} msg] $msg
    63 } {1 {wrong # args: should be "Rappture::encoding::encode ?-as z|b64? <string>"}}
     63} {1 {wrong # args: should be "Rappture::encoding::encode ?-as z|b64|zb64? <string>"}}
    6464
    6565test encode-2.1.0 {Rappture::encoding::encode, ascii string argument} {
    6666    list [catch {Rappture::encoding::encode "hi"} msg] $msg
    67 } {0 {H4sIAAAAAAAAA8vIBACsKpPYAgAAAA==
     67} {0 {@@RP-ENC:zb64
     68H4sIAAAAAAAAA8vIBACsKpPYAgAAAA==
    6869}}
    6970
     
    7273    set b [Rappture::encoding::decode -as b64 $h]
    7374    list [catch {Rappture::encoding::encode $b} msg] $msg
    74 } {0 {H4sIAAAAAAAAA5Pv5mAAA+bTJ1gY1mhNvsEE5AAAFVLsvBYAAAA=
     75} {0 {@@RP-ENC:zb64
     76H4sIAAAAAAAAA5Pv5mAAA+bTJ1gY1mhNvsEE5AAAFVLsvBYAAAA=
    7577}}
    7678
    7779test encode-2.2.0 {Rappture::encoding::encode, -as flag blank value} {
    7880    list [catch {Rappture::encoding::encode -as} msg] $msg
    79 } {1 {bad value "": should be one of z, b64}}
     81} {1 {bad value "": should be one of z, b64, zb64}}
    8082
    8183test encode-2.2.1 {Rappture::encoding::encode, -as flag bad value } {
    8284    list [catch {Rappture::encoding::encode -as zz} msg] $msg
    83 } {1 {bad value "zz": should be one of z, b64}}
     85} {1 {bad value "zz": should be one of z, b64, zb64}}
    8486
    8587test encode-2.2.2 {Rappture::encoding::encode, -as flag correct value z} {
    8688    list [catch {Rappture::encoding::encode -as z} msg] $msg
    87 } {1 {wrong # args: should be "Rappture::encoding::encode ?-as z|b64? <string>"}}
     89} {1 {wrong # args: should be "Rappture::encoding::encode ?-as z|b64|zb64? <string>"}}
    8890
    8991test encode-2.2.3 {Rappture::encoding::encode, -as z w/ string} {
    9092    list [catch {Rappture::encoding::encode -as z "hi"} msg] $msg
    91 } {0 {H4sIAAAAAAAAA8vIBACsKpPYAgAAAA==
    92 }}
     93} {0 {@@RP-ENC:z
     94\xCB\xC8\x3F\x2A\x3F\xD8}}
    9395
    9496test encode-2.2.4 {Rappture::encoding::encode, -as b64 w/ string} {
    9597    list [catch {Rappture::encoding::encode -as b64 "hi"} msg] $msg
    96 } {0 {aGk=
     98} {0 {@@RP-ENC:b64
     99aGk=
    97100}}
    98101
     
    105108test decode-3.0.0 {Rappture::encoding::decode, 0 arguments} {
    106109    list [catch {Rappture::encoding::decode} msg] $msg
    107 } {1 {wrong # args: should be "Rappture::encoding::decode ?-as z|b64? <string>"}}
     110} {1 {wrong # args: should be "Rappture::encoding::decode ?-as z|b64|zb64? <string>"}}
    108111
    109112test decode-3.1.0 {Rappture::encoding::decode, 1 arg, b64 encoded} {
     
    112115} {0 aGk=}
    113116
    114 test decode-3.1.1 {Rappture::encoding::decode, 1 arg, z encoded} {
    115     set h "H4sIAAAAAAAAA8vIBACsKpPYAgAAAA=="
     117test decode-3.1.1 {Rappture::encoding::decode, 1 arg, zb64 encoded} {
     118    set h "@@RP-ENC:zb64\nH4sIAAAAAAAAA8vIBACsKpPYAgAAAA=="
    116119    list [catch {Rappture::encoding::decode $h} msg] $msg
    117120} {0 hi}
     
    119122test decode-3.1.2 {Rappture::encoding::decode, 2 args} {
    120123    list [catch {Rappture::encoding::decode "hi" "bye"} msg] $msg
    121 } {1 {wrong # args: should be "Rappture::encoding::decode ?-as z|b64? <string>"}}
     124} {1 {wrong # args: should be "Rappture::encoding::decode ?-as z|b64|zb64? <string>"}}
    122125
    123126test decode-3.2.0 {Rappture::encoding::decode, -as flag, no value} {
    124127    list [catch {Rappture::encoding::decode -as} msg] $msg
    125 } {1 {bad value "": should be one of z, b64}}
     128} {1 {bad value "": should be one of z, b64, zb64}}
    126129
    127130test decode-3.2.1 {Rappture::encoding::decode, -as flag, bad value} {
    128131    list [catch {Rappture::encoding::decode -as zz} msg] $msg
    129 } {1 {bad value "zz": should be one of z, b64}}
     132} {1 {bad value "zz": should be one of z, b64, zb64}}
    130133
    131 test decode-3.2.2 {Rappture::encoding::decode, -as flag, z w/ string} {
    132     set h "H4sIAAAAAAAAA8vIBACsKpPYAgAAAA=="
     134test decode-3.2.2 {Rappture::encoding::decode, -as flag, zb64 w/ string} {
     135    set h "@@RP-ENC:zb64\nH4sIAAAAAAAAA8vIBACsKpPYAgAAAA=="
    133136    list [catch {Rappture::encoding::decode -as z $h} msg] $msg
    134137} {0 hi}
    135138
    136139test decode-3.2.3 {Rappture::encoding::decode, -as flag, b64 w/ string} {
    137     set h "aGk="
     140    set h "@@RP-ENC:b64\naGk="
    138141    list [catch {Rappture::encoding::decode -as b64 $h} msg] $msg
    139142} {0 hi}
  • trunk/src2/core/RpBuffer.cc

    r621 r652  
    627627    SimpleBuffer bout;
    628628
     629    if ((base64 == 0) && (compress == 0)) {
     630        return err;
     631    }
     632
    629633    err.addContext("Rappture::Buffer::encode()");
    630 
    631634    rewind();
    632635
     
    664667    SimpleBuffer bout;
    665668
     669    if ((base64 == 0) && (decompress == 0)) {
     670        return err;
     671    }
     672
     673    err.addContext("Rappture::Buffer::decode()");
    666674    rewind();
    667675
Note: See TracChangeset for help on using the changeset viewer.