IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 5, 2008, 3:13:14 PM (18 years ago)
Author:
Paul Price
Message:

Adding function pmConfigUserSite to get values from the user/site configurations. Using this for database details.

File:
1 edited

Legend:

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

    r18921 r18926  
    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     }
     1266psMetadataItem *pmConfigUserSite(const pmConfig *config, const char *name, psDataType type)
     1267{
     1268    PS_ASSERT_PTR_NON_NULL(config, NULL);
     1269    PS_ASSERT_STRING_NON_EMPTY(name, NULL);
     1270
     1271    psMetadataItem *item = psMetadataLookup(config->user, name);
     1272    if (!item) {
     1273        item = psMetadataLookup(config->site, name);
     1274        if (!item) {
     1275            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     1276                    "Unable to find %s in user or site configuration", name);
     1277            return NULL;
     1278        }
     1279    }
     1280    if (item->type != type) {
     1281        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     1282                "Type of %s (%x) in user/site configuration does not match expected (%x)",
     1283                name, item->type, type);
     1284        return NULL;
     1285    }
     1286
     1287    return item;
     1288}
    12791289
    12801290
     
    12961306    }
    12971307
    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) {
     1308    // Connection details
     1309    psMetadataItem *server = pmConfigUserSite(config, "DBSERVER",   PS_DATA_STRING);
     1310    psMetadataItem *user   = pmConfigUserSite(config, "DBUSER",     PS_DATA_STRING);
     1311    psMetadataItem *pass   = pmConfigUserSite(config, "DBPASSWORD", PS_DATA_STRING);
     1312    psMetadataItem *name   = pmConfigUserSite(config, "DBNAME",     PS_DATA_STRING);
     1313    psMetadataItem *port   = pmConfigUserSite(config, "DBPORT",     PS_TYPE_S32);
     1314
     1315    if (!server || !user || !pass || !name) {
    13051316        psWarning("Cannot find DBSERVER/DBUSER/DBPASSWORD/DBNAME in user or site configuration: "
    13061317                  "unable to connect to database.");
     1318        psErrorClear();
    13071319        return NULL;
    13081320    }
    1309 
    1310     if (strcasecmp(dbName, "XXX") == 0 || strcasecmp(dbName, "NONE") == 0) {
    1311         psTrace("psModules.config", 1, "Database initialisation skipped: database is %s.", dbName);
     1321    if (!port) {
     1322        psTrace("psModules.config", 1, "Database port defaulting to 0");
     1323        psErrorClear();
     1324    }
     1325
     1326    if (strcasecmp(name->data.str, "XXX") == 0 || strcasecmp(name->data.str, "NONE") == 0) {
     1327        psTrace("psModules.config", 1, "Database initialisation skipped: database is %s.", name->data.str);
    13121328        return NULL;
    13131329    }
    13141330
    1315     config->database = psDBInit(dbServer, dbUser, dbPass, dbName, dbPort);
     1331    config->database = psDBInit(server->data.str, user->data.str, pass->data.str, name->data.str,
     1332                                port ? port->data.S32 : 0);
    13161333    return config->database;
    13171334
Note: See TracChangeset for help on using the changeset viewer.