Changeset 1264 for trunk/src/core/RpEncode.cc
- Timestamp:
- Jan 7, 2009 9:31:14 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/RpEncode.cc
r1051 r1264 34 34 isbinary(const char* buf, int size) 35 35 { 36 if (buf == NULL) { 37 return 0; 38 } 39 36 40 if (size < 0) { 37 41 size = strlen(buf); … … 51 55 } 52 56 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 71 size_t 72 isencoded(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 } 56 122 57 123 /**********************************************************************/ … … 66 132 67 133 Rappture::Outcome 68 encode (Rappture::Buffer& buf, int flags)134 encode (Rappture::Buffer& buf, size_t flags) 69 135 { 70 136 … … 125 191 126 192 Rappture::Outcome 127 decode (Rappture::Buffer& buf, int flags)193 decode (Rappture::Buffer& buf, size_t flags) 128 194 { 129 195
Note: See TracChangeset
for help on using the changeset viewer.