Merge "encode field separator characters"
This commit is contained in:
commit
3a056d690f
1 changed files with 58 additions and 4 deletions
|
@ -101,7 +101,6 @@ void LocEngAdapter::setXtraUserAgent() {
|
||||||
char release[PROPERTY_VALUE_MAX];
|
char release[PROPERTY_VALUE_MAX];
|
||||||
char manufacture[PROPERTY_VALUE_MAX];
|
char manufacture[PROPERTY_VALUE_MAX];
|
||||||
char model[PROPERTY_VALUE_MAX];
|
char model[PROPERTY_VALUE_MAX];
|
||||||
char carrier[PROPERTY_VALUE_MAX];
|
|
||||||
char board[PROPERTY_VALUE_MAX];
|
char board[PROPERTY_VALUE_MAX];
|
||||||
char brand[PROPERTY_VALUE_MAX];
|
char brand[PROPERTY_VALUE_MAX];
|
||||||
char chipsetsn[CHIPSET_SERIAL_NUMBER_MAX_LEN];
|
char chipsetsn[CHIPSET_SERIAL_NUMBER_MAX_LEN];
|
||||||
|
@ -111,13 +110,18 @@ void LocEngAdapter::setXtraUserAgent() {
|
||||||
property_get("ro.build.version.release", release, defVal);
|
property_get("ro.build.version.release", release, defVal);
|
||||||
property_get("ro.product.manufacturer", manufacture, defVal);
|
property_get("ro.product.manufacturer", manufacture, defVal);
|
||||||
property_get("ro.product.model", model, defVal);
|
property_get("ro.product.model", model, defVal);
|
||||||
property_get("ro.carrier", carrier, defVal);
|
|
||||||
property_get("ro.product.board", board, defVal);
|
property_get("ro.product.board", board, defVal);
|
||||||
property_get("ro.product.brand", brand, defVal);
|
property_get("ro.product.brand", brand, defVal);
|
||||||
getChipsetSerialNo(chipsetsn, sizeof(chipsetsn), defVal);
|
getChipsetSerialNo(chipsetsn, sizeof(chipsetsn), defVal);
|
||||||
|
|
||||||
snprintf(userAgent, sizeof(userAgent), "A/%s/%s/%s/%s/%s/QCX3/s%u/-/%s/-/%s/-/-/-",
|
encodeInPlace(release, PROPERTY_VALUE_MAX);
|
||||||
release, manufacture, model, board, carrier,
|
encodeInPlace(manufacture, PROPERTY_VALUE_MAX);
|
||||||
|
encodeInPlace(model, PROPERTY_VALUE_MAX);
|
||||||
|
encodeInPlace(board, PROPERTY_VALUE_MAX);
|
||||||
|
encodeInPlace(brand, PROPERTY_VALUE_MAX);
|
||||||
|
|
||||||
|
snprintf(userAgent, sizeof(userAgent), "A/%s/%s/%s/%s/-/QCX3/s%u/-/%s/-/%s/-/-/-",
|
||||||
|
release, manufacture, model, board,
|
||||||
mContext->getIzatDevId(), chipsetsn, brand);
|
mContext->getIzatDevId(), chipsetsn, brand);
|
||||||
|
|
||||||
for (int i = 0; i < sizeof(userAgent) && userAgent[i]; i++) {
|
for (int i = 0; i < sizeof(userAgent) && userAgent[i]; i++) {
|
||||||
|
@ -199,6 +203,56 @@ void LocEngAdapter::setXtraUserAgent() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* encode the given string value such that all separator characters ('/','+','|','%')
|
||||||
|
* in the string are repaced by their corresponding encodings (%2F","%2B","%7C", "%25")
|
||||||
|
*/
|
||||||
|
static void encodeInPlace(char value[], const int size) {
|
||||||
|
char buffer[size];
|
||||||
|
|
||||||
|
struct ENCODE {
|
||||||
|
const char ch;
|
||||||
|
const char *code;
|
||||||
|
};
|
||||||
|
|
||||||
|
const ENCODE encodings[] = { {'/', "%2F"}, {'+', "%2B"}, {'|', "%7C",}, {'%', "%25"} };
|
||||||
|
const int nencodings = (int)sizeof(encodings) / sizeof(encodings[0]);
|
||||||
|
|
||||||
|
int inpos = 0, outpos = 0;
|
||||||
|
while(value[inpos] != '\0' && outpos < size - 1) {
|
||||||
|
// check if escaped character
|
||||||
|
int escchar = 0;
|
||||||
|
while(escchar < nencodings && encodings[escchar].ch != value[inpos]) {
|
||||||
|
escchar++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (escchar == nencodings) {
|
||||||
|
// non escaped character
|
||||||
|
buffer[outpos++] = value[inpos++];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// escaped character
|
||||||
|
int codepos = 0;
|
||||||
|
#define NUM_CHARS_IN_CODE 3
|
||||||
|
|
||||||
|
if (outpos + NUM_CHARS_IN_CODE >= size) {
|
||||||
|
// skip last character if there is insufficient space
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(outpos < size - 1 && codepos < NUM_CHARS_IN_CODE) {
|
||||||
|
buffer[outpos++] = encodings[escchar].code[codepos++];
|
||||||
|
}
|
||||||
|
inpos++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// copy to ouput
|
||||||
|
value[outpos] = '\0';
|
||||||
|
while(--outpos >= 0) {
|
||||||
|
value[outpos] = buffer[outpos];
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
sendMsg(new LocSetXtraUserAgent(mContext));
|
sendMsg(new LocSetXtraUserAgent(mContext));
|
||||||
|
|
Loading…
Reference in a new issue