View | Details | Raw Unified | Return to bug 41333
Collapse All | Expand All

(-)jk_isapi_plugin.c (-121 / +84 lines)
Lines 86-94 Link Here
86
#define URI_SELECT_PARSED_VERB      ("parsed")
86
#define URI_SELECT_PARSED_VERB      ("parsed")
87
#define URI_SELECT_UNPARSED_VERB    ("unparsed")
87
#define URI_SELECT_UNPARSED_VERB    ("unparsed")
88
#define URI_SELECT_ESCAPED_VERB     ("escaped")
88
#define URI_SELECT_ESCAPED_VERB     ("escaped")
89
#define URI_REWRITE_VERB            ("rewrite_rule_file")
89
#define URI_REWRITE_TAG             ("rewrite_rule_file")
90
#define SHM_SIZE_VERB               ("shm_size")
90
#define SHM_SIZE_TAG                ("shm_size")
91
#define WORKER_MOUNT_RELOAD_VERB    ("worker_mount_reload")
91
#define WORKER_MOUNT_RELOAD_TAG     ("worker_mount_reload")
92
92
93
93
94
#define TRANSLATE_HEADER            ("Translate:")
94
#define TRANSLATE_HEADER            ("Translate:")
Lines 211-216 Link Here
211
211
212
static int read_registry_init_data(void);
212
static int read_registry_init_data(void);
213
213
214
static int get_config_parameter(LPVOID src, const char *tag, 
215
                                char *val, DWORD sz);
216
217
static int get_config_bool(LPVOID src, const char *tag, int def);
218
219
static int get_config_int(LPVOID src, const char *tag, int def);
220
214
static int get_registry_config_parameter(HKEY hkey,
221
static int get_registry_config_parameter(HKEY hkey,
215
                                         const char *tag, char *b, DWORD sz);
222
                                         const char *tag, char *b, DWORD sz);
216
223
Lines 1324-1475 Link Here
1324
1331
1325
static int read_registry_init_data(void)
1332
static int read_registry_init_data(void)
1326
{
1333
{
1327
    char tmpbuf[INTERNET_MAX_URL_LENGTH];
1334
    char tmpbuf[MAX_PATH];
1328
    HKEY hkey;
1329
    long rc;
1330
    int ok = JK_TRUE;
1335
    int ok = JK_TRUE;
1331
    const char *tmp;
1336
    LPVOID src;
1332
    jk_map_t *map;
1337
    HKEY hkey;
1338
    jk_map_t *map = NULL;
1333
1339
1334
    if (jk_map_alloc(&map)) {
1340
    if (jk_map_alloc(&map)) {
1335
        if (jk_map_read_properties(map, ini_file_name, NULL, logger)) {
1341
        if (jk_map_read_properties(map, ini_file_name, NULL, logger)) {
1336
            using_ini_file = JK_TRUE;
1342
            using_ini_file = JK_TRUE;
1343
            src = map;
1337
        }
1344
        }
1338
    }
1339
    if (using_ini_file) {
1340
        tmp = jk_map_get_string(map, JK_LOG_FILE_TAG, NULL);
1341
        if (tmp) {
1342
            strcpy(log_file, tmp);
1343
        }
1344
        else {
1345
        else {
1345
            ok = JK_FALSE;
1346
            jk_map_free(&map);
1346
        }
1347
        }
1347
        tmp = jk_map_get_string(map, JK_LOG_LEVEL_TAG, NULL);
1348
    }
1348
        if (tmp) {
1349
    if (!using_ini_file) {
1349
            log_level = jk_parse_log_level(tmp);
1350
        long rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, REGISTRY_LOCATION, 
1351
                               (DWORD)0, KEY_READ, &hkey);
1352
        if (ERROR_SUCCESS != rc) {
1353
            return JK_FALSE;
1350
        }
1354
        }
1351
        tmp = jk_map_get_string(map, EXTENSION_URI_TAG, NULL);
1352
        if (tmp) {
1353
            strcpy(extension_uri, tmp);
1354
        }
1355
        else {
1355
        else {
1356
            ok = JK_FALSE;
1356
            src = &hkey;
1357
        }
1357
        }
1358
        tmp = jk_map_get_string(map, JK_WORKER_FILE_TAG, NULL);
1358
    }
1359
        if (tmp) {
1359
    ok = ok && get_config_parameter(src, JK_LOG_FILE_TAG, log_file, sizeof(log_file));
1360
            strcpy(worker_file, tmp);
1360
    if (get_config_parameter(src, JK_LOG_LEVEL_TAG, tmpbuf, sizeof(tmpbuf))) {
1361
        log_level = jk_parse_log_level(tmpbuf);
1362
    }
1363
    ok = ok && get_config_parameter(src, EXTENSION_URI_TAG, extension_uri, sizeof(extension_uri));
1364
    ok = ok && get_config_parameter(src, JK_WORKER_FILE_TAG, worker_file, sizeof(worker_file));
1365
    ok = ok && get_config_parameter(src, JK_MOUNT_FILE_TAG, worker_mount_file, sizeof(worker_mount_file));
1366
    get_config_parameter(src, URI_REWRITE_TAG, rewrite_rule_file, sizeof(rewrite_rule_file));
1367
    if (get_config_parameter(src, URI_SELECT_TAG, tmpbuf, sizeof(tmpbuf))) {
1368
        int opt = parse_uri_select(tmpbuf);
1369
        if (opt >= 0) {
1370
            uri_select_option = opt;
1361
        }
1371
        }
1362
        else {
1372
        else {
1363
            ok = JK_FALSE;
1373
            ok = JK_FALSE;
1364
        }
1374
        }
1365
        tmp = jk_map_get_string(map, JK_MOUNT_FILE_TAG, NULL);
1375
    }
1366
        if (tmp) {
1376
    shm_config_size = get_config_int(src, SHM_SIZE_TAG, JK_SHM_DEF_SIZE);
1367
            strcpy(worker_mount_file, tmp);
1377
    worker_mount_reload = get_config_int(src, WORKER_MOUNT_RELOAD_TAG, JK_URIMAP_DEF_RELOAD);
1368
        }
1369
        else {
1370
            ok = JK_FALSE;
1371
        }
1372
        tmp = jk_map_get_string(map, URI_REWRITE_VERB, NULL);
1373
        if (tmp) {
1374
            strcpy(rewrite_rule_file, tmp);
1375
        }
1376
        tmp = jk_map_get_string(map, URI_SELECT_TAG, NULL);
1377
        if (tmp) {
1378
            int opt = parse_uri_select(tmp);
1379
            if (opt >= 0) {
1380
                uri_select_option = opt;
1381
            }
1382
            else {
1383
                ok = JK_FALSE;
1384
            }
1385
        }
1386
        tmp = jk_map_get_string(map, SHM_SIZE_VERB, NULL);
1387
        if (tmp) {
1388
            shm_config_size = atoi(tmp);
1389
        }
1390
        tmp = jk_map_get_string(map, WORKER_MOUNT_RELOAD_VERB, NULL);
1391
        if (tmp) {
1392
            worker_mount_reload = atoi(tmp);
1393
        }
1394
1378
1379
    if (using_ini_file) {
1380
        jk_map_free(&map);
1395
    }
1381
    }
1396
    else {
1382
    else {
1397
        rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
1383
        RegCloseKey(hkey);
1398
                          REGISTRY_LOCATION, (DWORD) 0, KEY_READ, &hkey);
1384
    }
1399
        if (ERROR_SUCCESS != rc) {
1385
    return ok;
1400
            return JK_FALSE;
1386
}
1401
        }
1402
1387
1403
        if (get_registry_config_parameter(hkey,
1388
static int get_config_parameter(LPVOID src, const char *tag, 
1404
                                          JK_LOG_FILE_TAG,
1389
                                char *val, DWORD sz)
1405
                                          tmpbuf, sizeof(log_file))) {
1390
{
1406
            strcpy(log_file, tmpbuf);
1391
    const char *tmp = NULL;
1392
    if (using_ini_file) {
1393
        tmp = jk_map_get_string((jk_map_t*)src, tag, NULL);
1394
        if (tmp && (strnlen(tmp, sz) < sz)) {
1395
            strcpy(val, tmp);
1396
            return JK_TRUE;
1407
        }
1397
        }
1408
        else {
1398
        else {
1409
            ok = JK_FALSE;
1399
            return JK_FALSE;
1410
        }
1400
        }
1401
    } else {
1402
        return get_registry_config_parameter(*((HKEY*)src), tag, val, sz);
1403
    }
1404
}
1411
1405
1412
        if (get_registry_config_parameter(hkey,
1406
static int get_config_int(LPVOID src, const char *tag, int def)
1413
                                          JK_LOG_LEVEL_TAG,
1407
{
1414
                                          tmpbuf, sizeof(tmpbuf))) {
1408
    if (using_ini_file) {
1415
            log_level = jk_parse_log_level(tmpbuf);
1409
        return jk_map_get_int((jk_map_t*)src, tag, def);
1410
    } else {
1411
        int val;
1412
        if (get_registry_config_number(*((HKEY*)src), tag, &val) ) {
1413
            return val;
1416
        }
1414
        }
1417
1418
        if (get_registry_config_parameter(hkey,
1419
                                          EXTENSION_URI_TAG,
1420
                                          tmpbuf, sizeof(extension_uri))) {
1421
            strcpy(extension_uri, tmpbuf);
1422
        }
1423
        else {
1415
        else {
1424
            ok = JK_FALSE;
1416
            return def;
1425
        }
1417
        }
1418
    }
1419
}
1426
1420
1427
        if (get_registry_config_parameter(hkey,
1421
static int get_config_bool(LPVOID src, const char *tag, int def)
1428
                                          JK_WORKER_FILE_TAG,
1422
{
1429
                                          tmpbuf, sizeof(worker_file))) {
1423
    if (using_ini_file) {
1430
            strcpy(worker_file, tmpbuf);
1424
        return jk_map_get_bool((jk_map_t*)src, tag, def);
1425
    } else {
1426
        char tmpbuf[128];
1427
        if (get_registry_config_parameter(*((HKEY*)src), tag, 
1428
                                          tmpbuf, sizeof(tmpbuf))) {
1429
            return jk_get_bool_code(tmpbuf, def);
1431
        }
1430
        }
1432
        else {
1431
        else {
1433
            ok = JK_FALSE;
1432
            return def;
1434
        }
1433
        }
1435
1434
    }    
1436
        if (get_registry_config_parameter(hkey,
1437
                                          JK_MOUNT_FILE_TAG,
1438
                                          tmpbuf,
1439
                                          sizeof(worker_mount_file))) {
1440
            strcpy(worker_mount_file, tmpbuf);
1441
        }
1442
        else {
1443
            ok = JK_FALSE;
1444
        }
1445
1446
        if (get_registry_config_parameter(hkey,
1447
                                          URI_REWRITE_VERB,
1448
                                          tmpbuf,
1449
                                          sizeof(rewrite_rule_file))) {
1450
            strcpy(rewrite_rule_file, tmpbuf);
1451
        }
1452
1453
        if (get_registry_config_parameter(hkey,
1454
                                          URI_SELECT_TAG,
1455
                                          tmpbuf, sizeof(tmpbuf))) {
1456
            int opt = parse_uri_select(tmpbuf);
1457
            if (opt >= 0) {
1458
                uri_select_option = opt;
1459
            }
1460
            else {
1461
                ok = JK_FALSE;
1462
            }
1463
        }
1464
        get_registry_config_number(hkey, SHM_SIZE_VERB,
1465
                                   &shm_config_size);
1466
1467
        get_registry_config_number(hkey, WORKER_MOUNT_RELOAD_VERB,
1468
                                   &worker_mount_reload);
1469
1470
        RegCloseKey(hkey);
1471
    }
1472
    return ok;
1473
}
1435
}
1474
1436
1475
static int get_registry_config_parameter(HKEY hkey,
1437
static int get_registry_config_parameter(HKEY hkey,
Lines 1478-1490 Link Here
1478
    DWORD type = 0;
1440
    DWORD type = 0;
1479
    LONG lrc;
1441
    LONG lrc;
1480
1442
1443
    sz = sz - 1; /* Reserve space for RegQueryValueEx to add null terminator */
1444
    b[sz] = '\0'; /* Null terminate in case RegQueryValueEx doesn't */
1445
1481
    lrc = RegQueryValueEx(hkey, tag, (LPDWORD) 0, &type, (LPBYTE) b, &sz);
1446
    lrc = RegQueryValueEx(hkey, tag, (LPDWORD) 0, &type, (LPBYTE) b, &sz);
1482
    if ((ERROR_SUCCESS != lrc) || (type != REG_SZ)) {
1447
    if ((ERROR_SUCCESS != lrc) || (type != REG_SZ)) {
1483
        return JK_FALSE;
1448
        return JK_FALSE;
1484
    }
1449
    }
1485
1450
1486
    b[sz] = '\0';
1487
1488
    return JK_TRUE;
1451
    return JK_TRUE;
1489
}
1452
}
1490
1453

Return to bug 41333