VirtualBox

Changeset 58000 in vbox for trunk/src/VBox/Main/src-server


Ignore:
Timestamp:
Oct 2, 2015 10:05:38 AM (9 years ago)
Author:
vboxsync
Message:

USBIdDatabase*: Corrected file header, fixed LogRel statement (was given NULL string pointers instead of vendor + device IDs), some style fixes.

Location:
trunk/src/VBox/Main/src-server
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/HostUSBDeviceImpl.cpp

    r57994 r58000  
    170170    if (mUsb->pszManufacturer == NULL || mUsb->pszManufacturer[0] == 0)
    171171    {
    172         const char* vendorName = AliasDictionary::findVendor(mUsb->idVendor);
     172        const char *vendorName = AliasDictionary::findVendor(mUsb->idVendor);
    173173        if (vendorName)
    174174            aManufacturer = vendorName;
     
    185185    if (mUsb->pszProduct == NULL || mUsb->pszProduct[0] == 0)
    186186    {
    187         const char* productName = AliasDictionary::findProduct(mUsb->idVendor, mUsb->idProduct);
     187        const char *productName = AliasDictionary::findProduct(mUsb->idVendor, mUsb->idProduct);
    188188        if (productName)
    189189            aProduct = productName;
     
    335335        name = Utf8StrFmt("%s %s", mUsb->pszManufacturer, mUsb->pszProduct);
    336336    else if (haveManufacturer)
    337         name = Utf8StrFmt("%s", mUsb->pszManufacturer);
     337        name = mUsb->pszManufacturer;
    338338    else if (haveProduct)
    339         name = Utf8StrFmt("%s", mUsb->pszProduct);
     339        name = mUsb->pszProduct;
    340340    else
    341341    {
    342         const char* vendorName = AliasDictionary::findVendor(mUsb->idVendor);
    343         const char* productName = AliasDictionary::findProduct(mUsb->idVendor, mUsb->idProduct);
    344         if (vendorName && productName)
    345         {
    346             name = Utf8StrFmt("%s %s", vendorName, productName);
    347         }
     342        const char *pszVendorName  = AliasDictionary::findVendor(mUsb->idVendor);
     343        const char *pszProductName = AliasDictionary::findProduct(mUsb->idVendor, mUsb->idProduct);
     344        if (pszVendorName && pszProductName)
     345            name = Utf8StrFmt("%s %s", pszVendorName, pszProductName);
    348346        else
    349347        {
    350             name = "<unknown>";
    351             LogRel(("USB: Unknown USB device detected (idVendor: 0x%04x, idProduct: 0x%04x). Please, report the idVendor and idProduct to virtualbox.org.\n", vendorName, productName));
     348            LogRel(("USB: Unknown USB device detected (idVendor: 0x%04x, idProduct: 0x%04x). Please, report the idVendor and idProduct to virtualbox.org.\n",
     349                    mUsb->idVendor, mUsb->idProduct));
     350            if (pszVendorName)
     351                name = pszVendorName;
     352            else if (pszProductName)
     353                name = pszProductName;
     354            else
     355                name = "<unknown>";
    352356        }
    353357    }
  • trunk/src/VBox/Main/src-server/USBIdDatabaseGenerator.cpp

    r57662 r58000  
     1/* $Id$ */
     2/** @file
     3 * USB device vendor and product ID database - generator.
     4 */
     5
    16/*
    2 * Copyright (C) 2006-2015 Oracle Corporation
    3 *
    4 * This file is part of VirtualBox Open Source Edition (OSE), as
    5 * available from http://www.virtualbox.org. This file is free software;
    6 * you can redistribute it and/or modify it under the terms of the GNU
    7 * General Public License (GPL) as published by the Free Software
    8 * Foundation, in version 2 as it comes in the "COPYING" file of the
    9 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
    10 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
    11 */
     7 * Copyright (C) 2015 Oracle Corporation
     8 *
     9 * This file is part of VirtualBox Open Source Edition (OSE), as
     10 * available from http://www.virtualbox.org. This file is free software;
     11 * you can redistribute it and/or modify it under the terms of the GNU
     12 * General Public License (GPL) as published by the Free Software
     13 * Foundation, in version 2 as it comes in the "COPYING" file of the
     14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
     15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
     16 */
    1217
    1318#include <stdio.h>
     
    2631using namespace std;
    2732
    28 const char *header =
     33static const char * const header =
     34    "/** @file\n"
     35    " * USB device vendor and product ID database - Autogenerated from <stupid C++ cannot do %s>\n"
     36    " */\n"
     37    "\n"
    2938    "/*\n"
    30     " * Copyright(C) 2015 Oracle Corporation\n"
     39    " * Copyright (C) 2015 Oracle Corporation\n"
    3140    " *\n"
    3241    " * This file is part of VirtualBox Open Source Edition(OSE), as\n"
     
    116125        switch (res[i])
    117126        {
    118         case '"':
    119         case '\\': res.insert(i++, "\\"); break;
    120         default:
    121         {
    122             // encode multibyte UTF-8 symbols to be sure that they
    123             // will be safely read by compiler
    124             if ((unsigned char)res[i] >= 127)
     127            case '"':
     128            case '\\': res.insert(i++, "\\"); break;
     129            default:
    125130            {
    126                 size_t start = i;
    127                 string temp = "\" \"";
    128                 char buffer[8] = { 0 };
    129                 do
     131                // encode multibyte UTF-8 symbols to be sure that they
     132                // will be safely read by compiler
     133                if ((unsigned char)res[i] >= 127)
    130134                {
    131                     RTStrPrintf(buffer, sizeof(buffer), "\\x%x", (unsigned char)res[i]);
    132                     temp.append(buffer);
    133                 } while ((unsigned char)res[++i] & 0x80);
    134                 // splitting string after escape sequence to finish number sequence
    135                 // otherwise it could lead to situation when "\x88a" will threathened as
    136                 // multibyte symbol '\x88a' instead of two symbols '\x88' and 'a'
    137                 temp.append("\" \"");
    138                 res.replace(start, i - start, temp);
    139                 i += temp.length();
     135                    size_t start = i;
     136                    string temp = "\" \"";
     137                    char buffer[8] = { 0 };
     138                    do
     139                    {
     140                        RTStrPrintf(buffer, sizeof(buffer), "\\x%x", (unsigned char)res[i]);
     141                        temp.append(buffer);
     142                    } while ((unsigned char)res[++i] & 0x80);
     143                    // splitting string after escape sequence to finish number sequence
     144                    // otherwise it could lead to situation when "\x88a" will threathened as
     145                    // multibyte symbol '\x88a' instead of two symbols '\x88' and 'a'
     146                    temp.append("\" \"");
     147                    res.replace(start, i - start, temp);
     148                    i += temp.length();
     149                }
    140150            }
    141         }
    142151        }
    143152    }
     
    234243        switch (state)
    235244        {
    236         case State::lookForStartBlock:
    237         {
    238             if (line.find(start_block) != string::npos)
    239                 state = State::lookForEndBlock;
    240             break;
    241         }
    242         case State::lookForEndBlock:
    243         {
    244             if (line.find(end_block) != string::npos)
    245                 state = State::finished;
    246             else
     245            case State::lookForStartBlock:
    247246            {
    248                 if (!IsCommentOrEmptyLine(line))
     247                if (line.find(start_block) != string::npos)
     248                    state = State::lookForEndBlock;
     249                break;
     250            }
     251            case State::lookForEndBlock:
     252            {
     253                if (line.find(end_block) != string::npos)
     254                    state = State::finished;
     255                else
    249256                {
    250                     if (line[0] == '\t')
     257                    if (!IsCommentOrEmptyLine(line))
    251258                    {
    252                         // Parse Product line
    253                         // first line should be vendor
    254                         if (vendor.vendorID == 0)
     259                        if (line[0] == '\t')
    255260                        {
    256                             cerr << "Wrong file format. Product before vendor: "
    257                                 << line.c_str() << "'" << endl;
    258                             return ERROR_WRONG_FILE_FORMAT;
     261                            // Parse Product line
     262                            // first line should be vendor
     263                            if (vendor.vendorID == 0)
     264                            {
     265                                cerr << "Wrong file format. Product before vendor: "
     266                                    << line.c_str() << "'" << endl;
     267                                return ERROR_WRONG_FILE_FORMAT;
     268                            }
     269                            ProductRecord product = { 0, vendor.vendorID, 0, "" };
     270                            if (ParseAlias(line.substr(1), product.productID, product.product) != 0)
     271                            {
     272                                cerr << "Error in parsing product line: '"
     273                                    << line.c_str() << "'" << endl;
     274                                return ERROR_IN_PARSE_LINE;
     275                            }
     276                            product.key = USBKEY(product.vendorID, product.productID);
     277                            Assert(product.vendorID != 0);
     278                            g_products.push_back(product);
    259279                        }
    260                         ProductRecord product = { 0, vendor.vendorID, 0, "" };
    261                         if (ParseAlias(line.substr(1), product.productID, product.product) != 0)
     280                        else
    262281                        {
    263                             cerr << "Error in parsing product line: '"
    264                                 << line.c_str() << "'" << endl;
    265                             return ERROR_IN_PARSE_LINE;
     282                            // Parse vendor line
     283                            if (ParseAlias(line, vendor.vendorID, vendor.vendor) != 0)
     284                            {
     285                                cerr << "Error in parsing vendor line: '"
     286                                    << line.c_str() << "'" << endl;
     287                                return ERROR_IN_PARSE_LINE;
     288                            }
     289                            g_vendors.push_back(vendor);
    266290                        }
    267                         product.key = USBKEY(product.vendorID, product.productID);
    268                         Assert(product.vendorID != 0);
    269                         g_products.push_back(product);
    270                     }
    271                     else
    272                     {
    273                         // Parse vendor line
    274                         if (ParseAlias(line, vendor.vendorID, vendor.vendor) != 0)
    275                         {
    276                             cerr << "Error in parsing vendor line: '"
    277                                 << line.c_str() << "'" << endl;
    278                             return ERROR_IN_PARSE_LINE;
    279                         }
    280                         g_vendors.push_back(vendor);
    281291                    }
    282292                }
     293                break;
    283294            }
    284             break;
    285         }
    286295        }
    287296    }
     
    294303}
    295304
    296 int main(int argc, char* argv[])
     305int main(int argc, char *argv[])
    297306{
    298307    int rc = RTR3InitExe(argc, &argv, 0);
     
    312321    g_vendors.reserve(3500);
    313322
    314     char* outName = NULL;
    315     rc = 0;
     323    const char *outName = NULL;
    316324    for (int i = 1; i < argc; i++)
    317325    {
     
    322330        }
    323331
    324         if (RT_FAILURE(rc = RTStrmOpen(argv[i], "r", &fin)))
     332        rc = RTStrmOpen(argv[i], "r", &fin);
     333        if (RT_FAILURE(rc))
    325334        {
    326335            cerr << "Format: " << argv[0] <<
     
    349358    {
    350359        cerr << "Warning: Duplicate alias detected. " << *ita << endl;
     360        /** @todo r=bird: Why return success (0) when we didn't generate the
     361         *        file?!?!? */
    351362        return 0;
    352363    }
     
    360371    }
    361372
     373/** @todo String compression. */
     374
    362375    fout.open(outName);
    363376    if (!fout.is_open())
  • trunk/src/VBox/Main/src-server/USBIdDatabaseStub.cpp

    r57358 r58000  
     1/* $Id$ */
     2/** @file
     3 * USB device vendor and product ID database - stub.
     4 */
     5
    16/*
    2 * Copyright(C) 2005 - 2015 Oracle Corporation
    3 *
    4 * This file is part of VirtualBox Open Source Edition(OSE), as
    5 * available from http ://www.virtualbox.org. This file is free software;
    6 * you can redistribute it and / or modify it under the terms of the GNU
    7 * General Public License(GPL) as published by the Free Software
    8 * Foundation, in version 2 as it comes in the "COPYING" file of the
    9 * VirtualBox OSE distribution.VirtualBox OSE is distributed in the
    10 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
    11 *
    12 */
     7 * Copyright (C) 2015 Oracle Corporation
     8 *
     9 * This file is part of VirtualBox Open Source Edition (OSE), as
     10 * available from http://www.virtualbox.org. This file is free software;
     11 * you can redistribute it and/or modify it under the terms of the GNU
     12 * General Public License (GPL) as published by the Free Software
     13 * Foundation, in version 2 as it comes in the "COPYING" file of the
     14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
     15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
     16 */
    1317
    1418#include "USBIdDatabase.h"
    1519
    16 /** USB devices aliases array.
    17 *   Format: VendorId, ProductId, Vendor Name, Product Name
    18 *   The source of the list is http://www.linux-usb.org/usb.ids
    19 */
    20 Product AliasDictionary::productArray[] = {0};
     20Product         AliasDictionary::productArray[] = {0};
     21const size_t    AliasDictionary::products_size  = 0;
     22Vendor          AliasDictionary::vendorArray[]  = {0};
     23const size_t    AliasDictionary::vendors_size   = 0;
    2124
    22 const size_t AliasDictionary::products_size = sizeof(AliasDictionary::productArray) / sizeof(Product);
    23 
    24 Vendor AliasDictionary::vendorArray[] = {0};
    25 
    26 const size_t AliasDictionary::vendors_size = sizeof(AliasDictionary::vendorArray) / sizeof(Vendor);
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