// Evaluate - filters and sends records read from opened reader as per select statement to http response writer.
424979
func (s3Select *S3Select) Evaluate(w http.ResponseWriter) {
	getProgressFunc := s3Select.getProgress
	if !s3Select.Progress.Enabled {
		getProgressFunc = nil
	}
	writer := newMessageWriter(w, getProgressFunc)

	var inputRecord sql.Record
	var outputRecord sql.Record
	var err error
	var data []byte
	sendRecord := func() bool {
		if outputRecord == nil {
			return true
		}

		if data, err = s3Select.marshal(outputRecord); err != nil {
			return false
		}

		if len(data) > maxRecordSize {
			writer.FinishWithError("OverMaxRecordSize", "The length of a record in the input or result is greater than maxCharsPerRecord of 1 MB.")
			return false
		}

		if err = writer.SendRecord(data); err != nil {
			// FIXME: log this error.
			err = nil
			return false
		}

		return true
	}

	for {
		if s3Select.statement.LimitReached() {
			if err = writer.Finish(s3Select.getProgress()); err != nil {
				// FIXME: log this error.
				err = nil
			}
			break
		}

		if inputRecord, err = s3Select.recordReader.Read(); err != nil {
			if err != io.EOF {
				break
			}

			if s3Select.statement.IsAggregated() {
				outputRecord = s3Select.outputRecord()
				if err = s3Select.statement.AggregateResult(outputRecord); err != nil {
					break
				}

				if !sendRecord() {
					break
				}
			}

			if err = writer.Finish(s3Select.getProgress()); err != nil {
				// FIXME: log this error.
				err = nil
			}
			break
		}

		if inputRecord, err = s3Select.statement.EvalFrom(s3Select.Input.format, inputRecord); err != nil {
			break
		}

		if s3Select.statement.IsAggregated() {
			if err = s3Select.statement.AggregateRow(inputRecord); err != nil {
				break
			}
		} else {
			outputRecord = s3Select.outputRecord()
			if outputRecord, err = s3Select.statement.Eval(inputRecord, outputRecord); err != nil {
				break
			}

			if !sendRecord() {
				break
			}
		}
	}

	if err != nil {
		_ = writer.FinishWithError("InternalError", err.Error())
	}
}
362326
func EvalParsedInput(input ast.Value) EvalOption {
	return func(e *EvalContext) {
		e.parsedInput = input
		e.hasInput = true
	}
}
858343
func (n *EvalSequence) Filter(fn EvalNodeFilterFunc) {
	for i, node := range n.Nodes {
		n.Nodes[i] = fn(node)
	}
}
1275935
func evaluateDigest(params map[string]string, method string, us UserStore, nonces NonceStore, logger *log.Logger) (int, string, bool) {
	user, userOk := params["username"]
	realm, realmOk := params["realm"]
	nonce, nonceOk := params["nonce"]
	response, responseOk := params["response"]
	cnonce, cnonceOk := params["cnonce"]
	qop, qopOk := params["qop"]
	uri, uriOk := params["uri"]
	nc, ncOk := params["nc"]

	if !(userOk && realmOk && nonceOk && responseOk && uriOk) {
		if logger != nil {
			logger.Printf("required param omitted")
		}
		return http.StatusUnauthorized, "", false
	}

	storedUserRealmPassHash, ok, err := us.Lookup(user, realm)

	if !ok {
		if logger != nil {
			logger.Printf("no such user %v in realm %v", user, realm)
		}
		return http.StatusUnauthorized, "", false
	}
	if err != nil {
		if logger != nil {
			logger.Printf("no user")
		}
		return http.StatusInternalServerError, fmt.Sprintf("Unable to lookup user: %s", err.Error()), false
	}

	n, ok, err := nonces.Lookup(nonce)
	if !ok {
		if logger != nil {
			logger.Printf("no such nonce: %#v not in %#v", nonce, nonces)
		}
		return http.StatusUnauthorized, "", true
	}
	if err != nil {
		return http.StatusInternalServerError, fmt.Sprintf("Error processing nonce: %s", err.Error()), false
	}

	// compute A1
	ha1 := ""

	algorithm, algorithmOk := params["algorithm"]
	if !algorithmOk || algorithm == "MD5" {
		ha1 = storedUserRealmPassHash
	} else if algorithm == "MD5-sess" {
		if !cnonceOk {
			return http.StatusBadRequest, "MD5-sess digest without cnonce", false
		}
		v := md5.Sum([]byte(storedUserRealmPassHash + ":" + nonce + ":" + cnonce))
		ha1 = hex.EncodeToString(v[:])
		// we could store ha1 under nonce+cnonce I suppose, that seems to be the intent
		// of the RFC.
	} else {
		return http.StatusNotImplemented, fmt.Sprintf("Unsupported digest algorithm: %s", algorithm), false
	}

	if len(ha1) != 2*md5.Size {
		return http.StatusInternalServerError, fmt.Sprintf("Invalid digest HA1: len=%d", len(ha1)), false
	}

	// compute A2
	ha2 := ""

	if !qopOk || qop == "auth" {
		h := md5.Sum([]byte(method + ":" + uri))
		ha2 = hex.EncodeToString(h[:])
	} else if qop == "auth-int" {
		// Will need to read body, undo transfer encoding, and stick it back in to Request. Ick.
		// I should also point out that libcurl doesn't support auth-int, so validating is going to be rough. Opera
		// is rumored to be the only major browser to support auth-int, according to the internet in 2014
		return http.StatusNotImplemented, fmt.Sprintf("Unsupported digest qop: %s", qop), false
	} else {
		return http.StatusNotImplemented, fmt.Sprintf("Unsupported digest qop: %s", qop), false
	}

	if len(ha2) != 2*md5.Size {
		return http.StatusInternalServerError, fmt.Sprintf("Invalid digest HA2: len=%d", len(ha2)), false
	}

	calculatedResponse := ""

	if !qopOk {
		mm := md5.New()
		mm.Write([]byte(ha1))
		mm.Write([]byte(":" + nonce + ":"))
		mm.Write([]byte(ha2))
		calculatedResponse = hex.EncodeToString(mm.Sum([]byte{}))
	} else if qop == "auth" || qop == "auth-int" {
		if !ncOk {
			return http.StatusBadRequest, "Digest auth or auth-int is missing nc", false
		}
		ncVal, err := strconv.ParseUint(nc, 16, 32)
		if err != nil {
			return http.StatusBadRequest, "Invalid digest nc", false
		}
		if !n.AcceptCounter(uint(ncVal)) {
			return http.StatusUnauthorized, "Digest nc was not valid", true
		}

		r := ha1 + ":" + nonce + ":" + nc + ":" + cnonce + ":" + qop + ":" + ha2
		rr := md5.Sum([]byte(r))
		calculatedResponse = hex.EncodeToString(rr[:])
	} else {
		return http.StatusNotImplemented, fmt.Sprintf("Unsupported digest qop: %s", qop), false
	}
	if len(calculatedResponse) != 2*md5.Size {
		return http.StatusInternalServerError, fmt.Sprintf("Miscalculated digest response: %#v", calculatedResponse), false
	}

	n.Next()

	// resist timing attacks, at least here. At this one line.
	if subtle.ConstantTimeCompare([]byte(response), []byte(calculatedResponse)) == 1 {
		return http.StatusOK, "", false
	}

	return http.StatusUnauthorized, "", false
}
570780
func (f nullFunc) evaluate(values map[string][]string) bool {
	requestValue, ok := values[http.CanonicalHeaderKey(f.k.Name())]
	if !ok {
		requestValue = values[f.k.Name()]
	}

	if f.value {
		return len(requestValue) == 0
	}

	return len(requestValue) != 0
}
485458
func ResultHandler(w http.ResponseWriter, r *http.Request) {
	var (
		status int
		err    error
	)
	defer func() {
		if nil != err {
			http.Error(w, err.Error(), status)
		}
	}()
	val := r.Context().Value(ctxDBKey)
	if val == nil {
		httpError(w, r, http.StatusInternalServerError,
			fmt.Sprintf("Could not find database handler in request context"))
		return
	}

	db := val.(*pg.DB)

	idStr := r.FormValue("id")

	id, err := strconv.ParseInt(idStr, 10, 64)
	if err != nil {
		httpError(w, r, http.StatusBadRequest,
			fmt.Sprintf("Could not parse provided scan id %q: %v", idStr, err))
		return
	}

	scan, err := db.GetScanByID(id)
	if err != nil {
		httpError(w, r, http.StatusInternalServerError,
			fmt.Sprintf("Failed to retrieve scan id %d from database: %v", id, err))
		return
	}

	if scan.ID == -1 {
		httpError(w, r, http.StatusBadRequest,
			fmt.Sprintf("Failed to find scan id %d in database", id))
		return
	}

	// display the analysis results in alphabetical order of worker name
	sort.Sort(scan.AnalysisResults)

	jsScan, err := json.Marshal(scan)
	if err != nil {
		httpError(w, r, http.StatusInternalServerError,
			fmt.Sprintf("Failed to convert scan data into JSON: %v", err))
		return
	}
	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(http.StatusOK)
	fmt.Fprint(w, string(jsScan))
}
888892
func Evaluate(connInfo connection.Stored) ([]byte, error) {
	protores, err := gradeProtocol(connInfo)
	if err != nil {
		return nil, err
	}
	cipherres, err := gradeCiphers(connInfo)
	if err != nil {
		return nil, err
	}
	keyxres, err := gradeKeyX(connInfo)
	if err != nil {
		return nil, err
	}

	var score float64
	score = float64(protores.Grade)*0.3 + float64(cipherres.Grade)*0.4 + float64(keyxres.Grade)*0.3

	// fmt.Printf("proto : %d , cipher : %d , keyx: %d\n", int(protores.Grade), int(cipherres.Grade), int(keyxres.Grade))

	er := EvaluationResults{Grade: score, LetterGrade: getLetterfromGrade(score)}
	return json.Marshal(&er)
}
145288
func (e *SelectStatement) EvalFrom(format string, input Record) (Record, error) {
	if e.selectAST.From.HasKeypath() {
		if format == "json" {
			objFmt, rawVal := input.Raw()
			if objFmt != SelectFmtJSON {
				return nil, errDataSource(errors.New("unexpected non JSON input"))
			}

			jsonRec := rawVal.(jstream.KVS)
			txedRec, err := jsonpathEval(e.selectAST.From.Table.PathExpr[1:], jsonRec)
			if err != nil {
				return nil, err
			}

			var kvs jstream.KVS
			switch v := txedRec.(type) {
			case jstream.KVS:
				kvs = v
			default:
				kvs = jstream.KVS{jstream.KV{Key: "_1", Value: v}}
			}

			if err = input.Replace(kvs); err != nil {
				return nil, err
			}

			return input, nil
		}
		return nil, errDataSource(errors.New("path not supported"))
	}
	return input, nil
}
1036601
func EvalQuery(q interface{}, src *Col, result *map[int]struct{}) (err error) {
	return evalQuery(q, src, result, true)
}
741443
func (_m *PolicyEvaluator) Evaluate(policyBytes []byte, signatureSet []*common.SignedData) error {
	ret := _m.Called(policyBytes, signatureSet)

	var r0 error
	if rf, ok := ret.Get(0).(func([]byte, []*common.SignedData) error); ok {
		r0 = rf(policyBytes, signatureSet)
	} else {
		r0 = ret.Error(0)
	}

	return r0
}
359413
func evaluate(node ast.Node, ext vmExtMap, tla vmExtMap, nativeFuncs map[string]*NativeFunction,
	maxStack int, importer Importer, stringOutputMode bool) (string, error) {

	i, err := buildInterpreter(ext, nativeFuncs, maxStack, importer)
	if err != nil {
		return "", err
	}

	result, manifestationTrace, err := evaluateAux(i, node, tla)
	if err != nil {
		return "", err
	}

	var buf bytes.Buffer
	if stringOutputMode {
		err = i.manifestString(&buf, manifestationTrace, result)
	} else {
		err = i.manifestAndSerializeJSON(&buf, manifestationTrace, result, true, "")
	}
	if err != nil {
		return "", err
	}
	buf.WriteString("\n")
	return buf.String(), nil
}
870526
func (s *RPCServer) Eval(arg EvalIn, out *EvalOut) error {
	cfg := arg.Cfg
	if cfg == nil {
		cfg = &api.LoadConfig{true, 1, 64, 64, -1}
	}
	v, err := s.debugger.EvalVariableInScope(arg.Scope, arg.Expr, *api.LoadConfigToProc(cfg))
	if err != nil {
		return err
	}
	out.Variable = v
	return nil
}
912650
func Eval(expr string) (result *big.Rat, err error) {
	defer func() {
		if e := recover(); e != nil {
			result = nil
			err = fmt.Errorf("Invalid Expression: %s", expr)
		}
	}()

	tokens := Tokenise(expr)
	postfix := convert2postfix(tokens)
	return evaluatePostfix(postfix)
}
950806
func (c *Constant) EvalReal(ctx sessionctx.Context, _ chunk.Row) (float64, bool, error) {
	if c.DeferredExpr != nil {
		dt, err := c.DeferredExpr.Eval(chunk.Row{})
		if err != nil {
			return 0, true, err
		}
		if dt.IsNull() {
			return 0, true, nil
		}
		val, err := dt.ToFloat64(ctx.GetSessionVars().StmtCtx)
		if err != nil {
			return 0, true, err
		}
		c.Value.SetFloat64(val)
	} else {
		if c.GetType().Tp == mysql.TypeNull || c.Value.IsNull() {
			return 0, true, nil
		}
	}
	if c.GetType().Hybrid() || c.Value.Kind() == types.KindBinaryLiteral || c.Value.Kind() == types.KindString {
		res, err := c.Value.ToFloat64(ctx.GetSessionVars().StmtCtx)
		return res, err != nil, err
	}
	return c.Value.GetFloat64(), false, nil
}
645358
func (c *Client) Eval(script string, numkeys int, keys, args []string) (interface{}, error) {
	a := []interface{}{
		"EVAL",
		script, // escape?
		numkeys,
		strings.Join(keys, " "),
		strings.Join(args, " "),
	}
	v, err := c.execOnFirst(true, a...)
	if err != nil {
		return nil, err
	}
	return v, nil
}
297242
func (r AndRule) Evaluate(headers, query, payload *map[string]interface{}, body *[]byte, remoteAddr string) (bool, error) {
	res := true

	for _, v := range r {
		rv, err := v.Evaluate(headers, query, payload, body, remoteAddr)
		if err != nil {
			return false, err
		}

		res = res && rv
		if !res {
			return res, nil
		}
	}

	return res, nil
}
1146613
func (s *Statement) Evaluate(p *Path, options *PolicyOptions) bool {
	for _, c := range s.Conditions {
		if !c.Evaluate(p, options) {
			return false
		}
	}
	return true
}