void parse_banner(const std::string& banner, atransport* t) { D("parse_banner: %s", banner.c_str()); // The format is something like: // "device::ro.product.name=x;ro.product.model=y;ro.product.device=z;". std::vector<std::string> pieces = android::base::Split(banner, ":"); // Reset the features list or else if the server sends no features we may // keep the existing feature set (http://b/24405971). t->SetFeatures(""); if (pieces.size() > 2) { const std::string& props = pieces[2]; for (const auto& prop : android::base::Split(props, ";")) { // The list of properties was traditionally ;-terminated rather than ;-separated. if (prop.empty()) continue; std::vector<std::string> key_value = android::base::Split(prop, "="); if (key_value.size() != 2) continue; const std::string& key = key_value[0]; const std::string& value = key_value[1]; if (key == "ro.product.name") { qual_overwrite(&t->product, value); } else if (key == "ro.product.model") { qual_overwrite(&t->model, value); } else if (key == "ro.product.device") { qual_overwrite(&t->device, value); } else if (key == "features") { t->SetFeatures(value); } } } const std::string& type = pieces[0]; if (type == "bootloader") { D("setting connection_state to kCsBootloader"); t->connection_state = kCsBootloader; update_transports(); } else if (type == "device") { D("setting connection_state to kCsDevice"); t->connection_state = kCsDevice; update_transports(); } else if (type == "recovery") { D("setting connection_state to kCsRecovery"); t->connection_state = kCsRecovery; update_transports(); } else if (type == "sideload") { D("setting connection_state to kCsSideload"); t->connection_state = kCsSideload; update_transports(); } else { D("setting connection_state to kCsHost"); t->connection_state = kCsHost; } }
void parse_banner(const char* banner, atransport* t) { D("parse_banner: %s\n", banner); // The format is something like: // "device::ro.product.name=x;ro.product.model=y;ro.product.device=z;". std::vector<std::string> pieces = android::base::Split(banner, ":"); if (pieces.size() > 2) { const std::string& props = pieces[2]; for (auto& prop : android::base::Split(props, ";")) { // The list of properties was traditionally ;-terminated rather than ;-separated. if (prop.empty()) continue; std::vector<std::string> key_value = android::base::Split(prop, "="); if (key_value.size() != 2) continue; const std::string& key = key_value[0]; const std::string& value = key_value[1]; if (key == "ro.product.name") { qual_overwrite(&t->product, value); } else if (key == "ro.product.model") { qual_overwrite(&t->model, value); } else if (key == "ro.product.device") { qual_overwrite(&t->device, value); } } } const std::string& type = pieces[0]; if (type == "bootloader") { D("setting connection_state to CS_BOOTLOADER\n"); t->connection_state = CS_BOOTLOADER; update_transports(); } else if (type == "device") { D("setting connection_state to CS_DEVICE\n"); t->connection_state = CS_DEVICE; update_transports(); } else if (type == "recovery") { D("setting connection_state to CS_RECOVERY\n"); t->connection_state = CS_RECOVERY; update_transports(); } else if (type == "sideload") { D("setting connection_state to CS_SIDELOAD\n"); t->connection_state = CS_SIDELOAD; update_transports(); } else { D("setting connection_state to CS_HOST\n"); t->connection_state = CS_HOST; } }
void parse_banner(char *banner, atransport *t) { static const char *prop_seps = ";"; static const char key_val_sep = '='; char *cp; char *type; D("parse_banner: %s\n", banner); type = banner; cp = strchr(type, ':'); if (cp) { *cp++ = 0; /* Nothing is done with second field. */ cp = strchr(cp, ':'); if (cp) { char *save; char *key; key = adb_strtok_r(cp + 1, prop_seps, &save); while (key) { cp = strchr(key, key_val_sep); if (cp) { *cp++ = '\0'; if (!strcmp(key, "ro.product.name")) qual_overwrite(&t->product, cp); else if (!strcmp(key, "ro.product.model")) qual_overwrite(&t->model, cp); else if (!strcmp(key, "ro.product.device")) qual_overwrite(&t->device, cp); } key = adb_strtok_r(NULL, prop_seps, &save); } } } if(!strcmp(type, "bootloader")){ D("setting connection_state to CS_BOOTLOADER\n"); t->connection_state = CS_BOOTLOADER; update_transports(); return; } if(!strcmp(type, "device")) { D("setting connection_state to CS_DEVICE\n"); t->connection_state = CS_DEVICE; update_transports(); return; } if(!strcmp(type, "recovery")) { D("setting connection_state to CS_RECOVERY\n"); t->connection_state = CS_RECOVERY; update_transports(); return; } if(!strcmp(type, "sideload")) { D("setting connection_state to CS_SIDELOAD\n"); t->connection_state = CS_SIDELOAD; update_transports(); return; } t->connection_state = CS_HOST; }