IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 22, 2008, 10:21:52 AM (18 years ago)
Author:
eugene
Message:

using new user/site/system construction for config files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/config/pmConfig.c

    r16415 r16611  
    3434#endif // ifdef HAVE_NEBCLIENT
    3535
    36 #define PS_SITE "PS_SITE"         // Name of the environment variable containing the site config file
    37 #define PS_DEFAULT_SITE ".ipprc"  // Default site config file
     36#define IPPRC_ENV "IPPRC"        // Name of the environment variable containing the top-level config file
     37#define IPPRC_FILE ".ipprc"      // Default top-level config file
    3838
    3939#define DEFAULT_LOG STDERR_FILENO       // Default file descriptor for log messages
     
    5252static void configFree(pmConfig *config)
    5353{
     54    psFree(config->user);
    5455    psFree(config->site);
     56    psFree(config->system);
     57    psFree(config->complete);
    5558    psFree(config->files);
    5659    psFree(config->camera);
     
    8083
    8184    // Initialise
     85    config->user = NULL;
    8286    config->site = NULL;
     87    config->system = NULL;
     88    config->complete = NULL;
    8389    config->camera = NULL;
    8490    config->cameraName = NULL;
     
    145151    PS_ASSERT_STRING_NON_EMPTY(path,);
    146152
    147     pmConfigDone();
     153    assert (configPath == NULL);
     154    // XXX why was this being called?  pmConfigSet should only be called once...
     155    // pmConfigDone();
    148156
    149157    psList *list = psStringSplit(path, ":", false);
     
    159167void pmConfigDone(void)
    160168{
    161     psFree(configPath);
     169    if (configPath) {
     170        psFree(configPath);
     171    }
    162172    configPath = NULL;
    163173
     
    380390    config->defaultRecipe = defaultRecipe;
    381391
    382     //
    383     // The following section of code attempts to determine which file is
    384     // the configuration file.  At the end of this code block, the siteName
     392    // The following section of code attempts to determine which file to use as the
     393    // top-level the configuration file.  At the end of this code block, the configFile
    385394    // variable will contain the name of the configuration file.
    386     //
    387     char *siteName = NULL;
     395
     396    char *configFile = NULL;
    388397    //
    389398    // First, try command line
    390399    //
    391     psS32 argNum = psArgumentGet(*argc, argv, "-site");
     400    psS32 argNum = psArgumentGet(*argc, argv, "-ipprc");
    392401    if (argNum != 0) {
    393         //
    394         // We remove the "-site" argument from argv.  Then
    395         // we look for the next argument, which should be the filename, and
    396         // remove it as well.
    397         //
     402        // remove the "-ipprc" argument from argv, check and remove filename
    398403        psArgumentRemove(argNum, argc, argv);
    399404        if (argNum >= *argc) {
    400             psWarning("-site command-line switch provided without the required filename --- ignored.\n");
     405            psWarning("-ipprc command-line switch provided without the required filename --- ignored.\n");
    401406        } else {
    402             siteName = psStringCopy(argv[argNum]);
     407            configFile = psStringCopy(argv[argNum]);
    403408            psArgumentRemove(argNum, argc, argv);
    404409        }
     
    407412    // Next, try environment variable
    408413    //
    409     if (!siteName) {
    410         siteName = getenv(PS_SITE);
    411         if (siteName) {
    412             siteName = psStringCopy (siteName);
     414    if (!configFile) {
     415        configFile = getenv(IPPRC_ENV);
     416        if (configFile) {
     417            configFile = psStringCopy (configFile);
    413418        }
    414419    }
     
    417422    // Last chance is ~/.ipprc
    418423    //
    419     if (!siteName) {
     424    if (!configFile) {
    420425        char *home = getenv("HOME");
    421         siteName = psStringCopy(home);
    422         psStringAppend(&siteName, "/%s", PS_DEFAULT_SITE);
    423     }
    424 
     426        configFile = psStringCopy(home);
     427        psStringAppend(&configFile, "/%s", IPPRC_FILE);
     428    }
    425429
    426430    // We have the configuration filename; now we read and parse the config
    427     // file and store in psMetadata struct site.
    428     //
    429 
    430     if (!pmConfigFileRead(&config->site, siteName, "site")) {
     431    // file and store in psMetadata struct user.
     432    // XXX move this section to pmConfigReadUser.c ?
     433
     434    if (!pmConfigFileRead(&config->user, configFile, "user")) {
    431435        psFree(config);
    432436        return NULL;
    433437    }
    434438
    435     // Set options based on the site configuration.
     439    // XXX why was this being called here?  Is someone calling pmConfigRead multiple times?
     440    // pmConfigDone();
     441    assert (configPath == NULL); 
     442
     443    // define the config-file search path (configPath). 
     444    psString path = psMetadataLookupStr(NULL, config->user, "PATH");
     445    pmConfigSet (path);
     446
     447    // read the SITE file
     448    psString siteFile = psMetadataLookupStr(NULL, config->user, "SITE");
     449    if (!pmConfigFileRead(&config->site, siteFile, "site")) {
     450        psFree(config);
     451        return NULL;
     452    }
     453
     454    // load the SYSTEM file
     455    psString systemFile = psMetadataLookupStr(NULL, config->user, "SYSTEM");
     456    if (!pmConfigFileRead(&config->system, systemFile, "system")) {
     457        psFree(config);
     458        return NULL;
     459    }
     460
     461    // interpolate USER, SITE and SYSTEM into the config->complete metadata
     462    config->complete = psMetadataCopy (NULL,             config->user);
     463    config->complete = psMetadataCopy (config->complete, config->site);
     464    config->complete = psMetadataCopy (config->complete, config->system);
     465
     466    // Set LOG and TRACE options based on the user configuration.  These must be set AFTER
     467    // the SITE and SYSTEM config files are read so path:// entries here can be resolved.
    436468    {
    437469        bool mdok = true;   // Status of MD lookup result
    438470
    439         // Initialise the psLib time handling
    440         psString timeName = psMetadataLookupStr(&mdok, config->site, "TIME");
    441         if (mdok && timeName)
    442         {
    443             psTrace("psModules.config", 7, "Initialising psTime with file %s\n", timeName);
    444             psTimeInit(timeName);
    445         }
    446 
    447 
    448471        // Set logging level
    449         int logLevel = psMetadataLookupS32(&mdok, config->site, "LOGLEVEL");
     472        int logLevel = psMetadataLookupS32(&mdok, config->user, "LOGLEVEL");
    450473        if (mdok && logLevel >= 0)
    451474        {
     
    456479
    457480        // Set logging format
    458         psString logFormat = psMetadataLookupStr(&mdok, config->site, "LOGFORMAT");
     481        psString logFormat = psMetadataLookupStr(&mdok, config->user, "LOGFORMAT");
    459482        if (mdok && logFormat)
    460483        {
     
    463486        }
    464487
    465         // Set logging destination first from command line, second from site configuration
     488        // Set logging destination first from command line, second from user configuration
    466489        psString logDest = NULL;        // Logging destination
    467490        argNum = psArgumentGet(*argc, argv, "-log");
     
    477500        }
    478501        if (!logDest) {
    479             logDest = psMemIncrRefCounter(psMetadataLookupStr(&mdok, config->site, "LOGDEST"));
     502            logDest = psMemIncrRefCounter(psMetadataLookupStr(&mdok, config->user, "LOGDEST"));
    480503        }
    481504        if (logDest) {
     
    497520
    498521        // Set trace levels
    499         psMetadata *trace = psMetadataLookupMetadata(&mdok, config->site, "TRACE");
     522        psMetadata *trace = psMetadataLookupMetadata(&mdok, config->user, "TRACE");
    500523        if (mdok && trace) {
    501524            psMetadataIterator *traceIter = psMetadataIteratorAlloc(trace, PS_LIST_HEAD, NULL); // Iterator
     
    515538
    516539        // Set trace formats
    517         psString traceFormat = psMetadataLookupStr(&mdok, config->site, "TRACEFORMAT");
     540        psString traceFormat = psMetadataLookupStr(&mdok, config->user, "TRACEFORMAT");
    518541        if (mdok && traceFormat) {
    519542            psTrace("psModules.config", 7, "Setting trace format to %s\n", traceFormat);
     
    535558        }
    536559        if (!traceDest) {
    537             traceDest = psMemIncrRefCounter(psMetadataLookupStr(&mdok, config->site, "TRACEDEST"));
     560            traceDest = psMemIncrRefCounter(psMetadataLookupStr(&mdok, config->user, "TRACEDEST"));
    538561        }
    539562        if (traceDest) {
     
    563586    }
    564587
    565     // define the config-file search path (configPath).  Ensure that
    566     // it contains the directory where we found the config file in
    567     // the first place
    568     if (configPath) {
    569         pmConfigDone();
    570     }
    571 
    572     psString siteNameDir = psStringCopy(dirname(siteName));
    573     psFree(siteName);
    574 
    575     psString path = psMetadataLookupStr(NULL, config->site, "PATH");
    576     psString newPath = NULL;            // New path
    577     // The following gymnastics with 'newPath' are required to avoid changing the pointer out from under the
    578     // psMetadataItem on which 'path' sits (leading to memory corruption because it no longer points to valid
    579     // memory).
    580     if (path) {
    581         psStringAppend(&newPath, "%s:%s", path, siteNameDir);
    582     } else {
    583         newPath = psMemIncrRefCounter(siteNameDir);
    584     }
    585     psFree(siteNameDir);
    586     pmConfigSet(newPath);
    587     psFree(newPath);
     588    // XXX read TIME from SITE (or system?)
     589    {
     590        bool mdok = true;
     591
     592        // Initialise the psLib time handling
     593        // XXX is this still needed / desired?
     594        psString timeName = psMetadataLookupStr(&mdok, config->complete, "TIME");
     595        if (mdok && timeName)
     596        {
     597            psTrace("psModules.config", 7, "Initialising psTime with file %s\n", timeName);
     598            psTimeInit(timeName);
     599        }
     600    }
    588601
    589602    // Next, we do a similar thing for the camera configuration file.  The
    590603    // file is read and parsed into psMetadata struct "camera".
    591     //
    592604    argNum = psArgumentGet(*argc, argv, "-camera");
    593605    if (argNum > 0) {
     
    600612            char *cameraName = argv[argNum]; // symbolic name of the camera
    601613
    602             // look for the CAMERAS list in config->site
    603             psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->site, "CAMERAS");
     614            // look for the CAMERAS list in config->complete
     615            psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->complete, "CAMERAS");
    604616            if (!cameras) {
    605617                psError(PS_ERR_IO, false, "Unable to find CAMERAS in site configuration.\n");
     
    647659                                  "Camera specified on command line", config->camera);
    648660
    649             if (!pmConfigCameraSkycellVersion(config->site, cameraName)) {
     661            if (!pmConfigCameraSkycellVersion(config->complete, cameraName)) {
    650662                psError(PS_ERR_UNKNOWN, false,
    651663                        "Unable to generate skycell versions of specified camera %s.\n",
     
    655667            }
    656668
    657             if (!pmConfigCameraMosaickedVersions(config->site, cameraName)) {
     669            if (!pmConfigCameraMosaickedVersions(config->complete, cameraName)) {
    658670                psError(PS_ERR_UNKNOWN, false,
    659671                        "Unable to generate mosaicked versions of specified camera %s.\n",
     
    668680    if (!config->camera && readCameraConfig) {
    669681        bool mdok;                      // Status of MD lookup
    670         psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->site, "CAMERAS"); // List of cameras
     682        psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->complete, "CAMERAS"); // List of cameras
    671683        if (!mdok || !cameras) {
    672             psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find CAMERAS in the site configuration.\n");
     684            psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find CAMERAS in the system configuration.\n");
    673685            return false;
    674686        }
    675687
    676688        if (!metadataReadFiles(cameras, "camera configuration")) {
    677             psError(PS_ERR_UNKNOWN, false, "Unable to read cameras within site configuration.\n");
     689            psError(PS_ERR_UNKNOWN, false, "Unable to read cameras within system configuration.\n");
    678690            psFree(config);
    679691            return NULL;
     
    702714        psFree(iter);
    703715
    704         if (!pmConfigCameraSkycellVersionsAll(config->site)) {
     716        if (!pmConfigCameraSkycellVersionsAll(config->complete)) {
    705717            psError(PS_ERR_UNKNOWN, false, "Unable to generate skycell versions of cameras.\n");
    706718            psFree(config);
    707719            return NULL;
    708720        }
    709         if (!pmConfigCameraMosaickedVersionsAll(config->site)) {
     721        if (!pmConfigCameraMosaickedVersionsAll(config->complete)) {
    710722            psError(PS_ERR_UNKNOWN, false, "Unable to generate mosaicked versions of cameras.\n");
    711723            psFree(config);
     
    715727
    716728    // Load the recipes from the camera file, if appropriate
    717     if(!pmConfigReadRecipes(config, PM_RECIPE_SOURCE_SITE | PM_RECIPE_SOURCE_CAMERA)) {
     729    if(!pmConfigReadRecipes(config, PM_RECIPE_SOURCE_SYSTEM | PM_RECIPE_SOURCE_CAMERA)) {
    718730        psError(PS_ERR_IO, false, "Failed to read recipes from camera file");
    719731        psFree(config);
     
    746758        psArgumentRemove(argNum, argc, argv);
    747759
    748         psMetadata *cameras = psMetadataLookupMetadata(NULL, config->site, "CAMERAS"); // List of cameras
     760        psMetadata *cameras = psMetadataLookupMetadata(NULL, config->complete, "CAMERAS"); // List of cameras
    749761        if (!cameras) {
    750762            psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find CAMERAS in the site configuration.\n");
     
    794806        } else {
    795807            char *dbserver = argv[argNum]; // The camera configuration file to read
    796             if (!psMetadataAddStr(config->site, PS_LIST_TAIL, "DBSERVER", PS_META_REPLACE, NULL, dbserver)) {
     808            if (!psMetadataAddStr(config->complete, PS_LIST_TAIL, "DBSERVER", PS_META_REPLACE, NULL, dbserver)) {
    797809                psWarning("Failed to overwrite .ipprc DBSERVER value");
    798810            }
     
    809821        } else {
    810822            char *dbname = argv[argNum]; // The camera configuration file to read
    811             if (!psMetadataAddStr(config->site, PS_LIST_TAIL, "DBNAME", PS_META_REPLACE, NULL, dbname)) {
     823            if (!psMetadataAddStr(config->complete, PS_LIST_TAIL, "DBNAME", PS_META_REPLACE, NULL, dbname)) {
    812824                psWarning("Failed to overwrite .ipprc DBNAME value");
    813825            }
     
    824836        } else {
    825837            char *dbuser = argv[argNum]; // The camera configuration file to read
    826             if (!psMetadataAddStr(config->site, PS_LIST_TAIL, "DBUSER", PS_META_REPLACE, NULL, dbuser)) {
     838            if (!psMetadataAddStr(config->complete, PS_LIST_TAIL, "DBUSER", PS_META_REPLACE, NULL, dbuser)) {
    827839                psWarning("Failed to overwrite .ipprc DBUSER value");
    828840            }
     
    839851        } else {
    840852            char *dbpassword = argv[argNum]; // The camera configuration file to read
    841             if (!psMetadataAddStr(config->site, PS_LIST_TAIL, "DBPASSWORD", PS_META_REPLACE,
     853            if (!psMetadataAddStr(config->complete, PS_LIST_TAIL, "DBPASSWORD", PS_META_REPLACE,
    842854                                  NULL, dbpassword)) {
    843855                psWarning("Failed to overwrite .ipprc DBPASSWORD value");
     
    855867        } else {
    856868            char *dbport = argv[argNum]; // The camera configuration file to read
    857             if (!psMetadataAddS32(config->site, PS_LIST_TAIL, "DBPORT", PS_META_REPLACE, NULL,
     869            if (!psMetadataAddS32(config->complete, PS_LIST_TAIL, "DBPORT", PS_META_REPLACE, NULL,
    858870                                  (psS32)atoi(dbport))) {
    859871                psWarning("Failed to overwrite .ipprc DBPORT value");
     
    10271039    if (! config->camera) {
    10281040        bool mdok;                      // Metadata lookup status
    1029         psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->site, "CAMERAS");
     1041        psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->complete, "CAMERAS");
    10301042        if (! mdok || !cameras) {
    10311043            psError(PS_ERR_IO, true, "Unable to find CAMERAS in the configuration.");
     
    11141126    PS_ASSERT_STRING_NON_EMPTY(cameraName, NULL);
    11151127
    1116     psMetadata *cameras = psMetadataLookupMetadata(NULL, config->site, "CAMERAS");
     1128    psMetadata *cameras = psMetadataLookupMetadata(NULL, config->complete, "CAMERAS");
    11171129    if (!cameras) {
    11181130        psError(PS_ERR_IO, true, "Unable to find CAMERAS in the configuration.");
     
    11401152{
    11411153    PS_ASSERT_PTR_NON_NULL(config, NULL);
    1142     PS_ASSERT_PTR_NON_NULL(config->site, NULL);
     1154    PS_ASSERT_PTR_NON_NULL(config->complete, NULL);
    11431155
    11441156    #ifndef HAVE_PSDB
     
    11571169
    11581170    // XXX leaky strings
    1159     psString dbServer = psMetadataLookupStr(&mdStatus01, config->site, "DBSERVER");
    1160     psString dbUsername = psMetadataLookupStr(&mdStatus02, config->site, "DBUSER");
    1161     psString dbPassword = psMetadataLookupStr(&mdStatus03, config->site, "DBPASSWORD");
    1162     psString dbName = psMetadataLookupStr(&mdStatus04, config->site, "DBNAME");
    1163     psS32 dbPort = psMetadataLookupS32(&mdStatus05, config->site, "DBPORT");
     1171    psString dbServer = psMetadataLookupStr(&mdStatus01, config->complete, "DBSERVER");
     1172    psString dbUsername = psMetadataLookupStr(&mdStatus02, config->complete, "DBUSER");
     1173    psString dbPassword = psMetadataLookupStr(&mdStatus03, config->complete, "DBPASSWORD");
     1174    psString dbName = psMetadataLookupStr(&mdStatus04, config->complete, "DBNAME");
     1175    psS32 dbPort = psMetadataLookupS32(&mdStatus05, config->complete, "DBPORT");
    11641176    if (!mdStatus05) {
    11651177        dbPort = 0;
     
    13521364    // replace path://PATH with matched datapath
    13531365    if (!strncasecmp(filename, "path://", strlen("path://"))) {
    1354         PS_ASSERT_METADATA_NON_NULL(config->site, NULL);
     1366        PS_ASSERT_METADATA_NON_NULL(config->complete, NULL);
    13551367
    13561368        psString newName = psStringCopy(filename);
    13571369
    13581370        // filename should be of the form: path://PATH/rest/of/file
    1359         // replace PATH with matching name from config->site:DATAPATH
    1360         psMetadata *datapath = psMetadataLookupPtr (NULL, config->site, "DATAPATH");
     1371        // replace PATH with matching name from config->complete:DATAPATH
     1372        psMetadata *datapath = psMetadataLookupPtr (NULL, config->complete, "DATAPATH");
    13611373        if (datapath == NULL) {
    13621374            psError(PS_ERR_UNKNOWN, true, "DATAPATH is not defined in config.site");
     
    14101422        // if env isn't set, check the config system
    14111423        if (!neb_server) {
    1412             neb_server = psMetadataLookupStr(&status, config->site, "NEB_SERVER");
     1424            neb_server = psMetadataLookupStr(&status, config->complete, "NEB_SERVER");
    14131425            if (!status) {
    14141426                psError(PM_ERR_CONFIG, true, "failed to lookup config value for NEB_SERVER.");
Note: See TracChangeset for help on using the changeset viewer.