I was trying to read all the virtual_capability with the wurfl.xml file (<ver>data.scientiamobile.com - 2016-03-27 00:30:33</ver>).
But wurfl_device_get_virtual_capability(hd, capability); is returning NULL always even wurfl.xml file having virtual_capability the node.
Library version installed is libwurfl-1.4.4.1-1.x86_64
Example:
<device id="generic_smarttv_chromecast" user_agent="Mozilla/5.0 (CrKey armv7l 1.4.15250) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.0 Safari/537.36" fall_back="generic_smarttv_browser">
<group id="product_info">
<capability name="model_name" value="Chromecast"/>
<capability name="brand_name" value="Google"/>
<capability name="release_date" value="2013_july"/>
</group>
<group id="virtual">
<capability name="controlcap_advertised_device_os" value="Chromecast"/>
</group>
</device>
Code Below:
Code: Select all
#define WURFL_FILE "wurfl.xml"
#define WURFL_DATA_FILE "device_capabilities.csv"
/* Extract WURFL device data file in CSV format*/
int function_wurfl_extract_data() {
wurfl_handle hwurfl = wurfl_create();
if(wurfl_set_root(hwurfl, WURFL_FILE) != WURFL_OK) {
fprintf(stderr, "%s\n", wurfl_get_error_message(hwurfl));
return 0;
}
if (wurfl_load(hwurfl) != WURFL_OK) {
fprintf(stderr, "%s\n", wurfl_get_error_message(hwurfl));
return 0;
}
if(!hwurfl) {
fprintf(stderr, "initialize wurfl handler from wurfl.xml failed\n");
return -1;
}
std::ifstream infile(WURFL_FILE);
std::ofstream ofile(WURFL_DATA_FILE, std::ofstream::out | std::ofstream::trunc);
std::string line;
char datetime[20];
ut_get_time_now(datetime, 20);
while(getline(infile, line)) {
int pos1 = line.find("device id=\"");
if(pos1 >= 0) {
int pos2 = line.find("\"", pos1+11);
if(pos2 > pos1+11) {
std::string device_id = line.substr(pos1+11, pos2-pos1-11);
wurfl_device_handle hdevice = wurfl_get_device(hwurfl, device_id.c_str());
if(hdevice) {
std::string brand_name = wurfl_device_get_capability(hdevice, "brand_name");
std::string model_name = wurfl_device_get_capability(hdevice, "model_name");
std::string marketing_name = wurfl_device_get_capability(hdevice, "marketing_name");
std::string date = wurfl_device_get_capability(hdevice, "release_date")));
int pos3 = line.find("user_agent=\"");
if(pos3 >= 0) {
int pos4 = line.find("\"", pos3+12);
if(pos4 > pos3+12) {
std::string user_agent = line.substr(pos3+12, pos4-pos3-12);
std::cout << "user_agent : " << user_agent << std::endl;
wurfl_device_handle hvcdevice = wurfl_lookup_useragent(hwurfl, user_agent.c_str());
if(hvcdevice) {
std::string advertised_device_os = wurfl_device_get_virtual_capability(hvcdevice, "controlcap_advertised_device_os");
std::string advertised_device_os_version = wurfl_device_get_virtual_capability(hvcdevice, "controlcap_advertised_device_os_version");
std::string form_factor = wurfl_device_get_virtual_capability(hvcdevice, "controlcap_form_factor");
std::string advertised_browser = wurfl_device_get_virtual_capability(hvcdevice, "controlcap_advertised_browser");
std::string advertised_browser_version = wurfl_device_get_virtual_capability(hvcdevice, "controlcap_advertised_browser_version");
std::string is_smartphone = (strcmp(wurfl_device_get_virtual_capability(hvcdevice, "controlcap_is_smartphone"), "force_false")==0 ? "0" : "1");
std::string is_full_desktop = (strcmp(wurfl_device_get_virtual_capability(hvcdevice, "controlcap_is_full_desktop"), "force_false")==0 ? "0" : "1");
std::string is_robot = (strcmp(wurfl_device_get_virtual_capability(hvcdevice, "controlcap_is_robot"), "force_false")==0 ? "0" : "1");
std::string is_mobile = (strcmp(wurfl_device_get_virtual_capability(hvcdevice, "controlcap_is_mobile"), "force_false")==0 ? "0" : "1");
std::string is_phone = (strcmp(wurfl_device_get_virtual_capability(hvcdevice, "controlcap_is_phone"), "force_false")==0 ? "0" : "1");
std::string is_app = (strcmp(wurfl_device_get_virtual_capability(hvcdevice, "controlcap_is_phone"), "force_false")==0 ? "0" : "1");
std::string is_app_webview = (strcmp(wurfl_device_get_virtual_capability(hvcdevice, "controlcap_is_app_webview"), "force_false")==0 ? "0" : "1");
wurfl_device_destroy(hvcdevice);
ofile << data << std::endl; //Here data string is comma separeted all fields
}
}
}
wurfl_device_destroy(hdevice);
}
}
}
}
infile.close();
ofile.close();
return 0;
}
Thank you, looking forward the support and assistance.