IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 19, 2008, 10:09:10 AM (18 years ago)
Author:
eugene
Message:

re-vamping config to define user/site/system

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20080219/psModules/src/config/pmConfig.c

    r16415 r16542  
    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->site);
     54    psFree(config->xxUser);
     55    psFree(config->xxSite);
     56    psFree(config->xxSystem);
    5557    psFree(config->files);
    5658    psFree(config->camera);
     
    8082
    8183    // Initialise
    82     config->site = NULL;
     84    config->xxUser = NULL;
     85    config->xxSite = NULL;
     86    config->xxSystem = NULL;
    8387    config->camera = NULL;
    8488    config->cameraName = NULL;
     
    145149    PS_ASSERT_STRING_NON_EMPTY(path,);
    146150
    147     pmConfigDone();
     151    assert (configPath == NULL);
     152    // XXX why was this being called?  pmConfigSet should only be called once...
     153    // pmConfigDone();
    148154
    149155    psList *list = psStringSplit(path, ":", false);
     
    159165void pmConfigDone(void)
    160166{
    161     psFree(configPath);
     167    if (configPath) {
     168        psFree(configPath);
     169    }
    162170    configPath = NULL;
    163171
     
    380388    config->defaultRecipe = defaultRecipe;
    381389
    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
     390    // The following section of code attempts to determine which file to use as the
     391    // top-level the configuration file.  At the end of this code block, the configFile
    385392    // variable will contain the name of the configuration file.
    386     //
    387     char *siteName = NULL;
     393
     394    char *configFile = NULL;
    388395    //
    389396    // First, try command line
    390397    //
    391     psS32 argNum = psArgumentGet(*argc, argv, "-site");
     398    psS32 argNum = psArgumentGet(*argc, argv, "-ipprc");
    392399    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         //
     400        // remove the "-ipprc" argument from argv, check and remove filename
    398401        psArgumentRemove(argNum, argc, argv);
    399402        if (argNum >= *argc) {
    400             psWarning("-site command-line switch provided without the required filename --- ignored.\n");
     403            psWarning("-ipprc command-line switch provided without the required filename --- ignored.\n");
    401404        } else {
    402             siteName = psStringCopy(argv[argNum]);
     405            configFile = psStringCopy(argv[argNum]);
    403406            psArgumentRemove(argNum, argc, argv);
    404407        }
     
    407410    // Next, try environment variable
    408411    //
    409     if (!siteName) {
    410         siteName = getenv(PS_SITE);
    411         if (siteName) {
    412             siteName = psStringCopy (siteName);
     412    if (!configFile) {
     413        configFile = getenv(IPPRC_ENV);
     414        if (configFile) {
     415            configFile = psStringCopy (configFile);
    413416        }
    414417    }
     
    417420    // Last chance is ~/.ipprc
    418421    //
    419     if (!siteName) {
     422    if (!configFile) {
    420423        char *home = getenv("HOME");
    421         siteName = psStringCopy(home);
    422         psStringAppend(&siteName, "/%s", PS_DEFAULT_SITE);
     424        configFile = psStringCopy(home);
     425        psStringAppend(&configFile, "/%s", IPPRC_FILE);
    423426    }
    424427
    425428
    426429    // 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")) {
     430    // file and store in psMetadata struct xxUser.
     431    // XXX move this section to pmConfigReadUser.c ?
     432
     433    if (!pmConfigFileRead(&config->xxUser, configFile, "user")) {
    431434        psFree(config);
    432435        return NULL;
    433436    }
    434437
    435     // Set options based on the site configuration.
     438    // Set options based on the user configuration.
    436439    {
    437440        bool mdok = true;   // Status of MD lookup result
    438441
    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 
    448442        // Set logging level
    449         int logLevel = psMetadataLookupS32(&mdok, config->site, "LOGLEVEL");
     443        int logLevel = psMetadataLookupS32(&mdok, config->xxUser, "LOGLEVEL");
    450444        if (mdok && logLevel >= 0)
    451445        {
     
    456450
    457451        // Set logging format
    458         psString logFormat = psMetadataLookupStr(&mdok, config->site, "LOGFORMAT");
     452        psString logFormat = psMetadataLookupStr(&mdok, config->xxUser, "LOGFORMAT");
    459453        if (mdok && logFormat)
    460454        {
     
    463457        }
    464458
    465         // Set logging destination first from command line, second from site configuration
     459        // Set logging destination first from command line, second from user configuration
    466460        psString logDest = NULL;        // Logging destination
    467461        argNum = psArgumentGet(*argc, argv, "-log");
     
    477471        }
    478472        if (!logDest) {
    479             logDest = psMemIncrRefCounter(psMetadataLookupStr(&mdok, config->site, "LOGDEST"));
     473            logDest = psMemIncrRefCounter(psMetadataLookupStr(&mdok, config->xxUser, "LOGDEST"));
    480474        }
    481475        if (logDest) {
     
    497491
    498492        // Set trace levels
    499         psMetadata *trace = psMetadataLookupMetadata(&mdok, config->site, "TRACE");
     493        psMetadata *trace = psMetadataLookupMetadata(&mdok, config->xxUser, "TRACE");
    500494        if (mdok && trace) {
    501495            psMetadataIterator *traceIter = psMetadataIteratorAlloc(trace, PS_LIST_HEAD, NULL); // Iterator
     
    515509
    516510        // Set trace formats
    517         psString traceFormat = psMetadataLookupStr(&mdok, config->site, "TRACEFORMAT");
     511        psString traceFormat = psMetadataLookupStr(&mdok, config->xxUser, "TRACEFORMAT");
    518512        if (mdok && traceFormat) {
    519513            psTrace("psModules.config", 7, "Setting trace format to %s\n", traceFormat);
     
    535529        }
    536530        if (!traceDest) {
    537             traceDest = psMemIncrRefCounter(psMetadataLookupStr(&mdok, config->site, "TRACEDEST"));
     531            traceDest = psMemIncrRefCounter(psMetadataLookupStr(&mdok, config->xxUser, "TRACEDEST"));
    538532        }
    539533        if (traceDest) {
     
    563557    }
    564558
    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);
     559    // XXX why was this being called here?  Is someone calling pmConfigRead multiple times?
     560    // pmConfigDone();
     561    assert (configPath == NULL); 
     562
     563    // define the config-file search path (configPath). 
     564    psString path = psMetadataLookupStr(NULL, config->xxUser, "PATH");
     565    pmConfigSet (path);
     566
     567    // load the SITE file
     568    psString siteFile = psMetadataLookupStr(NULL, config->xxUser, "SITE");
     569    if (!pmConfigFileRead(&config->xxSite, siteFile, "site")) {
     570        psFree(config);
     571        return NULL;
     572    }
     573
     574    // load the SYSTEM file
     575    psString systemFile = psMetadataLookupStr(NULL, config->xxUser, "SYSTEM");
     576    if (!pmConfigFileRead(&config->xxSystem, systemFile, "system")) {
     577        psFree(config);
     578        return NULL;
     579    }
     580
     581    // XXX read TIME from SITE (or system?)
     582    {
     583        bool mdok = true;
     584
     585        // Initialise the psLib time handling
     586        // XXX is this still needed / desired?
     587        psString timeName = psMetadataLookupStr(&mdok, config->xxSite, "TIME");
     588        if (mdok && timeName)
     589        {
     590            psTrace("psModules.config", 7, "Initialising psTime with file %s\n", timeName);
     591            psTimeInit(timeName);
     592        }
     593    }
    588594
    589595    // Next, we do a similar thing for the camera configuration file.  The
    590596    // file is read and parsed into psMetadata struct "camera".
    591     //
    592597    argNum = psArgumentGet(*argc, argv, "-camera");
    593598    if (argNum > 0) {
     
    600605            char *cameraName = argv[argNum]; // symbolic name of the camera
    601606
    602             // look for the CAMERAS list in config->site
    603             psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->site, "CAMERAS");
     607            // look for the CAMERAS list in config->xxSystem
     608            psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->xxSystem, "CAMERAS");
    604609            if (!cameras) {
    605610                psError(PS_ERR_IO, false, "Unable to find CAMERAS in site configuration.\n");
     
    647652                                  "Camera specified on command line", config->camera);
    648653
    649             if (!pmConfigCameraSkycellVersion(config->site, cameraName)) {
     654            if (!pmConfigCameraSkycellVersion(config->xxSystem, cameraName)) {
    650655                psError(PS_ERR_UNKNOWN, false,
    651656                        "Unable to generate skycell versions of specified camera %s.\n",
     
    655660            }
    656661
    657             if (!pmConfigCameraMosaickedVersions(config->site, cameraName)) {
     662            if (!pmConfigCameraMosaickedVersions(config->xxSystem, cameraName)) {
    658663                psError(PS_ERR_UNKNOWN, false,
    659664                        "Unable to generate mosaicked versions of specified camera %s.\n",
     
    668673    if (!config->camera && readCameraConfig) {
    669674        bool mdok;                      // Status of MD lookup
    670         psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->site, "CAMERAS"); // List of cameras
     675        psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->xxSystem, "CAMERAS"); // List of cameras
    671676        if (!mdok || !cameras) {
    672             psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find CAMERAS in the site configuration.\n");
     677            psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find CAMERAS in the system configuration.\n");
    673678            return false;
    674679        }
    675680
    676681        if (!metadataReadFiles(cameras, "camera configuration")) {
    677             psError(PS_ERR_UNKNOWN, false, "Unable to read cameras within site configuration.\n");
     682            psError(PS_ERR_UNKNOWN, false, "Unable to read cameras within system configuration.\n");
    678683            psFree(config);
    679684            return NULL;
     
    702707        psFree(iter);
    703708
    704         if (!pmConfigCameraSkycellVersionsAll(config->site)) {
     709        if (!pmConfigCameraSkycellVersionsAll(config->xxSystem)) {
    705710            psError(PS_ERR_UNKNOWN, false, "Unable to generate skycell versions of cameras.\n");
    706711            psFree(config);
    707712            return NULL;
    708713        }
    709         if (!pmConfigCameraMosaickedVersionsAll(config->site)) {
     714        if (!pmConfigCameraMosaickedVersionsAll(config->xxSystem)) {
    710715            psError(PS_ERR_UNKNOWN, false, "Unable to generate mosaicked versions of cameras.\n");
    711716            psFree(config);
     
    715720
    716721    // Load the recipes from the camera file, if appropriate
    717     if(!pmConfigReadRecipes(config, PM_RECIPE_SOURCE_SITE | PM_RECIPE_SOURCE_CAMERA)) {
     722    if(!pmConfigReadRecipes(config, PM_RECIPE_SOURCE_SYSTEM | PM_RECIPE_SOURCE_CAMERA)) {
    718723        psError(PS_ERR_IO, false, "Failed to read recipes from camera file");
    719724        psFree(config);
     
    746751        psArgumentRemove(argNum, argc, argv);
    747752
    748         psMetadata *cameras = psMetadataLookupMetadata(NULL, config->site, "CAMERAS"); // List of cameras
     753        psMetadata *cameras = psMetadataLookupMetadata(NULL, config->xxSystem, "CAMERAS"); // List of cameras
    749754        if (!cameras) {
    750755            psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find CAMERAS in the site configuration.\n");
     
    794799        } else {
    795800            char *dbserver = argv[argNum]; // The camera configuration file to read
    796             if (!psMetadataAddStr(config->site, PS_LIST_TAIL, "DBSERVER", PS_META_REPLACE, NULL, dbserver)) {
     801            if (!psMetadataAddStr(config->xxSite, PS_LIST_TAIL, "DBSERVER", PS_META_REPLACE, NULL, dbserver)) {
    797802                psWarning("Failed to overwrite .ipprc DBSERVER value");
    798803            }
     
    809814        } else {
    810815            char *dbname = argv[argNum]; // The camera configuration file to read
    811             if (!psMetadataAddStr(config->site, PS_LIST_TAIL, "DBNAME", PS_META_REPLACE, NULL, dbname)) {
     816            if (!psMetadataAddStr(config->xxSite, PS_LIST_TAIL, "DBNAME", PS_META_REPLACE, NULL, dbname)) {
    812817                psWarning("Failed to overwrite .ipprc DBNAME value");
    813818            }
     
    824829        } else {
    825830            char *dbuser = argv[argNum]; // The camera configuration file to read
    826             if (!psMetadataAddStr(config->site, PS_LIST_TAIL, "DBUSER", PS_META_REPLACE, NULL, dbuser)) {
     831            if (!psMetadataAddStr(config->xxSite, PS_LIST_TAIL, "DBUSER", PS_META_REPLACE, NULL, dbuser)) {
    827832                psWarning("Failed to overwrite .ipprc DBUSER value");
    828833            }
     
    839844        } else {
    840845            char *dbpassword = argv[argNum]; // The camera configuration file to read
    841             if (!psMetadataAddStr(config->site, PS_LIST_TAIL, "DBPASSWORD", PS_META_REPLACE,
     846            if (!psMetadataAddStr(config->xxSite, PS_LIST_TAIL, "DBPASSWORD", PS_META_REPLACE,
    842847                                  NULL, dbpassword)) {
    843848                psWarning("Failed to overwrite .ipprc DBPASSWORD value");
     
    855860        } else {
    856861            char *dbport = argv[argNum]; // The camera configuration file to read
    857             if (!psMetadataAddS32(config->site, PS_LIST_TAIL, "DBPORT", PS_META_REPLACE, NULL,
     862            if (!psMetadataAddS32(config->xxSite, PS_LIST_TAIL, "DBPORT", PS_META_REPLACE, NULL,
    858863                                  (psS32)atoi(dbport))) {
    859864                psWarning("Failed to overwrite .ipprc DBPORT value");
     
    10271032    if (! config->camera) {
    10281033        bool mdok;                      // Metadata lookup status
    1029         psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->site, "CAMERAS");
     1034        psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->xxSystem, "CAMERAS");
    10301035        if (! mdok || !cameras) {
    10311036            psError(PS_ERR_IO, true, "Unable to find CAMERAS in the configuration.");
     
    11141119    PS_ASSERT_STRING_NON_EMPTY(cameraName, NULL);
    11151120
    1116     psMetadata *cameras = psMetadataLookupMetadata(NULL, config->site, "CAMERAS");
     1121    psMetadata *cameras = psMetadataLookupMetadata(NULL, config->xxSystem, "CAMERAS");
    11171122    if (!cameras) {
    11181123        psError(PS_ERR_IO, true, "Unable to find CAMERAS in the configuration.");
     
    11401145{
    11411146    PS_ASSERT_PTR_NON_NULL(config, NULL);
    1142     PS_ASSERT_PTR_NON_NULL(config->site, NULL);
     1147    PS_ASSERT_PTR_NON_NULL(config->xxSite, NULL);
    11431148
    11441149    #ifndef HAVE_PSDB
     
    11571162
    11581163    // 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");
     1164    psString dbServer = psMetadataLookupStr(&mdStatus01, config->xxSite, "DBSERVER");
     1165    psString dbUsername = psMetadataLookupStr(&mdStatus02, config->xxSite, "DBUSER");
     1166    psString dbPassword = psMetadataLookupStr(&mdStatus03, config->xxSite, "DBPASSWORD");
     1167    psString dbName = psMetadataLookupStr(&mdStatus04, config->xxSite, "DBNAME");
     1168    psS32 dbPort = psMetadataLookupS32(&mdStatus05, config->xxSite, "DBPORT");
    11641169    if (!mdStatus05) {
    11651170        dbPort = 0;
     
    13521357    // replace path://PATH with matched datapath
    13531358    if (!strncasecmp(filename, "path://", strlen("path://"))) {
    1354         PS_ASSERT_METADATA_NON_NULL(config->site, NULL);
     1359        PS_ASSERT_METADATA_NON_NULL(config->xxSite, NULL);
    13551360
    13561361        psString newName = psStringCopy(filename);
    13571362
    13581363        // 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");
     1364        // replace PATH with matching name from config->xxSite:DATAPATH
     1365        psMetadata *datapath = psMetadataLookupPtr (NULL, config->xxSite, "DATAPATH");
    13611366        if (datapath == NULL) {
    13621367            psError(PS_ERR_UNKNOWN, true, "DATAPATH is not defined in config.site");
     
    14101415        // if env isn't set, check the config system
    14111416        if (!neb_server) {
    1412             neb_server = psMetadataLookupStr(&status, config->site, "NEB_SERVER");
     1417            neb_server = psMetadataLookupStr(&status, config->xxSite, "NEB_SERVER");
    14131418            if (!status) {
    14141419                psError(PM_ERR_CONFIG, true, "failed to lookup config value for NEB_SERVER.");
Note: See TracChangeset for help on using the changeset viewer.