string TC_Parsepara::decodestr(const string &sParam) { string sBuffer(""); string::size_type pos = 0; while( pos < sParam.length()) { if(sParam[pos] == '%') { if (pos >= sParam.length() - 2) { break; } sBuffer += x2c(sParam.substr(pos + 1)); pos += 3; } else { sBuffer += sParam[pos]; pos++; } } return sBuffer; }
/* COMMAND "unescape": Convert hexadecimal representations to ASCII characters. * All sequences of the form "% HEX HEX" are unescaped. * SIGNATURE: unescape(str) : str; */ str unescape_str(str *retval, str s) { int x, y; str res; if (!s) throw(ILLARG, "url.escape", "url missing"); res = (str) GDKmalloc(strlen(s)); if (!res) throw(MAL, "url.unescape", "malloc failed"); for (x = 0, y = 0; s[x]; ++x, ++y) { if (s[x] == '%') { res[y] = x2c(&s[x + 1]); x += 2; } else { res[y] = s[x]; } } res[y] = '\0'; *retval = GDKrealloc(res, strlen(res)+1); return MAL_SUCCEED; }
void unescape_url(char *url){ register int x, y; for(x=0, y=0;url[y];++x, ++y){ if((url[x]=url[y])=='%'){ url[x]=x2c(&url[y+1]); y+=2; } } url[x]=0; }
void unescape_url( char *url ) { register int x, y; for ( x = 0, y = 0; url[y]; ++x, ++y ) { if ( ( ( url[x] = url[y] ) == '%' ) && isxdigit( url[y + 1] ) && isxdigit( url[y + 2] ) ) { url[x] = x2c( &url[y + 1] ); y += 2; } } url[x] = '\0'; }
// Reduce any %xx escape sequences to the characters they represent. void unescape_url(char *url) { register int i,j; for(i=0,j=0; url[j]; ++i,++j) { if((url[i] = url[j]) == '%') { url[i] = x2c(&url[j+1]) ; j+= 2 ; } } url[i] = '\0' ; }
/* * *** Ripped from HTTPD util.c (why are so many PORTABLE things not in APR UTIL?) * * Unescapes a URL, leaving reserved characters intact. * Returns 0 on success, non-zero on error * Failure is due to * bad % escape returns HTTP_BAD_REQUEST * * decoding %00 or a forbidden character returns HTTP_NOT_FOUND */ static int unescape_url(char *url, const char *forbid, const char *reserved) { register int badesc, badpath; char *x, *y; badesc = 0; badpath = 0; /* Initial scan for first '%'. Don't bother writing values before * seeing a '%' */ y = strchr(url, '%'); if (y == NULL) { return APR_SUCCESS; } for (x = y; *y; ++x, ++y) { if (*y != '%') { *x = *y; } else { if (!apr_isxdigit(*(y + 1)) || !apr_isxdigit(*(y + 2))) { badesc = 1; *x = '%'; } else { char decoded; decoded = x2c(y + 1); if ((decoded == '\0') || (forbid && strchr(forbid, decoded))) { badpath = 1; *x = decoded; y += 2; } else if (reserved && strchr(reserved, decoded)) { *x++ = *y++; *x++ = *y++; *x = *y; } else { *x = decoded; y += 2; } } } } *x = '\0'; if (badesc) { return APR_EINVAL; } else if (badpath) { return APR_EINVAL; } else { return APR_SUCCESS; } }
/* stolen from NCSA code */ static void unescape_url(char *url) { int x,y; for (x=0, y=0 ; url[y] ; ++x, ++y) { if((url[x] = url[y]) == '%') { url[x] = x2c(&url[y+1]); y+=2; } } url[x] = '\0'; }
// Reduce any %xx escape sequences to the characters they represent void CGIDemangler::unescape(char *url) { int i,j; for(i=0,j=0; url[j]; ++i,++j) { if((url[i] = url[j]) == '%') { url[i] = x2c(&url[j+1]) ; j+= 2 ; } } url[i] = '\0' ; }
/* Modified by Juris Feb 2007 */ void unescape_url (char *url) { int i, j; for (i = 0, j = 0; url[j]; ++i, ++j) { if ((url[i] = url[j]) != '%') continue; if (!url[j + 1] || !url[j + 2]) break; url[i] = x2c (&url[j + 1]); j += 2; } url[i] = '\0'; }
/** Reduce any %xx escape sequences to the characters they represent **/ void unescape_url(char *url) { register int i, j; char *p; char decoded; for (p = url; *p; p++) if (*p == '+') *p = ' '; for (i = 0, j = 0; url[j]; ++i, ++j) { if ((url[i] = url[j]) == '%') { decoded = x2c(&url[j + 1]); if (isprint(decoded)) { url[i] = decoded; } url[i] = x2c(&url[j + 1]); if (!url[j+1] || !url[j+2]) break; j += 2; } } url[i] = '\0'; }
/** Reduce any %xx escape sequences to the characters they represent. **/ void unescape_url(LString& url) { register int i,j; for(i=0,j=0; j<url.size(); ++i,++j) { if((url.at(i) = url[j]) == '%') { url.at(i) = x2c(url.at(j+1), url.at(j+2)); j+= 2 ; } } if (i < url.size()) url.at(i) = '\0' ; }
static int oidc_session_unescape_url(char *url, const char *forbid, const char *reserved) { register int badesc, badpath; char *x, *y; badesc = 0; badpath = 0; /* Initial scan for first '%'. Don't bother writing values before * seeing a '%' */ y = strchr(url, '%'); if (y == NULL) { return OK; } for (x = y; *y; ++x, ++y) { if (*y != '%') { *x = *y; } else { if (!apr_isxdigit(*(y + 1)) || !apr_isxdigit(*(y + 2))) { badesc = 1; *x = '%'; } else { char decoded; decoded = x2c(y + 1); if ((decoded == '\0') || (forbid && ap_strchr_c(forbid, decoded))) { badpath = 1; *x = decoded; y += 2; } else if (reserved && ap_strchr_c(reserved, decoded)) { *x++ = *y++; *x++ = *y++; *x = *y; } else { *x = decoded; y += 2; } } } } *x = '\0'; if (badesc) { return HTTP_BAD_REQUEST; } else if (badpath) { return HTTP_NOT_FOUND; } else { return OK; } }
/* x2c() and unescape_url() stolen from NCSA code */ void HttpRequestPacket::unescape_url(char *url) { register int x,y; for (x=0,y=0; url[y]; ++x,++y) { if((url[x] = url[y]) == '%') { url[x] = x2c(&url[y+1]); y+=2; } else if ( url[y] == '+' ) { url[x] = ' ';//space charset } } url[x] = '\0'; }
void unescape_url(char *url) { register int i, j; for (i = 0, j = 0; url[j]; ++i, ++j) { if ((url[i] = url[j]) == '%') { url[i] = x2c(&url[j + 1]); j += 2; } else if (url[i] == '+') url[i] = ' '; } url[i] = '\0'; /* terminate it at the new length */ }
void unescape_url(char *url) { register int x,y,len; len = strlen(url); for (x=0, y=0; url[y]; ++x, ++y) { if ((url[x] = url[y]) == '%' && y < len - 2) /* 2.0.4 - MJ Pomraning ([email protected]) */ { url[x] = x2c(&url[y+1]); y+=2; } } url[x] = '\0'; }
static int hex2bytes_inplace_3des(unsigned char *data, int len) { unsigned char *d = data; int i, count = 0; if ((data == NULL)||(len == 0)) return 0; for(i = 0; i <= len - 1; i++) { if(VALID_HEX(data[i]) && VALID_HEX(data[i+1])) { *d++ = x2c(&data[i]); i++; count++; } else { break; } } return count; }
/* returns a freshly malloc'ed and converted buffer */ char *au_unescape(char *buf) { int len, i; char saved, *str, *ptr = buf; /* Find the end of the name */ if (*ptr == '(') { ptr = strchr(ptr, ')'); if (ptr == NULL) return NULL; else ptr++; } else { while (isxdigit(*ptr)) ptr++; } saved = *ptr; *ptr = 0; str = strdup(buf); *ptr = saved; /* See if its '(null)' from the kernel */ if (*buf == '(') return str; /* We can get away with this since the buffer is 2 times * bigger than what we are putting there. */ len = strlen(str); if (len < 2) { free(str); return NULL; } ptr = str; for (i=0; i<len; i+=2) { *ptr = x2c((unsigned char *)&str[i]); ptr++; } *ptr = 0; return str; }
void L3Geom::applyLocalForceTorque(const Vector3r& localF, const Vector3r& localT, const Interaction* I, Scene* scene, NormShearPhys* nsp) const { Vector2r foo; // avoid undefined ~Vector2r with clang? #ifdef L3_TRSF_QUATERNION Vector3r globF=trsf.conjugate()*localF; #else Vector3r globF=trsf.transpose()*localF; // trsf is orthonormal, therefore inverse==transpose #endif Vector3r x1c(normal*(refR1+.5*u[0])), x2c(-normal*(refR2+.5*u[0])); if(nsp){ nsp->normalForce=normal*globF.dot(normal); nsp->shearForce=globF-nsp->normalForce; } Vector3r globT=Vector3r::Zero(); // add torque, if any #ifdef L3_TRSF_QUATERNION if(localT!=Vector3r::Zero()){ globT=trsf.conjugate()*localT; } #else if(localT!=Vector3r::Zero()){ globT=trsf.transpose()*localT; } #endif // apply force and torque scene->forces.addForce(I->getId1(), globF); scene->forces.addTorque(I->getId1(),x1c.cross( globF)+globT); scene->forces.addForce(I->getId2(),-globF); scene->forces.addTorque(I->getId2(),x2c.cross(-globF)-globT); }
/* returns a freshly malloc'ed and converted buffer */ char *unescape(const char *buf) { int len, i; char *str, *strptr; const char *ptr = buf; /* Find the end of the name */ if (*ptr == '(') { ptr = strchr(ptr, ')'); if (ptr == NULL) return NULL; else ptr++; } else { while (isxdigit(*ptr)) ptr++; } str = strndup(buf, ptr - buf); if (*buf == '(') return str; /* We can get away with this since the buffer is 2 times * bigger than what we are putting there. */ len = strlen(str); if (len < 2) { free(str); return NULL; } strptr = str; for (i=0; i<len; i+=2) { *strptr = x2c((unsigned char *)&str[i]); strptr++; } *strptr = 0; return str; }
/* * Unescapes a URL. * Returns 0 on success, non-zero on error * Failure is due to * bad % escape returns HTTP_BAD_REQUEST * * decoding %00 -> \0 (the null character) * decoding %2f -> / (a special character) * returns HTTP_NOT_FOUND */ AP_DECLARE(int) ap_unescape_url(char *url) { register int badesc, badpath; char *x, *y; badesc = 0; badpath = 0; /* Initial scan for first '%'. Don't bother writing values before * seeing a '%' */ y = strchr(url, '%'); if (y == NULL) { return OK; } for (x = y; *y; ++x, ++y) { if (*y != '%') *x = *y; else { if (!apr_isxdigit(*(y + 1)) || !apr_isxdigit(*(y + 2))) { badesc = 1; *x = '%'; } else { *x = x2c(y + 1); y += 2; if (IS_SLASH(*x) || *x == '\0') badpath = 1; } } } *x = '\0'; if (badesc) return HTTP_BAD_REQUEST; else if (badpath) return HTTP_NOT_FOUND; else return OK; }
ib_status_t ib_util_decode_url_ex(uint8_t *data_in, size_t dlen_in, size_t *dlen_out, ib_flags_t *result) { IB_FTRACE_INIT(); assert(data_in != NULL); assert(dlen_out != NULL); assert(result != NULL); uint8_t *out = data_in; uint8_t *in = data_in; uint8_t *end = data_in + dlen_in; bool modified = false; while (in < end) { if (*in == '%') { /* Character is a percent sign. */ /* Are there enough bytes available? */ if (in + 2 < end) { char c1 = *(in + 1); char c2 = *(in + 2); if (IS_HEX_CHAR(c1) && IS_HEX_CHAR(c2)) { /* Valid encoding - decode it. */ *out++ = x2c(in + 1); in += 3; modified = true; } else { /* Not a valid encoding, skip this % */ if (in == out) { ++out; ++in; } else { *out++ = *in++; modified = true; } } } else { /* Not enough bytes available, copy the raw bytes. */ if (in == out) { ++out; ++in; } else { *out++ = *in++; modified = true; } } } else { /* Character is not a percent sign. */ if (*in == '+') { *out++ = ' '; modified = true; } else if (out != in) { *out++ = *in; modified = true; } else { ++out; } ++in; } } *dlen_out = (out - data_in); *result = ( (modified == true) ? (IB_STRFLAG_ALIAS | IB_STRFLAG_MODIFIED) : IB_STRFLAG_ALIAS ); IB_FTRACE_RET_STATUS(IB_OK); }
ib_status_t ib_util_decode_url_cow_ex(ib_mpool_t *mp, const uint8_t *data_in, size_t dlen_in, uint8_t **data_out, size_t *dlen_out, ib_flags_t *result) { IB_FTRACE_INIT(); assert(mp != NULL); assert(data_in != NULL); assert(data_out != NULL); assert(dlen_out != NULL); assert(result != NULL); uint8_t *out = NULL; const uint8_t *in = data_in; const uint8_t *end = data_in + dlen_in; *data_out = NULL; while (in < end) { if (*in == '%') { /* Character is a percent sign. */ /* Are there enough bytes available? */ if (in + 2 < end) { char c1 = *(in + 1); char c2 = *(in + 2); if (IS_HEX_CHAR(c1) && IS_HEX_CHAR(c2)) { /* Valid encoding - decode it. */ out = ib_util_copy_on_write(mp, data_in, in, dlen_in, out, data_out, NULL); if (out == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } *out++ = x2c(in + 1); in += 3; } else { /* Not a valid encoding, skip this % */ if (out == NULL) { ++in; } else { *out++ = *in++; } } } else { /* Not enough bytes available, copy the raw bytes. */ if (out == NULL) { ++in; } else { *out++ = *in++; } } } else { /* Character is not a percent sign. */ if (*in == '+') { out = ib_util_copy_on_write(mp, data_in, in, dlen_in, out, data_out, NULL); if (out == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } *out++ = ' '; } else if (out != NULL) { *out++ = *in; } ++in; } } if (out == NULL) { *result = IB_STRFLAG_ALIAS; *data_out = (uint8_t *)data_in; *dlen_out = dlen_in; } else { *result = IB_STRFLAG_NEWBUF | IB_STRFLAG_MODIFIED; *dlen_out = out - *data_out; } IB_FTRACE_RET_STATUS(IB_OK); }