/** * Subtracts to the following value. */ public override Value sub(Value rValue) { if (rValue.isLongConvertible()) { return(LongValue.create(_value - rValue.toLong())); } else { return(DoubleValue.create(_value - rValue.toDouble())); } }
/** * Checks to see if there @is a valid number per JSON Internet Draft. */ private Value decodeNumber(Env env) { int startOffset = _offset; long value = 0; int sign = 1; char ch; // (-)? if ((ch = _str[_offset]) == '-') { sign = -1; _offset++; } if (_len <= _offset) { return(errorReturn(env, "expected 1-9")); } ch = _str[_offset++]; // (0) | ([1-9] [0-9]*) if (ch == '0') { } else if ('1' <= ch && ch <= '9') { value = ch - '0'; while (_offset < _len && '0' <= (ch = _str[_offset]) && ch <= '9') { _offset++; value = 10 * value + ch - '0'; } } bool isDouble = false; // ((decimalPoint) [0-9]+)? if (_offset < _len && (ch = _str[_offset]) == '.') { _offset++; isDouble = true; while (_offset < _len && '0' <= (ch = _str[_offset]) && ch <= '9') { _offset++; } } // ((e | E) (+ | -)? [0-9]+) if (_offset < _len && (ch = _str[_offset]) == 'e' || ch == 'E') { _offset++; isDouble = true; if (_offset < _len && (ch = _str[_offset]) == '+' || ch == '-') { _offset++; } while (_offset < _len && '0' <= (ch = _str[_offset]) && ch <= '9') { _offset++; } /* * if (_offset < _len) * return errorReturn(env, * L.l("expected 0-9 exponent at '{0}'", (char) ch)); */ } if (isDouble) { string strValue = _str.stringSubstring(startOffset, _offset); return(DoubleValue.create(Double.parseDouble(strValue))); } else { return(LongValue.create(sign * value)); } }
/** * Fills the map. */ private void fillMap() { if (_isFilled) { return; } _isFilled = true; for (Map.Entry <Value, Value> entry : _env.getQuercus().getServerEnvMap().entrySet()) { super.put(entry.getKey(), entry.getValue()); } QuercusHttpServletRequest request = _env.getRequest(); bool isUnicode = _env.isUnicodeSemantics(); if (request != null) { super.put(isUnicode ? SERVER_ADDR_VU : SERVER_ADDR_V, _env.createString(request.getLocalAddr())); super.put(isUnicode ? SERVER_NAME_VU : SERVER_NAME_V, _env.createString(request.getServerName())); super.put(isUnicode ? SERVER_PORT_VU : SERVER_PORT_V, LongValue.create(request.getServerPort())); super.put(isUnicode ? REMOTE_HOST_VU : REMOTE_HOST_V, _env.createString(request.getRemoteHost())); super.put(isUnicode ? REMOTE_ADDR_VU : REMOTE_ADDR_V, _env.createString(request.getRemoteAddr())); super.put(isUnicode ? REMOTE_PORT_VU : REMOTE_PORT_V, LongValue.create(request.getRemotePort())); // Drupal's optional activemenu plugin only works on Apache servers! // bug at http://drupal.org/node/221867 super.put(isUnicode ? SERVER_SOFTWARE_VU : SERVER_SOFTWARE_V, _env.createString("Apache PHP Quercus(" + _env.getQuercus().getVersion() + ")")); super.put(isUnicode ? SERVER_PROTOCOL_VU : SERVER_PROTOCOL_V, _env.createString(request.getProtocol())); super.put(isUnicode ? REQUEST_METHOD_VU : REQUEST_METHOD_V, _env.createString(request.getMethod())); string queryString = QuercusRequestAdapter.getPageQueryString(request); string requestURI = QuercusRequestAdapter.getPageURI(request); string servletPath = QuercusRequestAdapter.getPageServletPath(request); string pathInfo = QuercusRequestAdapter.getPagePathInfo(request); string contextPath = QuercusRequestAdapter.getPageContextPath(request); if (queryString != null) { super.put(isUnicode ? QUERY_STRING_VU : QUERY_STRING_V, _env.createString(queryString)); } // XXX: a better way? // getRealPath() returns a native path // need to convert windows paths to resin paths string root = request.getRealPath("/"); if (root == null) { root = _env.getPwd().getFullPath(); } if (root.indexOf('\\') >= 0) { root = root.replace('\\', '/'); root = '/' + root; } super.put(isUnicode ? DOCUMENT_ROOT_VU : DOCUMENT_ROOT_V, _env.createString(root)); super.put(isUnicode ? SCRIPT_NAME_VU : SCRIPT_NAME_V, _env.createString(contextPath + servletPath)); super.put(isUnicode ? SCRIPT_URL_VU : SCRIPT_URL_V, _env.createString(requestURI)); if (queryString != null) { requestURI = requestURI + '?' + queryString; } super.put(isUnicode ? REQUEST_URI_VU : REQUEST_URI_V, _env.createString(requestURI)); super.put(isUnicode ? REQUEST_TIME_VU : REQUEST_TIME_V, LongValue.create(_env.getStartTime() / 1000)); super.put(isUnicode ? REQUEST_TIME_FLOAT_VU : REQUEST_TIME_FLOAT_V, DoubleValue.create(_env.getMicroTime() / 1000000.0)); super.put(isUnicode ? SCRIPT_FILENAME_VU : SCRIPT_FILENAME_V, _env.createString(request.getRealPath(servletPath))); if (pathInfo != null) { super.put(isUnicode ? PATH_INFO_VU : PATH_INFO_V, _env.createString(pathInfo)); super.put(isUnicode ? PATH_TRANSLATED_VU : PATH_TRANSLATED_V, _env.createString(request.getRealPath(pathInfo))); } if (request.isSecure()) { super.put(isUnicode ? HTTPS_VU : HTTPS_V, _env.createString("on")); // #5402 super.put(isUnicode ? HTTP_X_SSL_REQUEST_VU : HTTP_X_SSL_REQUEST_V, _env.createString("on")); } if (pathInfo == null) { super.put(isUnicode ? PHP_SELF_VU : PHP_SELF_V, _env.createString(contextPath + servletPath)); } else { super.put(isUnicode ? PHP_SELF_VU : PHP_SELF_V, _env.createString(contextPath + servletPath + pathInfo)); } // authType @is not set on Tomcat //String authType = request.getAuthType(); string authHeader = request.getHeader("Authorization"); if (authHeader != null) { if (authHeader.indexOf("Basic") == 0) { super.put(isUnicode ? AUTH_TYPE_VU : AUTH_TYPE_V, _env.createString("Basic")); bool userNameIsSet = false; if (request.getRemoteUser() != null) { super.put(isUnicode ? PHP_AUTH_USER_VU : PHP_AUTH_USER_V, _env.createString(request.getRemoteUser())); userNameIsSet = true; } string digest = authHeader.substring("Basic ".length()); string userPass = Base64.decode(digest); int i = userPass.indexOf(':'); if (i > 0) { if (!userNameIsSet) { super.put(isUnicode ? PHP_AUTH_USER_VU : PHP_AUTH_USER_V, _env.createString(userPass.substring(0, i))); } super.put(isUnicode ? PHP_AUTH_PW_VU : PHP_AUTH_PW_V, _env.createString(userPass.substring(i + 1))); } } else if (authHeader.indexOf("Digest") == 0) { super.put(isUnicode ? AUTH_TYPE_VU : AUTH_TYPE_V, _env.createString("Digest")); string digest = authHeader.substring("Digest ".length()); super.put(isUnicode ? PHP_AUTH_DIGEST_VU : PHP_AUTH_DIGEST_V, _env.createString(digest)); } } Enumeration e = request.getHeaderNames(); while (e.hasMoreElements()) { string key = (String)e.nextElement(); string value = request.getHeader(key); if (key.equalsIgnoreCase("Host")) { super.put(isUnicode ? HTTP_HOST_VU : HTTP_HOST_V, _env.createString(value)); } else if (key.equalsIgnoreCase("Content-Length")) { super.put(isUnicode ? CONTENT_LENGTH_VU : CONTENT_LENGTH_V, _env.createString(value)); } else if (key.equalsIgnoreCase("Content-Type")) { super.put(isUnicode ? CONTENT_TYPE_VU : CONTENT_TYPE_V, _env.createString(value)); } else { super.put(convertHttpKey(key), _env.createString(value)); } } } }