VirtualBox

Ignore:
Timestamp:
Mar 15, 2018 2:11:55 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
121304
Message:

NetworkServices/Dhcpd: stub for reading the config from a file.

Location:
trunk/src/VBox/NetworkServices/Dhcpd
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/NetworkServices/Dhcpd/Config.cpp

    r71306 r71353  
    193193
    194194
     195static const RTGETOPTDEF g_aOptions[] =
     196{
     197    { "--config",       'c',    RTGETOPT_REQ_STRING },
     198};
     199
     200
     201Config *Config::create(int argc, char **argv)
     202{
     203    RTGETOPTSTATE State;
     204    int rc;
     205
     206    rc = RTGetOptInit(&State, argc, argv,
     207                      g_aOptions, RT_ELEMENTS(g_aOptions), 1,
     208                      RTGETOPTINIT_FLAGS_NO_STD_OPTS);
     209    AssertRCReturn(rc, NULL);
     210
     211    std::unique_ptr<Config> config;
     212    for (;;)
     213    {
     214        RTGETOPTUNION Val;
     215
     216        rc = RTGetOpt(&State, &Val);
     217        if (rc == 0)            /* done */
     218            break;
     219
     220        switch (rc)
     221        {
     222            case 'c': /* --config */
     223                if (config.get() != NULL)
     224                {
     225                    printf("Duplicate option: --config '%s'\n", Val.psz);
     226                    return NULL;
     227                }
     228
     229                printf("reading config from %s\n", Val.psz);
     230                config.reset(Config::read(Val.psz));
     231                if (config.get() == NULL)
     232                    return NULL;
     233
     234                break;
     235
     236            case VINF_GETOPT_NOT_OPTION:
     237                RTMsgError("Unexpected command line argument: '%s'", Val.psz);
     238                return NULL;
     239
     240            default:
     241                RTGetOptPrintError(rc, &Val);
     242                return NULL;
     243        }
     244    }
     245
     246    if (config.get() == NULL)
     247        return NULL;
     248
     249    if (!config->isSane())
     250        return NULL;
     251
     252    config->sanitizeBaseName();
     253
     254    return config.release();
     255}
     256
     257
    195258Config *Config::read(const char *pszFileName)
    196259{
     260    std::unique_ptr<Config> config(new Config());
     261
    197262    RT_NOREF(pszFileName);
    198     return NULL;                /* not yet */
     263    return config.release();
    199264}
    200265
  • trunk/src/VBox/NetworkServices/Dhcpd/Config.h

    r70836 r71353  
    5454public: /* factory methods */
    5555    static Config *hardcoded();                   /* for testing */
     56    static Config *create(int argc, char **argv); /* --config */
    5657    static Config *compat(int argc, char **argv); /* old VBoxNetDHCP flags */
    57     static Config *read(const char *pszFileName);
    5858
    5959public: /* accessors */
     
    7979
    8080private:
     81    static Config *read(const char *pszFileName);
     82
    8183    void sanitizeBaseName();
    8284
  • trunk/src/VBox/NetworkServices/Dhcpd/VBoxNetDhcpd.cpp

    r71305 r71353  
    580580    if (argc < 2)
    581581        m_Config = Config::hardcoded();
     582    else if (strcmp(argv[1], "--config") == 0)
     583        m_Config = Config::create(argc, argv);
    582584    else
    583585        m_Config = Config::compat(argc, argv);
Note: See TracChangeset for help on using the changeset viewer.

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