View Source

[modwtcl]
apreq.h
dist/
libapreq1/
mod_wtcl.c
mod_wtcl.h
setupExclude.txt
util/
win.def
win.mak
wt1.1/
WtAppTable.c
WtAppTable.h
WtBasicCmds.c
WtBasicCmds.h
WtClientRequest.c
WtClientRequest.h
WtCollection.c
WtCollection.h
WtCollectionCmds.c
WtCollectionCmds.h
WtContext.c
WtContext.h
WtContextEvents.c
WtContextEvents.h
WtCookie.c
WtCookie.h
WtDbSession.c
WtDbSession.h
WtExecute.c
WtExecute.h
WtHtmlEntities.c
WtHtmlEntities.h
WtInitCmds.c
WtInitCmds.h
WtMtTable.c
WtMtTable.h
WtMultiTable.c
WtMultiTable.h
WtOS.h
WtProcSession.c
WtProcSession.h
WtResponse.c
WtResponse.h
WtServerCmds.c
WtServerCmds.h
WtSession.c
WtSession.h
WtSettings.c
WtSettings.h
WtTable.c
WtTable.h
WtTableCmds.c
WtTableCmds.h
WtTableUtil.c
WtTableUtil.h
WtUpload.c
WtUpload.h
WtUtil.c
WtUtil.h
WtWebErrors.c
WtWebErrors.h
WtWindows.h
File: / archive / modwtcl / WtSettings.c

Lines Size Modified Created Owner MIME Types
389 11,630 2010/05/08 18:46:41 2011/06/13 15:35:15 BUILTIN\Administrators text/x-csrc

0001
/*
0002
 * Copyright 2001 Alexander Boverman and the original authors.
0003
 * 
0004
 * Licensed under the Apache License, Version 2.0 (the "License");
0005
 * you may not use this file except in compliance with the License.
0006
 * You may obtain a copy of the License at
0007
 * 
0008
 *      http://www.apache.org/licenses/LICENSE-2.0
0009
 * 
0010
 * Unless required by applicable law or agreed to in writing, software
0011
 * distributed under the License is distributed on an "AS IS" BASIS,
0012
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013
 * See the License for the specific language governing permissions and
0014
 * limitations under the License.
0015
 */
0016
0017
#include "WtSettings.h"
0018
#include "WtContext.h"
0019
#include "WtTable.h"
0020
#include "WtUtil.h"
0021
#include "WtDbSession.h"
0022
#include "WtTableUtil.h"
0023
#include "WtContextEvents.h"
0024
0025
void WtInitOptionCodes(WtContext *w)
0026
{
0027
  Tcl_HashEntry *ent;
0028
  int created;
0029
  Tcl_HashSearch search;
0030
  const char *key;
0031
  int code;
0032
  Tcl_Obj *str;
0033
0034
  if (w->optionCodes) {
0035
    return;
0036
  }
0037
0038
  w->optionCodes = (Tcl_HashTable *)ckalloc(sizeof(Tcl_HashTable));
0039
  Tcl_InitHashTable(w->optionCodes, TCL_STRING_KEYS);
0040
0041
  ent = Tcl_CreateHashEntry(w->optionCodes, "server.reuseInterp", &created);
0042
  Tcl_SetHashValue(ent, WT_SERVER_REUSE_INTERP);
0043
0044
  ent = Tcl_CreateHashEntry(w->optionCodes, "server.deleteInterp", &created);
0045
  Tcl_SetHashValue(ent, WT_SERVER_DELETE_INTERP);
0046
0047
  ent = Tcl_CreateHashEntry(w->optionCodes, "server.taskNamespace", &created);
0048
  Tcl_SetHashValue(ent, WT_SERVER_TASK_NAMESPACE);
0049
0050
  ent = Tcl_CreateHashEntry(w->optionCodes, "server.initInterpScript", &created);
0051
  Tcl_SetHashValue(ent, WT_SERVER_INIT_INTERP_SCRIPT);
0052
0053
  ent = Tcl_CreateHashEntry(w->optionCodes, "server.loadPackagesScript", &created);
0054
  Tcl_SetHashValue(ent, WT_SERVER_LOAD_PACKAGES_SCRIPT);
0055
0056
  ent = Tcl_CreateHashEntry(w->optionCodes, "server.startWorkerScript", &created);
0057
  Tcl_SetHashValue(ent, WT_SERVER_START_WORKER_SCRIPT);
0058
0059
  ent = Tcl_CreateHashEntry(w->optionCodes, "server.createInterpScript", &created);
0060
  Tcl_SetHashValue(ent, WT_SERVER_CREATE_INTERP_SCRIPT);
0061
0062
  ent = Tcl_CreateHashEntry(w->optionCodes, "server.startRequestSript", &created);
0063
  Tcl_SetHashValue(ent, WT_SERVER_START_REQUEST_SCRIPT);
0064
0065
  ent = Tcl_CreateHashEntry(w->optionCodes, "server.endRequestSript", &created);
0066
  Tcl_SetHashValue(ent, WT_SERVER_END_REQUEST_SCRIPT);
0067
0068
  ent = Tcl_CreateHashEntry(w->optionCodes, "server.errorScript", &created);
0069
  Tcl_SetHashValue(ent, WT_SERVER_ERROR_SCRIPT);
0070
0071
  ent = Tcl_CreateHashEntry(w->optionCodes, "server.restScript", &created);
0072
  Tcl_SetHashValue(ent, WT_SERVER_REST_INTERP_SCRIPT);
0073
0074
  ent = Tcl_CreateHashEntry(w->optionCodes, "server.deleteInterpScript", &created);
0075
  Tcl_SetHashValue(ent, WT_SERVER_DELETE_INTERP_SCRIPT);
0076
0077
  ent = Tcl_CreateHashEntry(w->optionCodes, "server.endWorkerScript", &created);
0078
  Tcl_SetHashValue(ent, WT_SERVER_END_WORKER_SCRIPT);
0079
0080
  ent = Tcl_CreateHashEntry(w->optionCodes, "server.includeStartScript", &created);
0081
  Tcl_SetHashValue(ent, WT_SERVER_INCLUDE_START_SCRIPT);
0082
0083
  ent = Tcl_CreateHashEntry(w->optionCodes, "server.includeEndScript", &created);
0084
  Tcl_SetHashValue(ent, WT_SERVER_INCLUDE_END_SCRIPT);
0085
0086
  ent = Tcl_CreateHashEntry(w->optionCodes, "server.includeNamespace", &created);
0087
  Tcl_SetHashValue(ent, WT_SERVER_INCLUDE_NAMESPACE);
0088
0089
  ent = Tcl_CreateHashEntry(w->optionCodes, "server.addHeaderTrailer", &created);
0090
  Tcl_SetHashValue(ent, WT_SERVER_ADD_HEADER_TRAILER);
0091
0092
  ent = Tcl_CreateHashEntry(w->optionCodes, "server.includeHeader", &created);
0093
  Tcl_SetHashValue(ent, WT_SERVER_INCLUDE_HEADER);
0094
0095
  ent = Tcl_CreateHashEntry(w->optionCodes, "server.includeTrailer", &created);
0096
  Tcl_SetHashValue(ent, WT_SERVER_INCLUDE_TRAILER);
0097
0098
  ent = Tcl_CreateHashEntry(w->optionCodes, "server.scriptStartString", &created);
0099
  Tcl_SetHashValue(ent, WT_SERVER_SCRIPT_START_STRING);
0100
0101
  ent = Tcl_CreateHashEntry(w->optionCodes, "server.scriptEndString", &created);
0102
  Tcl_SetHashValue(ent, WT_SERVER_SCRIPT_END_STRING);
0103
0104
  ent = Tcl_CreateHashEntry(w->optionCodes, "server.interpolateText", &created);
0105
  Tcl_SetHashValue(ent, WT_SERVER_INTERPOLATE_TEXT);
0106
0107
  ent = Tcl_CreateHashEntry(w->optionCodes, "server.pageTextHandler", &created);
0108
  Tcl_SetHashValue(ent, WT_SERVER_PAGE_TEXT_HANDLER);
0109
0110
  ent = Tcl_CreateHashEntry(w->optionCodes, "server.pageExprHandler", &created);
0111
  Tcl_SetHashValue(ent, WT_SERVER_PAGE_EXPR_HANDLER);
0112
0113
  ent = Tcl_CreateHashEntry(w->optionCodes, "session.handler", &created);
0114
  Tcl_SetHashValue(ent, WT_SESSION_HANDLER);
0115
0116
  ent = Tcl_CreateHashEntry(w->optionCodes, "session.handlerType", &created);
0117
  Tcl_SetHashValue(ent, WT_SESSION_HANDLER_TYPE);
0118
0119
  ent = Tcl_CreateHashEntry(w->optionCodes, "session.cookieName", &created);
0120
  Tcl_SetHashValue(ent, WT_SESSION_COOKIE_NAME);
0121
0122
  ent = Tcl_CreateHashEntry(w->optionCodes, "session.maxIdleTime", &created);
0123
  Tcl_SetHashValue(ent, WT_SESSION_MAX_IDLE_TIME);
0124
0125
  ent = Tcl_CreateHashEntry(w->optionCodes, "session.sweepFrequency", &created);
0126
  Tcl_SetHashValue(ent, WT_SESSION_SWEEP_FREQUENCY);
0127
0128
  ent = Tcl_CreateHashEntry(w->optionCodes,
0129
    "session.dbSession.dbHandlerNamespace", &created);
0130
  Tcl_SetHashValue(ent, WT_DB_SESSION_HANDLER);
0131
0132
  ent = Tcl_CreateHashEntry(w->optionCodes, "server.dataSourceHandler", &created);
0133
  Tcl_SetHashValue(ent, WT_DATA_SOURCE_HANDLER);
0134
0135
  /* Get key name from option code */
0136
0137
  w->optionKeys = (Tcl_HashTable *)ckalloc(sizeof(Tcl_HashTable));
0138
  Tcl_InitHashTable(w->optionKeys, TCL_ONE_WORD_KEYS);
0139
0140
  ent = Tcl_FirstHashEntry(w->optionCodes, &search);
0141
0142
  while (ent) {
0143
    key = (const char *)Tcl_GetHashKey(w->optionCodes, ent);
0144
    code = (int)Tcl_GetHashValue(ent);
0145
    Tcl_CreateHashEntry(w->optionKeys, (char *)code, &created);
0146
    str = Tcl_NewStringObj(key, -1);
0147
    Tcl_IncrRefCount(str);
0148
    Tcl_SetHashValue(ent, str);
0149
    ent = Tcl_NextHashEntry(&search);
0150
  }
0151
}
0152
0153
WtOptionCode WtGetOptionCode(const char *key, WtContext *w)
0154
{
0155
  Tcl_HashEntry *ent;
0156
0157
  WtInitOptionCodes(w);
0158
0159
  if (ent = Tcl_FindHashEntry(w->optionCodes, key)) {
0160
    return (WtOptionCode)Tcl_GetHashValue(ent);
0161
  }
0162
0163
  return WT_UNKNOWN_OPTION;
0164
}
0165
0166
Tcl_Obj *WtGetOptionKey(WtOptionCode code, WtContext *w)
0167
{
0168
  Tcl_HashEntry *ent;
0169
0170
  WtInitOptionCodes(w);
0171
0172
  if (ent = Tcl_FindHashEntry(w->optionKeys, (char *)code)) {
0173
    return (Tcl_Obj *)Tcl_GetHashValue(ent);
0174
  }
0175
0176
  return NULL;
0177
}
0178
0179
/* Initialize the default request settings */
0180
0181
int WtInitDefaultContextSettings(WtContext *w)
0182
{
0183
  if (!w->defaultCtxSettings) {
0184
    WtSetObj(&w->defaultCtxSettings, WtNewTableObj());
0185
    WtTableSetStrToStr(w->defaultCtxSettings, "server.dataSourceHandler",
0186
      "::wt::server::dataSources::wtSqlServer");
0187
  }
0188
  return 1;
0189
}
0190
0191
/* Initialize basic web settings */
0192
0193
int WtInitWebSettings(WtContext *w, Tcl_Obj *settings, Tcl_Interp *interp)
0194
{
0195
  int ok = 1;
0196
  Tcl_HashTable *settingsTable = WtGetTableMap(settings);
0197
  Tcl_HashEntry *ent;
0198
  Tcl_HashSearch search;
0199
  const char *key;
0200
  Tcl_Obj *val;
0201
0202
  ent = Tcl_FirstHashEntry(settingsTable, &search);
0203
  while (ent) {
0204
    key = WtToString((Tcl_Obj *)Tcl_GetHashKey(settingsTable, ent));
0205
    val = (Tcl_Obj *)Tcl_GetHashValue(ent);
0206
    if (!WtInitWebSetting(w, key, val, interp)) {
0207
      ok = 0;
0208
      break;
0209
    }
0210
    ent = Tcl_NextHashEntry(&search);
0211
  }
0212
0213
  return ok;
0214
}
0215
0216
/* Init a setting */
0217
0218
int WtInitWebSetting(WtContext *w, const char *key, Tcl_Obj *val,
0219
    Tcl_Interp *interp)
0220
{
0221
  int opt, flag, intVal, ok = 1;
0222
  double dblVal;
0223
  WtDbSession *ds;
0224
0225
  opt = WtGetOptionCode(key, w);
0226
0227
  switch (opt) {
0228
    case WT_SERVER_DELETE_INTERP:
0229
      if (Tcl_GetBooleanFromObj(interp, val, &flag) != TCL_OK) {
0230
        ok = 0;
0231
      } else {
0232
        w->web->deleteInterp = flag;
0233
      }
0234
      break;
0235
0236
    case WT_SERVER_LOAD_PACKAGES_SCRIPT:
0237
      WtTableAppendObjToList(w->web->ctxEventHandlers, "loadPackages", val,
0238
        interp);
0239
      break;
0240
0241
    case WT_SERVER_START_WORKER_SCRIPT:
0242
      WtTableAppendObjToList(w->web->ctxEventHandlers, "startWorker", val,
0243
        interp);
0244
      break;
0245
0246
    case WT_SERVER_CREATE_INTERP_SCRIPT:
0247
      WtTableAppendObjToList(w->web->ctxEventHandlers, "createInterp", val,
0248
        interp);
0249
      break;
0250
0251
    case WT_SERVER_START_REQUEST_SCRIPT:
0252
      WtTableAppendObjToList(w->web->ctxEventHandlers, "startRequest", val,
0253
        interp);
0254
      break;
0255
0256
    case WT_SERVER_END_REQUEST_SCRIPT:
0257
      WtTableAppendObjToList(w->web->ctxEventHandlers, "endRequest", val,
0258
        interp);
0259
      break;
0260
0261
    case WT_SERVER_ERROR_SCRIPT:
0262
      WtTableAppendObjToList(w->web->ctxEventHandlers, "error", val,
0263
        interp);
0264
      break;
0265
0266
    case WT_SERVER_REST_INTERP_SCRIPT:
0267
      WtTableAppendObjToList(w->web->ctxEventHandlers, "restInterp", val,
0268
        interp);
0269
      break;
0270
0271
    case WT_SERVER_DELETE_INTERP_SCRIPT:
0272
      WtTableAppendObjToList(w->web->ctxEventHandlers, "deleteInterp", val,
0273
        interp);
0274
      break;
0275
0276
    case WT_SERVER_END_WORKER_SCRIPT:
0277
      WtTableAppendObjToList(w->web->ctxEventHandlers, "endWorker", val,
0278
        interp);
0279
      break;
0280
0281
    case WT_SERVER_INCLUDE_START_SCRIPT:
0282
      WtTableAppendObjToList(w->web->ctxEventHandlers, "includeStart", val,
0283
        interp);
0284
      break;
0285
0286
    case WT_SERVER_INCLUDE_END_SCRIPT:
0287
      WtTableAppendObjToList(w->web->ctxEventHandlers, "includeEnd", val,
0288
        interp);
0289
      break;
0290
0291
    case WT_SERVER_INCLUDE_NAMESPACE:
0292
      WtSetObj(&w->web->loader.includeNamespace, val);
0293
      break;
0294
0295
    case WT_SERVER_ADD_HEADER_TRAILER:
0296
      if (Tcl_GetBooleanFromObj(interp, val, &flag) != TCL_OK) {
0297
        ok = 0;
0298
      } else {
0299
        w->web->loader.addHeaderTrailer = flag;
0300
      }
0301
      break;
0302
0303
    case WT_SERVER_INCLUDE_HEADER:
0304
      WtSetObj(&w->web->loader.includeHeader, val);
0305
      break;
0306
0307
    case WT_SERVER_INCLUDE_TRAILER:
0308
      WtSetObj(&w->web->loader.includeTrailer, val);
0309
      break;
0310
0311
    case WT_SERVER_SCRIPT_START_STRING:
0312
      WtSetObj(&w->web->loader.scriptStartString, val);
0313
      break;
0314
0315
    case WT_SERVER_SCRIPT_END_STRING:
0316
      WtSetObj(&w->web->loader.scriptEndString, val);
0317
      break;
0318
0319
    case WT_SERVER_INTERPOLATE_TEXT:
0320
      if (Tcl_GetBooleanFromObj(interp, val, &flag) != TCL_OK) {
0321
        ok = 0;
0322
      } else {
0323
        w->web->loader.interpolateText = flag;
0324
      }
0325
      break;
0326
0327
    case WT_SERVER_PAGE_TEXT_HANDLER:
0328
      WtSetObj(&w->web->loader.textHandler, val);
0329
      break;
0330
0331
    case WT_SERVER_PAGE_EXPR_HANDLER:
0332
      WtSetObj(&w->web->loader.exprHandler, val);
0333
      break;
0334
0335
    case WT_SESSION_HANDLER:
0336
      WtSetObj(&w->web->session.handler, val);
0337
      break;
0338
0339
    case WT_SESSION_HANDLER_TYPE:
0340
      WtSetObj(&w->web->session.handlerType, val);
0341
      break;
0342
0343
    case WT_SESSION_COOKIE_NAME:
0344
      WtSetObj(&w->web->session.cookieName, val);
0345
      break;
0346
0347
    case WT_SESSION_MAX_IDLE_TIME:
0348
      if (Tcl_GetIntFromObj(interp, val, &intVal) != TCL_OK) {
0349
        ok = 0;
0350
      } else {
0351
        w->web->session.maxIdleTime = intVal;
0352
      }
0353
      break;
0354
0355
    case WT_SESSION_SWEEP_FREQUENCY:
0356
      if (Tcl_GetDoubleFromObj(interp, val, &dblVal) != TCL_OK) {
0357
        ok = 0;
0358
      } else {
0359
        w->web->session.sweepFrequency = dblVal;
0360
      }
0361
      break;
0362
0363
    case WT_DB_SESSION_HANDLER:
0364
      ds = WtDbSessionRep(w->web->session.dbSession);
0365
      WtSetObj(&ds->dbHandler, val);
0366
      break;
0367
0368
    case WT_DATA_SOURCE_HANDLER:
0369
      WtSetObj(&w->web->dataSourceHandler, val);
0370
      break;
0371
  }
0372
0373
  return ok;
0374
}
0375
0376
int WtDeleteOptionKeys(Tcl_HashTable *optionKeys)
0377
{
0378
  int ok = 1;
0379
  Tcl_HashEntry *ent;
0380
  Tcl_HashSearch search;
0381
0382
  ent = Tcl_FirstHashEntry(optionKeys, &search);
0383
  while (ent) {
0384
    Tcl_DecrRefCount((Tcl_Obj *)Tcl_GetHashValue(ent));
0385
    ent = Tcl_NextHashEntry(&search);
0386
  }
0387
0388
  return ok;
0389
}