2016-01-25 73 views
0

我有一個Refer-To標題:關於「請參閱到」頭

Refer-To: <[email protected]?Target-Dialog=ksdjfhwrklf%3Bremote-tag=676723565%3Blocal-tag=45418454&Require=tdialog&From=tel:+1-237-555-1111&To=tel:+1-987-654-3210&Content-Type=application%2Fsdp&body=v%3D0%0D%0Ao%3D-%202987933623%202987933623%20IN%20IP6%205555::ggg:fff:aaa:bbb%0D%0As%3D-%0D%0Ac%3DIN%20IP6%205555::ggg:fff:aaa:bbb%0D%0At%3D0%200%0D%0Aaudio%203456%20RTP%2FAVP%2097%2096%0D%0Ab%3DAS:25.4%0D%0Aa%3Drtpmap:97%20AMR%0D%0Aa%3Dfmtp:97%20mode-set%3D0%2C2%2C5%2C7%3B%20mode-change-period%3D2%0D%0Aa%3Dmaxptime:20%0D%0A> 

在這頭,有很多的%3B%0D等。

我想知道如何將它們轉換爲人類可讀?

回答

-2

這裏是C方法的所有%XX轉換:

%XX的每次出現代表ASCII格式的字符 的十六進制值。例如,「%3D」 是 「=」

void 
__osip_uri_unescape (char *string) 
{ 
    size_t alloc = strlen (string) + 1; 
    unsigned char in; 
    int index = 0; 
    unsigned int hex; 
    char *ptr; 

    ptr = string; 
    while (--alloc > 0) { 
    in = *ptr; 
    if ('%' == in) { 
     /* encoded part */ 
     if (alloc > 2 && sscanf (ptr + 1, "%02X", &hex) == 1) { 
     in = (unsigned char) hex; 
     if (*(ptr + 2) && ((*(ptr + 2) >= '0' && *(ptr + 2) <= '9') || (*(ptr + 2) >= 'a' && *(ptr + 2) <= 'f') || (*(ptr + 2) >= 'A' && *(ptr + 2) <= 'F'))) { 
      alloc -= 2; 
      ptr += 2; 
     } 
     else { 
      alloc -= 1; 
      ptr += 1; 
     } 
     } 
     else { 
     break; 
     } 
    } 

    string[index++] = in; 
    ptr++; 
    } 
    string[index] = 0;   /* terminate it */ 
}