protected string getPath(QuercusHttpServletRequest req) { // php/8173 string pwd = getQuercus().getPwd().copy(); string servletPath = QuercusRequestAdapter.getPageServletPath(req); if (servletPath.startsWith("/")) { servletPath = servletPath.substring(1); } string path = pwd.lookupChild(servletPath); // php/2010, php/2011, php/2012 if (path.isFile()) { return(path); } StringBuilder sb = new StringBuilder(); sb.append(servletPath); string pathInfo = QuercusRequestAdapter.getPagePathInfo(req); if (pathInfo != null) { sb.append(pathInfo); } string scriptPath = sb.ToString(); path = pwd.lookupChild(scriptPath); return(path); /* jetty getRealPath() de-references symlinks, which causes problems with MergePath * // php/8173 * string pwd = getQuercus().getPwd().copy(); * * string scriptPath = QuercusRequestAdapter.getPageServletPath(req); * string pathInfo = QuercusRequestAdapter.getPagePathInfo(req); * * string path = pwd.lookup(req.getRealPath(scriptPath)); * * if (path.isFile()) * return path; * * // XXX: include * * string fullPath; * if (pathInfo != null) * fullPath = scriptPath + pathInfo; * else * fullPath = scriptPath; * * return pwd.lookup(req.getRealPath(fullPath)); */ }
protected string getPath(QuercusHttpServletRequest req) { // copy to clear status cache // XXX: improve caching so we don't need to do this anymore string pwd = _pwd.copy(); StringBuilder sb = new StringBuilder(); string servletPath = QuercusRequestAdapter.getPageServletPath(req); if (servletPath.startsWith("/")) { sb.append(servletPath, 1, servletPath.length()); } else { sb.append(servletPath); } string pathInfo = QuercusRequestAdapter.getPagePathInfo(req); if (pathInfo != null) { sb.append(pathInfo); } string scriptPath = sb.ToString(); string path = pwd.lookupChild(scriptPath); return(path); }
public override QuercusDotNet.Env.Env createEnv(QuercusPage page, WriteStream @out, QuercusHttpServletRequest request, QuercusHttpServletResponse response) { return(new CliEnv(this, page, @out, getArgv())); }
public override Env createEnv(QuercusPage page, WriteStream @out, QuercusHttpServletRequest request, QuercusHttpServletResponse response) { return(new CgiEnv(this, page, @out, request, response)); }
public GoogleEnv(QuercusContext quercus, QuercusPage page, WriteStream @out, QuercusHttpServletRequest request, QuercusHttpServletResponse response) { super(quercus, page, @out, request, response); }
public static string getPageContextPath(QuercusHttpServletRequest request) { string contextPath = request.getIncludeContextPath(); if (contextPath != null) { return(contextPath); } else { return(request.getContextPath()); } }
/** * Returns the path-info for the current page, i.e. this will return the * url of the include page, not the original request. */ public static string getPagePathInfo(QuercusHttpServletRequest request) { string uri = request.getIncludeRequestUri(); if (uri != null) { return(request.getIncludePathInfo()); } else { return(request.getPathInfo()); } }
/** * Returns the servlet-path for the current page, i.e. this will return the * url of the include page, not the original request. */ public static string getPageServletPath(QuercusHttpServletRequest request) { string servletPath = request.getIncludeServletPath(); if (servletPath != null) { return(servletPath); } else { return(request.getServletPath()); } }
static void fillPost(Env env, ArrayValue postArray, ArrayValue files, QuercusHttpServletRequest request, bool addSlashesToValues, bool isAllowUploads) { InputStream @is = null; try { string encoding = request.getCharacterEncoding(); string contentType = request.getHeader("Content-Type"); @is = request.getInputStream(); fillPost(env, postArray, files, @is, contentType, encoding, Integer.MAX_VALUE, addSlashesToValues, isAllowUploads); if (postArray.getSize() == 0) { // needs to be last or else this function will consume the inputstream putRequestMap(env, postArray, files, request, addSlashesToValues, isAllowUploads); } } catch (IOException e) { env.warning(e); } finally { try { if (@is != null) { @is.close(); } } catch (IOException e) { } } }
/** * Returns all the request headers */ public Value apache_request_headers(Env env) { QuercusHttpServletRequest req = env.getRequest(); ArrayValue result = new ArrayValueImpl(); Enumeration e = req.getHeaderNames(); while (e.hasMoreElements()) { string key = (String)e.nextElement(); result.put(env.createString(key), env.createString(req.getHeader(key))); } return(result); }
/* * private void fillCookie(ArrayValue cookies, CharSegment rawCookie) * { * char []buf = rawCookie.getBuffer(); * int j = rawCookie.getOffset(); * int end = j + rawCookie.length(); * * CharBuffer cbName = new CharBuffer(); * CharBuffer cbValue = new CharBuffer(); * * while (j < end) { * char ch = 0; * * cbName.clear(); * cbValue.clear(); * * for (; * j < end && ((ch = buf[j]) == ' ' || ch == ';' || ch ==','); * j++) { * } * * if (end <= j) * break; * * bool isSpecial = false; * if (buf[j] == '$') { * isSpecial = true; * j++; * } * * for (; j < end; j++) { * ch = buf[j]; * if (ch < 128 && TOKEN[ch]) * cbName.append(ch); * else * break; * } * * for (; j < end && (ch = buf[j]) == ' '; j++) { * } * * if (end <= j) * break; * else if (ch == ';' || ch == ',') { * cookies.append(createString(cbName.ToString()), getEmptyString()); * continue; * } * else if (ch != '=') { * for (; j < end && (ch = buf[j]) != ';'; j++) { * } * continue; * } * * j++; * * for (; j < end && (ch = buf[j]) == ' '; j++) { * } * * if (ch == '"') { * for (j++; j < end; j++) { * ch = buf[j]; * if (ch == '"') * break; * cbValue.append(ch); * } * j++; * } * else { * for (; j < end; j++) { * ch = buf[j]; * if (ch < 128 && VALUE[ch]) * cbValue.append(ch); * else * break; * } * } * * if (! isSpecial) { * if (cbName.length() == 0) { * //log.warning("bad cookie: " + rawCookie); * } * else { * cookies.append(createString(cbName.ToString()), * createString(cbValue.ToString())); * } * } * } * } */ protected override void fillPost(ArrayValue postArray, ArrayValue files, QuercusHttpServletRequest request, bool isMagicQuotes) { InputStream @is = System.in; Value serverEnv = getGlobalValue("_SERVER"); string method = serverEnv.get(createString("REQUEST_METHOD")).ToString(); string contentType = serverEnv.get(createString("CONTENT_TYPE")).ToString(); int contentLength = Integer.MAX_VALUE; Value contentLengthV = serverEnv.get(createString("CONTENT_LENGTH")); if (contentLengthV.isset()) { contentLength = contentLengthV.toInt(); } if (method.equals("POST")) { Post.fillPost(this, postArray, files, @is, contentType, null, contentLength, isMagicQuotes, getIniBoolean("file_uploads")); } else if (!method.equals("GET")) { StringValue bb = createBinaryBuilder(); //bb.appendReadAll(@is, contentLength); setInputData(bb); } }
/** * Returns the query-string for the current page, i.e. this will return the * url of the include page, not the original request. */ public static string getPageQueryString(QuercusHttpServletRequest request) { string uri = request.getIncludeRequestUri(); if (uri != null) { return(request.getIncludeQueryString()); } else { /* * // php/0829 * uri = (String) request.getAttribute(FWD_REQUEST_URI); * * if (uri != null) * return (String) request.getAttribute(FWD_QUERY_STRING); * else * return request.getQueryString(); */ return(request.getQueryString()); } }
public static string getPageURI(QuercusHttpServletRequest request) { string uri = request.getIncludeRequestUri(); if (uri != null) { return(uri); } else { // php/0829 uri = request.getForwardRequestUri(); if (uri != null) { return(uri); } else { return(request.getRequestURI()); } } }
public override void include(QuercusHttpServletRequest request, QuercusHttpServletResponse response) { HttpServletRequest req = request.toRequest(HttpServletRequest.class);
public static Object get_servlet_request(Env env) { QuercusHttpServletRequest request = env.getRequest(); return(request.toRequest(Object.class));
/** * 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)); } } } }
private static void putRequestMap(Env env, ArrayValue post, ArrayValue files, QuercusHttpServletRequest request, bool addSlashesToValues, bool isAllowUploads) { // this call consumes the inputstream Map <String, String[]> map = request.getParameterMap(); if (map == null) { return; } long maxFileSize = Long.MAX_VALUE; Value maxFileSizeV = post.get(env.createString("MAX_FILE_SIZE")); if (maxFileSizeV.isNull()) { maxFileSize = maxFileSizeV.toLong(); } if (isAllowUploads) { for (Map.Entry <String, String[]> entry : map.entrySet()) { string key = entry.getKey(); int len = key.length(); if (len < 10 || !key.endsWith(".filename")) { continue; } string name = key.substring(0, len - 9); string [] fileNames = request.getParameterValues(name + ".filename"); string [] tmpNames = request.getParameterValues(name + ".file"); string [] mimeTypes = request.getParameterValues(name + ".content-type"); for (int i = 0; i < fileNames.length; i++) { long fileLength = new FilePath(tmpNames[i]).getLength(); addFormFile(env, files, name, fileNames[i], tmpNames[i], mimeTypes[i], fileLength, addSlashesToValues, maxFileSize); } } } ArrayList <String> keys = new ArrayList <String>(); keys.addAll(request.getParameterMap().keySet()); Collections.sort(keys); for (String key : keys) { string [] value = request.getParameterValues(key); Post.addFormValue(env, post, key, value, addSlashesToValues, true); } }