- Timestamp:
- Apr 21, 2009, 5:41:50 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lang/tcl/tests/encode.test
r1412 r1414 53 53 } {1 {wrong # args: should be "Rappture::encoding::is binary|encoded <string>"}} 54 54 55 test is-1.2.2 {Rappture::encoding::is, with an embedded null} {55 test is-1.2.2.0 {Rappture::encoding::is, with an embedded null} { 56 56 list [catch {Rappture::encoding::is binary "x\000x"} msg] $msg 57 57 } {0 yes} 58 59 test is-1.2.2.1 {Rappture::encoding::is, with an embedded start of heading} { 60 list [catch {Rappture::encoding::is binary "x\001x"} msg] $msg 61 } {0 yes} 62 63 test is-1.2.2.2 {Rappture::encoding::is, with an embedded start of text} { 64 list [catch {Rappture::encoding::is binary "x\002x"} msg] $msg 65 } {0 yes} 66 67 test is-1.2.2.3 {Rappture::encoding::is, with an embedded end of text} { 68 list [catch {Rappture::encoding::is binary "x\003x"} msg] $msg 69 } {0 yes} 70 71 test is-1.2.2.4 {Rappture::encoding::is, with an embedded end of transmission} { 72 list [catch {Rappture::encoding::is binary "x\004x"} msg] $msg 73 } {0 yes} 74 75 test is-1.2.2.5 {Rappture::encoding::is, with an embedded enquiry} { 76 list [catch {Rappture::encoding::is binary "x\005x"} msg] $msg 77 } {0 yes} 78 79 test is-1.2.2.6 {Rappture::encoding::is, with an embedded acknowledge} { 80 list [catch {Rappture::encoding::is binary "x\006x"} msg] $msg 81 } {0 yes} 82 83 test is-1.2.2.7 {Rappture::encoding::is, with an embedded bell} { 84 list [catch {Rappture::encoding::is binary "x\007x"} msg] $msg 85 } {0 yes} 86 87 test is-1.2.2.8 {Rappture::encoding::is, with an embedded backspace} { 88 list [catch {Rappture::encoding::is binary "x\010x"} msg] $msg 89 } {0 yes} 90 91 test is-1.2.2.9 {Rappture::encoding::is, with an embedded horizontal tab} { 92 list [catch {Rappture::encoding::is binary "x\011x"} msg] $msg 93 } {0 no} 94 95 test is-1.2.2.10 {Rappture::encoding::is, with an embedded newlines} { 96 list [catch {Rappture::encoding::is binary "x\012x"} msg] $msg 97 } {0 no} 98 99 test is-1.2.2.11 {Rappture::encoding::is, with an embedded vertical tab} { 100 list [catch {Rappture::encoding::is binary "x\013x"} msg] $msg 101 } {0 yes} 102 103 test is-1.2.2.12 {Rappture::encoding::is, with an embedded form feed} { 104 # this is encountered in spice, maybe abinit? 105 list [catch {Rappture::encoding::is binary "x\014x"} msg] $msg 106 } {0 yes} 107 108 test is-1.2.2.13 {Rappture::encoding::is, with an embedded carriage return} { 109 list [catch {Rappture::encoding::is binary "x\015x"} msg] $msg 110 } {0 no} 111 112 test is-1.2.2.14 {Rappture::encoding::is, with an embedded shift out} { 113 list [catch {Rappture::encoding::is binary "x\016x"} msg] $msg 114 } {0 yes} 115 116 test is-1.2.2.15 {Rappture::encoding::is, with an embedded space} { 117 list [catch {Rappture::encoding::is binary "x\040x"} msg] $msg 118 } {0 no} 119 120 #test is-1.2.2.16 {Rappture::encoding::is, with an embedded 8bit ascii char } { 121 # list [catch {Rappture::encoding::is binary "x\200x"} msg] $msg 122 #} {0 yes} 123 58 124 59 125 test is-1.3.1 {Rappture::encoding::is, encoded subcommand w/ false string} { -
trunk/src/core/RpEncode.cc
r1413 r1414 37 37 const char *cp, *endPtr; 38 38 for (cp = buf, endPtr = buf + size; cp < endPtr; cp++) { 39 if (!isprint(*cp)) { 40 return true; 41 } 39 if (((*cp >= '\000') && (*cp <= '\010')) || 40 ((*cp >= '\013') && (*cp <= '\014')) || 41 ((*cp >= '\016') && (*cp <= '\037')) || 42 ((*cp >= '\177') && (*cp <= '\377')) ) { 43 // data is binary 44 return true; 45 } 42 46 } 43 47 return false; … … 55 59 const char *cp, *endPtr; 56 60 for (cp = buf, endPtr = buf + size; cp < endPtr; cp++) { 57 58 59 61 if (((*cp < 'A') || (*cp > '/')) && (!isspace(*cp)) && (*cp != '=')) { 62 return false; 63 } 60 64 } 61 65 return true; … … 136 140 137 141 bool 138 Rappture::encoding::encode(Rappture::Outcome &status, Rappture::Buffer& buf, 139 142 Rappture::encoding::encode(Rappture::Outcome &status, Rappture::Buffer& buf, 143 unsigned int flags) 140 144 { 141 145 Rappture::Buffer outData; 142 146 143 147 if (buf.size() <= 0) { 144 return true;// Nothing to encode.148 return true; // Nothing to encode. 145 149 } 146 150 if ((flags & (RPENC_Z | RPENC_B64)) == 0) { 147 148 151 // By default compress and encode the string. 152 flags |= RPENC_Z | RPENC_B64; 149 153 } 150 154 if (outData.append(buf.bytes(), buf.size()) != (int)buf.size()) { 151 152 155 status.addError("can't append %lu bytes", buf.size()); 156 return false; 153 157 } 154 158 if (!outData.encode(status, flags)) { 155 159 return false; 156 160 } 157 161 buf.clear(); 158 162 if ((flags & RPENC_RAW) == 0) { 159 160 161 162 163 164 165 166 167 168 169 170 171 163 switch (flags & (RPENC_Z | RPENC_B64)) { 164 case RPENC_Z: 165 buf.append("@@RP-ENC:z\n", 11); 166 break; 167 case RPENC_B64: 168 buf.append("@@RP-ENC:b64\n", 13); 169 break; 170 case (RPENC_B64 | RPENC_Z): 171 buf.append("@@RP-ENC:zb64\n", 14); 172 break; 173 default: 174 break; 175 } 172 176 } 173 177 if (buf.append(outData.bytes(),outData.size()) != (int)outData.size()) { 174 175 178 status.addError("can't append %d bytes", outData.size()); 179 return false; 176 180 } 177 181 return true; … … 193 197 194 198 bool 195 Rappture::encoding::decode(Rappture::Outcome &status, Rappture::Buffer& buf, 196 199 Rappture::encoding::decode(Rappture::Outcome &status, Rappture::Buffer& buf, 200 unsigned int flags) 197 201 { 198 202 Rappture::Buffer outData; … … 203 207 size = buf.size(); 204 208 if (size == 0) { 205 return true;// Nothing to decode.209 return true; // Nothing to decode. 206 210 } 207 211 bytes = buf.bytes(); 208 212 if ((flags & RPENC_RAW) == 0) { 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 213 unsigned int headerFlags = 0; 214 if ((size > 11) && (strncmp(bytes, "@@RP-ENC:z\n", 11) == 0)) { 215 bytes += 11; 216 size -= 11; 217 headerFlags |= RPENC_Z; 218 } else if ((size > 13) && (strncmp(bytes, "@@RP-ENC:b64\n", 13) == 0)){ 219 bytes += 13; 220 size -= 13; 221 headerFlags |= RPENC_B64; 222 } else if ((size > 14) && (strncmp(bytes, "@@RP-ENC:zb64\n", 14) == 0)){ 223 bytes += 14; 224 size -= 14; 225 headerFlags |= (RPENC_B64 | RPENC_Z); 226 } 227 if (headerFlags != 0) { 228 unsigned int reqFlags; 229 230 reqFlags = flags & (RPENC_B64 | RPENC_Z); 231 /* 232 * If there's a header and the programmer also requested decoding 233 * flags, verify that the two are the same. We don't want to 234 * penalize the programmer for over-specifying. But we need to 235 * catch cases when they don't match. If you really want to 236 * override the header, you should also specify the RPENC_RAW flag 237 * (-noheader). 238 */ 239 if ((reqFlags != 0) && (reqFlags != headerFlags)) { 240 status.addError("decode flags don't match the header"); 241 return false; 242 } 243 flags |= headerFlags; 244 } 241 245 } 242 246 if ((flags & (RPENC_B64 | RPENC_Z)) == 0) { 243 return true;/* No decode or decompress flags present. */247 return true; /* No decode or decompress flags present. */ 244 248 } 245 249 if (outData.append(bytes, size) != (int)size) { 246 247 250 status.addError("can't append %d bytes to buffer", size); 251 return false; 248 252 } 249 253 if (!outData.decode(status, flags)) { 250 254 return false; 251 255 } 252 256 buf.move(outData); 253 257 return true; 254 258 } 259
Note: See TracChangeset
for help on using the changeset viewer.