| #include "web_api.h" int escape_url_character(char *data, int data_len) { char * transfer_table[][2] = { {"+", "2B"}, {"[","5B"},{"]","5D"},{"`","60"}, {";","3B"},{"/","2F"},{"?","3F"},{":","3A"}, {"@","40"},{"=","3D"},{"&","26"},{"$","24"}, {" ","20"},{"<","3C"},{">","3E"},{"#","23"}, {"%","25"},{"{","7B"},{"}","7D"},{"|","7C"}, {"\\","5C"},{"^","5E"},{"~","7E"}, {NULL, NULL} }; int i = 0, j; char *buf = (char*) calloc(data_len + 1, sizeof(char)); while( i < data_len ){ if( '%' != data[i]){ strncat(buf, data+i, 1); i++; continue; } j = 0; while( NULL != transfer_table[j][1] ){ if( 0 == strncmp(data+i+1, transfer_table[j][1], 2 )){ strncat(buf, transfer_table[j][0], 1); i += 3; break; } j++; } if( NULL == transfer_table[j][1] ){ strncat(buf, data+i, 1); /* printf("escape_url_character: unhandled sequence: %s\n", data+i);*/ i++; } } memset(data, 0, data_len); strcpy(data, buf); free(buf); return 0; } Action() { return 0; } |
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/20652124/viewspace-664107/ ,如需转载,请注明出处,否则将追究法律责任。