void EvalTrim(const void *data, qCtx *ctx, qStr *out, qArgAry *args) { VALID_ARGC("trim", 1, 2); if (args->Count() > 1) { CStr str = (*args)[0]; if (str.IsEmpty()) return; CStr toks = (*args)[1]; if (toks.Length() == 0) out->PutS(str); else if (toks.Length() == 1) out->PutS(str.Trim(*toks)); else { const char *b, *p = str; size_t i = strspn(p,toks); b = p += i; p += str.Length() - 1 - i; while(p >= b && strchr(toks.Data(), *p)) --p; ++p; out->PutS(b, p - b); } } else out->PutS((*args)[0].Trim()); }
CDbCol *qObjODBC::GetEvalCol(qCtx *ctx, qArgAry *args) { CDbCol *col = 0; if (args->Count() > 0) { CStr index = (*args)[0]; index.Trim(); if (!index.IsEmpty()) { if (isdigit(index[0])) { col = myStmt.Column(atoi(index)-1); } else { strlwr(index.GetBuffer()); col = myStmt.Column((const char *)index); } } } return col; }
void EvalSql(const void *data, qCtx *ctx, qStr *out, qArgAry *args) { int errCode = 0; CStr errMsg; VALID_ARGC("sql", 2 ,5); CDbLib *dbLib = GetDbLib(ctx); CDbConn conn; CStr dsn = (*args)[0]; dsn.Trim(); qObjSql *handler; CStr sql = (*args)[1]; sql.Trim(); if (dsn.IsEmpty()) { ctx->Throw(out, 358, "No datasource specified"); return; } try { qObjTSRef ts; #ifdef HAVE_SQLITE3_H if(!strnicmp(dsn,"sqlite:",7)) { const char *p = dsn+7; while (isspace(*p)) ++p; handler = new qObjSqlite(p, ctx); } else #endif // HAVE_SQLITE3_H { ts = dbLib->GetRef(); handler = new qObjODBC(dsn, ctx, data); } qCtxTmp loopCtx(ctx); loopCtx.MapObj(handler, (QOBJMETH) &qObjSql::EvalColName, "column-name"); loopCtx.MapObj(handler, (QOBJMETH) &qObjSql::EvalColName, "col-name"); loopCtx.MapObj(handler, (QOBJMETH) &qObjSql::EvalColType, "column-type"); loopCtx.MapObj(handler, (QOBJMETH) &qObjSql::EvalColType, "col-type"); loopCtx.MapObj(handler, (QOBJMETH) &qObjSql::EvalEnumCol, "enumcolumn","1"); loopCtx.MapObj(handler, (QOBJMETH) &qObjSql::EvalEnumCol, "enumcol","1"); loopCtx.MapObj(handler, (QOBJMETH) &qObjSql::EvalColumn, "column"); loopCtx.MapObj(handler, (QOBJMETH) &qObjSql::EvalCol, "col"); loopCtx.MapObj(handler, (QOBJMETH) &qObjSql::EvalRow, "num-rows"); loopCtx.MapObj(handler, (QOBJMETH) &qObjSql::EvalSkipRows,"skip-rows"); CStr sql = (*args)[1]; sql.Trim(); handler->Execute(&loopCtx, out, sql, args->GetAt(2), args->GetAt(3), args->GetAt(4)); delete handler; } catch(qCtxEx ex) { errCode = ex.GetID(); errMsg = ex.GetMsg(); delete handler; } catch (qCtxExAbort ex) { throw ex; delete handler; } catch (...) { errCode = 303; errMsg = "Unknown SQL Library error."; delete handler; } if (errCode) ctx->Throw(out, errCode, errMsg); }
static int psx_user(request_rec *r) { qEnvApache *renv = NULL; try { qEnvApacheServer *senv = get_psx_srv_env(r); if (!senv) return DECLINED; const char *macro = senv->GetUserMacro(); if (!macro || !*macro) return DECLINED; renv = get_psx_req_env(r); if (!renv) return DECLINED; if (renv->IsAuth == 1) { if (r->main) renv->Free(); return OK; } else if (renv->IsAuth == -1) { return psx_auth_fail(r, renv); } qCtxTmp tmpCtx(renv->GetCtx()); char *user = NULL; const char *pw = NULL; int res=ap_get_basic_auth_pw(r,&pw); if (!res) { #ifdef APACHE2 user = r->user; #else user = r->connection->user; #endif } if (!user) user = ""; tmpCtx.MapObj(user, "username"); if (!pw) pw = ""; tmpCtx.MapObj(pw, "password"); CStr out = tmpCtx.ParseStr(macro); out.Trim(); // ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, AP2STATUS r, "macro: %s, username: %s, password: %s, macro output: %s, macro length: %d, macro char: %x", (const char *) macro, (const char *)user, (const char *)pw, (const char *)out, out.Length(), (unsigned int)*(const char *)out); if (out.IsEmpty()) { renv->IsAuth = -1; return psx_auth_fail(r, renv); } else { if (r->main) renv->Free(); renv->IsAuth = 1; return OK; } } catch (...) { // login code redirected things if (r->status == HTTP_MOVED_TEMPORARILY) { return OK; } if (renv) renv->Free(); smx_log_str(SMXLOGLEVEL_ERROR, "unhandled exception during authentication"); return DECLINED; } }