// ValidatePostCtx will confirm Post content length is valid.
1895
func (iapi *InsightApi) ValidatePostCtx(next http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		contentLengthString := r.Header.Get("Content-Length")
		contentLength, err := strconv.Atoi(contentLengthString)
		if err != nil {
			writeInsightError(w, "Content-Length Header must be set")
			return
		}
		// Broadcast Tx has the largest possible body.  Cap max content length
		// to iapi.params.MaxTxSize * 2 plus some arbitrary extra for JSON
		// encapsulation.
		maxPayload := (iapi.params.MaxTxSize * 2) + 50
		if contentLength > maxPayload {
			writeInsightError(w, fmt.Sprintf("Maximum Content-Length is %d", maxPayload))
			return
		}
		next.ServeHTTP(w, r)
	})
}
977940
func (s *StepValidateTemplate) validateTemplate() error {
	// Get RegionNo, ZoneNo
	if err := s.getZoneNo(); err != nil {
		return err
	}

	// Validate member_server_image_no and member_server_image_no
	if err := s.validateMemberServerImage(); err != nil {
		return err
	}

	// Validate server_image_product_code
	if err := s.validateServerImageProduct(); err != nil {
		return err
	}

	// Validate server_product_code
	return s.validateServerProductCode()
}
1069721
func GetOffsetCtx(r *http.Request) int {
	offset, ok := r.Context().Value(ctxOffset).(int)
	if !ok {
		apiLog.Warn("offset is not set or is not an int")
		return 0
	}
	return offset
}
389252
func (s *Sender) SendCtx(ctx context.Context, req *http.Request) (resp *http.Response, err error) {
	return s.ExecWithRetry(fmt.Sprintf("%s request to %s", req.Method, req.URL), func() (*http.Response, error) { return ctxhttp.Do(ctx, s.client, req) })
}
1151808
func PaginationCtx(next http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		to, from := r.FormValue("to"), r.FormValue("from")
		if to == "" {
			to = "20"
		}

		if from == "" {
			from = "0"
		}

		offset, err := strconv.Atoi(from)
		if err != nil {
			http.Error(w, "invalid from value", 422)
			return
		}
		count, err := strconv.Atoi(to)
		if err != nil {
			http.Error(w, "invalid to value", 422)
			return
		}

		ctx := context.WithValue(r.Context(), ctxCount, count)
		ctx = context.WithValue(ctx, ctxOffset, offset)
		next.ServeHTTP(w, r.WithContext(ctx))
	})
}
905464
func (ck *TCPCheck) Valid() error {
	if ck.Name == "" {
		return fmt.Errorf("invalid value for `Name`, must contain non-empty string")
	}

	if ck.Hostname == "" {
		return fmt.Errorf("invalid value for `Hostname`, must contain non-empty string")
	}

	if ck.Resolution != 1 && ck.Resolution != 5 && ck.Resolution != 15 &&
		ck.Resolution != 30 && ck.Resolution != 60 {
		return fmt.Errorf("invalid value %v for `Resolution`, allowed values are [1,5,15,30,60]", ck.Resolution)
	}

	if ck.Port < 1 {
		return fmt.Errorf("Invalid value for `Port`.  Must contain an integer >= 1")
	}

	return nil
}
718894
func PostAddrsUtxoCtx(next http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		req := apitypes.InsightAddr{}
		body, err := ioutil.ReadAll(r.Body)
		r.Body.Close()
		if err != nil {
			writeInsightError(w, fmt.Sprintf("error reading JSON message: %v", err))
			return
		}

		err = json.Unmarshal(body, &req)
		if err != nil {
			writeInsightError(w, fmt.Sprintf("Failed to parse request: %v", err))
			return
		}

		// Successful extraction of Body JSON
		ctx := context.WithValue(r.Context(), m.CtxAddress, req.Addrs)

		next.ServeHTTP(w, r.WithContext(ctx))
	})
}
267812
func validatePUBACKBytes(fixedHeader FixedHeader, variableHeader []byte) error {
	// Extract the MQTT Control Packet type.
	ptype, err := fixedHeader.ptype()
	if err != nil {
		return err
	}

	// Check the length of the fixed header.
	if len(fixedHeader) != lenPUBACKFixedHeader {
		return ErrInvalidFixedHeaderLen
	}

	// Check the MQTT Control Packet type.
	if ptype != TypePUBACK {
		return ErrInvalidPacketType
	}

	// Check the reserved bits of the fixed header.
	if fixedHeader[0]<<4 != 0x00 {
		return ErrInvalidFixedHeader
	}

	// Check the Remaining Length of the fixed header.
	if fixedHeader[1] != lenPUBACKVariableHeader {
		return ErrInvalidRemainingLength
	}

	// Check the length of the variable header.
	if len(variableHeader) != lenPUBACKVariableHeader {
		return ErrInvalidVariableHeaderLen
	}

	// Extract the Packet Identifier.
	packetID, _ := decodeUint16(variableHeader)

	// Check the Packet Identifier.
	if packetID == 0 {
		return ErrInvalidPacketID
	}

	return nil
}
1182902
func ErrorCtx(ctx context.Context, err error, data Data) {
	correlationKey := common.GetRequestId(ctx)
	ErrorC(correlationKey, err, data)
}
1247701
func (pb *ProgressBar) Postfix(postfix string) *ProgressBar {
	pb.mu.Lock()
	defer pb.mu.Unlock()
	pb.postfix = postfix
	return pb
}
1113949
func ValidatePostInit() error {
	if option.Config.EnableIPv4 || option.Config.Tunnel != option.TunnelDisabled {
		if ipv4ExternalAddress == nil {
			return fmt.Errorf("External IPv4 node address could not be derived, please configure via --ipv4-node")
		}
	}

	if option.Config.EnableIPv4 {
		if ipv4InternalAddress == nil {
			return fmt.Errorf("BUG: Internal IPv4 node address was not configured")
		}

		if !ipv4AllocRange.Contains(ipv4InternalAddress) {
			return fmt.Errorf("BUG: Internal IPv4 (%s) must be part of cluster prefix (%s)",
				ipv4InternalAddress, ipv4AllocRange)
		}

		ones, _ := ipv4AllocRange.Mask.Size()
		if ipv4ClusterCidrMaskSize > ones {
			return fmt.Errorf("IPv4 per node allocation prefix (%s) must be inside cluster prefix (%s)",
				ipv4AllocRange, GetIPv4ClusterRange())
		}
	}

	return nil
}
1226785
func GetBlockIndexCtx(r *http.Request) int {
	idx, ok := r.Context().Value(ctxBlockIndex).(int)
	if !ok {
		apiLog.Warn("block index not set or is not an int")
		return -1
	}
	return idx
}
651610
func MPathCtx(next http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		pathMStr := chi.URLParam(r, "M")
		M, err := strconv.Atoi(pathMStr)
		if err != nil {
			apiLog.Infof("No/invalid numeric value (uint64): %v", err)
			http.NotFound(w, r)
			return
		}
		ctx := context.WithValue(r.Context(), ctxM, M)
		next.ServeHTTP(w, r.WithContext(ctx))
	})
}
1150893
func ChartTypeCtx(next http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		ctx := context.WithValue(r.Context(), ctxChartType,
			chi.URLParam(r, "charttype"))
		next.ServeHTTP(w, r.WithContext(ctx))
	})
}
718422
func PostTxnsCtx(next http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		req := apitypes.Txns{}
		body, err := ioutil.ReadAll(r.Body)
		r.Body.Close()
		if err != nil {
			apiLog.Debugf("No/invalid txns: %v", err)
			http.Error(w, "error reading JSON message", http.StatusBadRequest)
			return
		}
		err = json.Unmarshal(body, &req)
		if err != nil {
			apiLog.Debugf("failed to unmarshal JSON request to apitypes.Txns: %v", err)
			http.Error(w, "failed to unmarshal JSON request", http.StatusBadRequest)
			return
		}
		// Successful extraction of body JSON
		ctx := context.WithValue(r.Context(), ctxTxns, req.Transactions)

		next.ServeHTTP(w, r.WithContext(ctx))
	})
}
1045002
func validateCommentLength(vars *variable.SessionVars, comment string, maxLen int, err error) (string, error) {
	if len(comment) > maxLen {
		if vars.StrictSQLMode {
			return "", err
		}
		vars.StmtCtx.AppendWarning(err)
		return comment[:maxLen], nil
	}
	return comment, nil
}
651590
func validateContentType(allowed []string, actual string) error {
	debugLog("validating content type for %q against [%s]", actual, strings.Join(allowed, ", "))
	if len(allowed) == 0 {
		return nil
	}
	mt, _, err := mime.ParseMediaType(actual)
	if err != nil {
		return errors.InvalidContentType(actual, allowed)
	}
	if swag.ContainsStringsCI(allowed, mt) {
		return nil
	}
	if swag.ContainsStringsCI(allowed, "*/*") {
		return nil
	}
	parts := strings.Split(actual, "/")
	if len(parts) == 2 && swag.ContainsStringsCI(allowed, parts[0]+"/*") {
		return nil
	}
	return errors.InvalidContentType(actual, allowed)
}