VirtualBox

Changeset 57338 in vbox


Ignore:
Timestamp:
Aug 14, 2015 5:51:13 AM (9 years ago)
Author:
vboxsync
Message:

Main/HostUSBdevice: Fixed issue on Linux

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Config.kmk

    r57335 r57338  
    552552endif
    553553# Whether to generate a database of USB vendor IDs and device IDs into VBoxSVC.
    554 #VBOX_WITH_MAIN_USB_ID_DATABASE = 1
     554VBOX_WITH_MAIN_USB_ID_DATABASE = 1
    555555# The recompiler.
    556556VBOX_WITH_REM = 1
  • trunk/src/VBox/Main/include/USBIdDatabase.h

    r57185 r57338  
    7979    {
    8080        Product lookFor = { USBKEY(vendorId, productId) };
    81         Product* it = std::lower_bound(productArray, productArray + products_size + 1, lookFor, ProductLess());
     81        Product* it = std::lower_bound(productArray, productArray + products_size, lookFor, ProductLess());
    8282        return lookFor.key == it->key ? it->product : NULL;
    8383    }
     
    8686    {
    8787        Vendor lookFor = { vendorID };
    88         Vendor* it = std::lower_bound(vendorArray, vendorArray + vendors_size + 1, lookFor, VendorLess());
     88        Vendor* it = std::lower_bound(vendorArray, vendorArray + vendors_size, lookFor, VendorLess());
    8989        return lookFor.vendorID == it->vendorID ? it->vendor : NULL;
    9090    }
  • trunk/src/VBox/Main/src-server/USBIdDatabaseGenerator.cpp

    r57034 r57338  
    1919
    2020#include <iprt/string.h>
     21#include <iprt/stream.h>
    2122
    2223using namespace std;
    2324
    2425const char* header = "/*\n\
    25 * Copyright(C) 2005 - 2015 Oracle Corporation\n\
    26 *\n\
    27 * This file is part of VirtualBox Open Source Edition(OSE), as\n\
    28 * available from http ://www.virtualbox.org. This file is free software;\n\
    29 * you can redistribute it and / or modify it under the terms of the GNU\n\
    30 * General Public License(GPL) as published by the Free Software\n\
    31 * Foundation, in version 2 as it comes in the \"COPYING\" file of the\n\
    32 * VirtualBox OSE distribution.VirtualBox OSE is distributed in the\n\
    33 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.\n\
    34 *\n\
    35 */\
    36 \n\
    37 \n\
    38 #include \"USBIdDatabase.h\"\n\
    39 \n\
    40 /** USB devices aliases array.\n\
    41 *   Format: VendorId, ProductId, Vendor Name, Product Name\n\
    42 *   The source of the list is http://www.linux-usb.org/usb.ids\n\
    43 */\n\
    44 Product AliasDictionary::productArray[] = { \n";
     26 * Copyright(C) 2005 - 2015 Oracle Corporation\n\
     27 *\n\
     28 * This file is part of VirtualBox Open Source Edition(OSE), as\n\
     29 * available from http ://www.virtualbox.org. This file is free software;\n\
     30 * you can redistribute it and / or modify it under the terms of the GNU\n\
     31 * General Public License(GPL) as published by the Free Software\n\
     32 * Foundation, in version 2 as it comes in the \"COPYING\" file of the\n\
     33 * VirtualBox OSE distribution.VirtualBox OSE is distributed in the\n\
     34 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.\n\
     35 *\n\
     36 */\
     37 \n\
     38 \n\
     39 #include \"USBIdDatabase.h\"\n\
     40 \n\
     41 /** USB devices aliases array.\n\
     42 *   Format: VendorId, ProductId, Vendor Name, Product Name\n\
     43 *   The source of the list is http://www.linux-usb.org/usb.ids\n\
     44 */\n\
     45 Product AliasDictionary::productArray[] = { \n";
    4546
    4647const char* footer = "};\n\
    47 \n\
    48 const size_t AliasDictionary::products_size = sizeof(AliasDictionary::productArray) / sizeof(Product); \n";
     48 \n\
     49 const size_t AliasDictionary::products_size = sizeof(AliasDictionary::productArray) / sizeof(Product); \n";
    4950
    5051const char* vendor_header = "\nVendor AliasDictionary::vendorArray[] = { \n";
     
    5354const size_t AliasDictionary::vendors_size = sizeof(AliasDictionary::vendorArray) / sizeof(Vendor);";
    5455
    55 const wchar_t* start_block = L"#                interface  interface_name               <-- two tabs";
    56 const wchar_t* end_block = L"# List of known device classes, subclasses and protocols";
     56const char* start_block = "#            interface  interface_name               <-- two tabs";
     57const char* end_block = "# List of known device classes, subclasses and protocols";
    5758
    5859#define USBKEY(vendorId, productId) (((vendorId) << 16) | (productId))
     
    6869{
    6970    size_t vendorID;
    70     wstring vendor;
     71    string vendor;
    7172};
    7273
     
    7677    size_t vendorID;
    7778    size_t productID;
    78     wstring product;
     79    string product;
    7980};
    8081
     
    99100}
    100101
    101 string conv(const wstring& src)
    102 {
    103     string res;
    104     char* buf = NULL;
    105    
    106     if (RTUtf16ToLatin1((PRTUTF16)src.c_str(), &buf) == VINF_SUCCESS)
    107     {
    108         size_t len = strlen(buf);
    109         for (size_t i = 0; i < len; i++)
    110         {
    111             if (buf[i] == '"')
    112                 buf[i] = '\'';
    113         }
    114         res = buf;
    115         RTStrFree(buf);
     102string conv(const string& src)
     103{
     104    string res = src;
     105    for (size_t i = 0; i < res.length(); i++)
     106    {
     107        switch (res[i])
     108        {
     109        case '"':
     110        case '\\': res.insert(i++, "\\");
     111        }
    116112    }
    117113    return res;
     
    126122}
    127123
    128 wostream& operator <<(wostream& stream, const ProductRecord product)
    129 {
    130     stream << L"{USBKEY(0x" << hex << product.vendorID
    131         << L", 0x" << product.productID << L"), "
    132         << L"\"" << product.product.c_str() << L"\" }," << endl;
    133     return stream;
    134 }
    135 
    136124ostream& operator <<(ostream& stream, const VendorRecord vendor)
    137125{
    138126    stream << "{0x" << hex << vendor.vendorID
    139127        << ", \"" << conv(vendor.vendor).c_str() << "\" }," << endl;
    140     return stream;
    141 }
    142 
    143 wostream& operator <<(wostream& stream, const VendorRecord vendor)
    144 {
    145     stream << L"{0x" << hex << vendor.vendorID
    146         << L", \"" << vendor.vendor.c_str() << L"\" }," << endl;
    147128    return stream;
    148129}
     
    165146
    166147
    167 int ParseAlias(const wstring& src, size_t& id, wstring& desc)
    168 {
    169     int i = 0;
     148int ParseAlias(const string& src, size_t& id, string& desc)
     149{
     150    unsigned int i = 0;
    170151    int idx = 0;
    171     wstring sin;
    172 
    173     if (swscanf(src.c_str(), L"%x", &i) != 1)
     152    string sin;
     153
     154    if (sscanf(src.c_str(), "%x", &i) != 1)
    174155        return ERROR_IN_PARSE_LINE;
    175156
    176     size_t index = src.find_first_of(L" \t", 1);
    177     index = src.find_first_not_of(L" \t", index);
     157    size_t index = src.find_first_of(" \t", 1);
     158    index = src.find_first_not_of(" \t", index);
    178159
    179160    if (index == string::npos)
     
    187168}
    188169
    189 bool IsCommentOrEmptyLine(const wstring& str)
    190 {
    191     size_t index = str.find_first_not_of(L" \t");// skip left spaces
    192     return index == string::npos || str[index] == L'#';
    193 }
    194 
    195 int ParseUsbIds(wifstream& instream)
     170bool IsCommentOrEmptyLine(const string& str)
     171{
     172    size_t index = str.find_first_not_of(" \t");// skip left spaces
     173    return index == string::npos || str[index] == '#';
     174}
     175
     176bool getline(PRTSTREAM instream, string& resString)
     177{
     178    const size_t szBuf = 4096;
     179    char buf[szBuf] = { 0 };
     180
     181    int rc = RTStrmGetLine(instream, buf, szBuf);
     182    if (RT_SUCCESS(rc))
     183    {
     184        resString = buf;
     185        return true;
     186    }
     187    else if (rc != VERR_EOF)
     188    {
     189        cerr << "Warning: Invalid line in file. Error: " << hex << rc << endl;
     190    }
     191    return false;
     192}
     193
     194int ParseUsbIds(PRTSTREAM instream)
    196195{
    197196    State::Value state = State::lookForStartBlock;
    198     wstring line;
     197    string line;
    199198    int res = 0;
    200     VendorRecord vendor = { 0, L"" };
     199    VendorRecord vendor = { 0, "" };
    201200
    202201    while (state != State::finished && getline(instream, line))
     
    228227                            return ERROR_WRONG_FILE_FORMAT;
    229228                        }
    230                         ProductRecord product = { 0, vendor.vendorID, 0, L"" };
     229                        ProductRecord product = { 0, vendor.vendorID, 0, "" };
    231230                        if (ParseAlias(line.substr(1), product.productID, product.product) != 0)
    232231                        {
     
    274273    }
    275274    ofstream fout;
    276     wifstream fin;
     275    PRTSTREAM fin;
    277276    g_products.reserve(20000);
    278277    g_vendors.reserve(3500);
    279278
    280279    char* outName = NULL;
     280    int rc = 0;
    281281    for (int i = 1; i < argc; i++)
    282282    {
     
    287287        }
    288288
    289         fin.open(argv[i]);
    290         if (!fin.is_open())
     289        if (RT_FAILURE(rc = RTStrmOpen(argv[i], "r", &fin)))
    291290        {
    292291            cerr << "Format: " << argv[0] <<
    293292                " [linux.org usb list file] [custom usb list file] [-o output file]" << endl;
    294             cerr << "Error: Can not open file '" << argv[i] << "'." << endl;
     293            cerr << "Error: Can not open file '" << argv[i] << "'. Error: " << hex << rc << endl;
    295294            return ERROR_OPEN_FILE;
    296295        }
     
    301300            cerr << "Error in parsing USB devices file '" <<
    302301                argv[i] << "'" << endl;
    303             fin.close();
     302            RTStrmClose(fin);
    304303            return res;
    305304        }
    306         fin.close();
     305        RTStrmClose(fin);
    307306    }
    308307
     
    311310
    312311    // validate that all records are unique
    313     ProductsSet::iterator it = adjacent_find(g_products.begin(), g_products.end());
    314     if (it != g_products.end())
    315     {
    316         cerr << "Error: Duplicate alias detected. " << *it << endl;
    317         return ERROR_DUPLICATE_ENTRY;
     312    ProductsSet::iterator ita = adjacent_find(g_products.begin(), g_products.end());
     313    if (ita != g_products.end())
     314    {
     315        cerr << "Warning: Duplicate alias detected. " << *ita << endl;
     316        return 0;
    318317    }
    319318
     
    336335
    337336    fout << header;
    338     for (ProductsSet::iterator it = g_products.begin(); it != g_products.end(); ++it)
    339     {
    340         fout << *it;
     337    for (ProductsSet::iterator itp = g_products.begin(); itp != g_products.end(); ++itp)
     338    {
     339        fout << *itp;
    341340    }
    342341    fout << footer;
    343342
    344343    fout << vendor_header;
    345     for (VendorsSet::iterator it = g_vendors.begin(); it != g_vendors.end(); ++it)
    346     {
    347         fout << *it;
     344    for (VendorsSet::iterator itv = g_vendors.begin(); itv != g_vendors.end(); ++itv)
     345    {
     346        fout << *itv;
    348347    }
    349348    fout << vendor_footer;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette