Ver Mensaje Individual
  #2 (permalink)  
Antiguo 28/02/2014, 05:09
Avatar de enlinea777
enlinea777
 
Fecha de Ingreso: mayo-2008
Ubicación: frente al pc
Mensajes: 1.830
Antigüedad: 15 años, 11 meses
Puntos: 127
Respuesta: Cómo decodificar una URL con script CGI??

en google hay mucha informacion

https://www.google.cl/search?q=c%2B%...HoBQ&gws_rd=cr


Para muestra un boton:
Código C++:
Ver original
  1. #include <assert.h>
  2.  
  3. void urldecode(char *pszDecodedOut, size_t nBufferSize, const char *pszEncodedIn)
  4. {
  5.     memset(pszDecodedOut, 0, nBufferSize);
  6.  
  7.     enum DecodeState_e
  8.     {
  9.         STATE_SEARCH = 0, ///< searching for an ampersand to convert
  10.         STATE_CONVERTING, ///< convert the two proceeding characters from hex
  11.     };
  12.  
  13.     DecodeState_e state = STATE_SEARCH;
  14.  
  15.     for(unsigned int i = 0; i < strlen(pszEncodedIn)-1; ++i)
  16.     {
  17.         switch(state)
  18.         {
  19.         case STATE_SEARCH:
  20.             {
  21.                 if(pszEncodedIn[i] != '%')
  22.                 {
  23.                     strncat(pszDecodedOut, &pszEncodedIn[i], 1);
  24.                     assert(strlen(pszDecodedOut) < nBufferSize);
  25.                     break;
  26.                 }
  27.  
  28.                 // We are now converting
  29.                 state = STATE_CONVERTING;
  30.             }
  31.             break;
  32.  
  33.         case STATE_CONVERTING:
  34.             {
  35.                 // Conversion complete (i.e. don't convert again next iter)
  36.                 state = STATE_SEARCH;
  37.  
  38.                 // Create a buffer to hold the hex. For example, if %20, this
  39.                 // buffer would hold 20 (in ASCII)
  40.                 char pszTempNumBuf[3] = {0};
  41.                 strncpy(pszTempNumBuf, &pszEncodedIn[i], 2);
  42.  
  43.                 // Ensure both characters are hexadecimal
  44.                 bool bBothDigits = true;
  45.  
  46.                 for(int j = 0; j < 2; ++j)
  47.                 {
  48.                     if(!isxdigit(pszTempNumBuf[j]))
  49.                         bBothDigits = false;
  50.                 }
  51.  
  52.                 if(!bBothDigits)
  53.                     break;
  54.  
  55.                 // Convert two hexadecimal characters into one character
  56.                 int nAsciiCharacter;
  57.                 sscanf(pszTempNumBuf, "%x", &nAsciiCharacter);
  58.  
  59.                 // Ensure we aren't going to overflow
  60.                 assert(strlen(pszDecodedOut) < nBufferSize);
  61.  
  62.                 // Concatenate this character onto the output
  63.                 strncat(pszDecodedOut, (char*)&nAsciiCharacter, 1);
  64.  
  65.                 // Skip the next character
  66.                 i++;
  67.             }
  68.             break;
  69.         }
  70.     }
  71. }