IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18921


Ignore:
Timestamp:
Aug 5, 2008, 12:23:33 PM (18 years ago)
Author:
Paul Price
Message:

Take database information from user or site configuration.

File:
1 edited

Legend:

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

    r18908 r18921  
    12641264}
    12651265
     1266// Look up a value from the user or site configuration
     1267#define CONFIG_USER_SITE(TYPE, TARGET, TYPENAME, NAME, DEFAULT) \
     1268    TYPE TARGET; \
     1269    { \
     1270        bool status = false;                /* Status of MD lookup */ \
     1271        TARGET = psMetadataLookup##TYPENAME(&status, config->user, NAME); \
     1272        if (!status) { \
     1273            TARGET = psMetadataLookup##TYPENAME(&status, config->site, NAME); \
     1274            if (!status) { \
     1275                TARGET = DEFAULT; \
     1276            } \
     1277        } \
     1278    }
     1279
     1280
    12661281psDB *pmConfigDB(pmConfig *config)
    12671282{
     
    12691284    PS_ASSERT_PTR_NON_NULL(config->user, NULL);
    12701285
    1271     #ifndef HAVE_PSDB
     1286#ifndef HAVE_PSDB
    12721287
    12731288    psError(PS_ERR_UNKNOWN, false,
     
    12751290    return NULL;
    12761291
    1277     #else
     1292#else
    12781293
    12791294    if (config->database) {
     
    12811296    }
    12821297
    1283     psBool mdStatus01 = false;
    1284     psBool mdStatus02 = false;
    1285     psBool mdStatus03 = false;
    1286     psBool mdStatus04 = false;
    1287     psBool mdStatus05 = false;
    1288 
    1289     // XXX leaky strings
    1290     psString dbServer = psMetadataLookupStr(&mdStatus01, config->user, "DBSERVER");
    1291     psString dbUsername = psMetadataLookupStr(&mdStatus02, config->user, "DBUSER");
    1292     psString dbPassword = psMetadataLookupStr(&mdStatus03, config->user, "DBPASSWORD");
    1293     psString dbName = psMetadataLookupStr(&mdStatus04, config->user, "DBNAME");
    1294     psS32 dbPort = psMetadataLookupS32(&mdStatus05, config->user, "DBPORT");
    1295     if (!mdStatus05) {
    1296         dbPort = 0;
    1297     }
    1298     if (!(mdStatus01 && mdStatus02 && mdStatus03 && mdStatus04)) {
    1299         psWarning("Could not determine database server, name, user, and password from site metadata.\n");
     1298    CONFIG_USER_SITE(const char*, dbServer, Str, "DBSERVER",   NULL);
     1299    CONFIG_USER_SITE(const char*, dbUser,   Str, "DBUSER",     NULL);
     1300    CONFIG_USER_SITE(const char*, dbPass,   Str, "DBPASSWORD", NULL);
     1301    CONFIG_USER_SITE(const char*, dbName,   Str, "DBNAME",     NULL);
     1302    CONFIG_USER_SITE(int,         dbPort,   S32, "DBPORT",     0);
     1303
     1304    if (!dbServer || !dbUser || !dbPass || !dbName) {
     1305        psWarning("Cannot find DBSERVER/DBUSER/DBPASSWORD/DBNAME in user or site configuration: "
     1306                  "unable to connect to database.");
    13001307        return NULL;
    13011308    }
     
    13061313    }
    13071314
    1308     config->database = psDBInit(dbServer, dbUsername, dbPassword, dbName, dbPort);
     1315    config->database = psDBInit(dbServer, dbUser, dbPass, dbName, dbPort);
    13091316    return config->database;
    1310     #endif
     1317
     1318#endif
    13111319}
    13121320
Note: See TracChangeset for help on using the changeset viewer.