示例#1
0
        public virtual int sceUriParse(TPointer parsedUriArea, PspString url, TPointer workArea, TPointer32 workAreaSizeAddr, int workAreaSize)
        {
            if (parsedUriArea.Null || workArea.Null)
            {
                // The required workArea size if maximum the size if the URL + 7 times the null-byte
                // for string termination.
                workAreaSizeAddr.setValue(url.String.Length + 7);
                return(0);
            }

            string urlString = sceHttp.patchUrl(url.String);

            if (!urlString.Equals(url.String))
            {
                Console.WriteLine(string.Format("sceUriParse patched URL '{0}' into '{1}'", url.String, urlString));
            }

            // Parse the URL into URI components
            URI uri;

            try
            {
                uri = new URI(urlString);
            }
            catch (URISyntaxException e)
            {
                Console.WriteLine("parsedUriArea", e);
                return(-1);
            }

            // Parsing of the userInfo in the format "<userName>:<password>"
            string userInfo         = uri.UserInfo;
            string userInfoUserName = userInfo;
            string userInfoPassword = "";

            if (!string.ReferenceEquals(userInfo, null))
            {
                int userInfoColon = userInfo.IndexOf(":", StringComparison.Ordinal);
                if (userInfoColon >= 0)
                {
                    userInfoUserName = userInfo.Substring(0, userInfoColon);
                    userInfoPassword = userInfo.Substring(userInfoColon + 1);
                }
            }

            string query = uri.Query;

            if (!string.ReferenceEquals(query, null) && query.Length > 0)
            {
                query = "?" + query;
            }

            pspParsedUri parsedUri = new pspParsedUri();
            int          offset    = 0;

            if (uri.SchemeSpecificPart != null && uri.SchemeSpecificPart.StartsWith("//"))
            {
                parsedUri.noSlash = 0;
            }
            else
            {
                parsedUri.noSlash = 1;
            }
            // Store the URI components in sequence into workArea
            // and store the respective addresses into the parsedUri structure.
            parsedUri.schemeAddr = workArea.Address + offset;
            offset = addString(workArea, workAreaSize, offset, uri.Scheme);

            parsedUri.userInfoUserNameAddr = workArea.Address + offset;
            offset = addString(workArea, workAreaSize, offset, userInfoUserName);

            parsedUri.userInfoPasswordAddr = workArea.Address + offset;
            offset = addString(workArea, workAreaSize, offset, userInfoPassword);

            parsedUri.hostAddr = workArea.Address + offset;
            offset             = addString(workArea, workAreaSize, offset, uri.Host);

            parsedUri.pathAddr = workArea.Address + offset;
            offset             = addString(workArea, workAreaSize, offset, uri.Path);

            parsedUri.queryAddr = workArea.Address + offset;
            offset = addString(workArea, workAreaSize, offset, query);

            parsedUri.fragmentAddr = workArea.Address + offset;
            offset = addString(workArea, workAreaSize, offset, uri.Fragment);

            if (uri.Port < 0)
            {
                if ("http".Equals(uri.Scheme))
                {
                    parsedUri.port = 80;
                }
                else if ("https".Equals(uri.Scheme))
                {
                    parsedUri.port = 443;
                }
                else
                {
                    parsedUri.port = 0;
                }
            }
            else
            {
                parsedUri.port = uri.Port;
            }

            workAreaSizeAddr.setValue(offset);
            parsedUri.write(parsedUriArea);

            return(0);
        }
示例#2
0
        public virtual int sceUriBuild(TPointer workArea, TPointer32 workAreaSizeAddr, int workAreaSize, TPointer parsedUriAddr, int flags)
        {
            pspParsedUri parsedUri = new pspParsedUri();

            parsedUri.read(parsedUriAddr);

            // Extract the URI components from the parseUri structure
            string scheme           = getUriComponent(parsedUri.schemeAddr, flags, 0x1);
            string userInfoUserName = getUriComponent(parsedUri.userInfoUserNameAddr, flags, 0x10);
            string userInfoPassword = getUriComponent(parsedUri.userInfoPasswordAddr, flags, 0x20);
            string host             = getUriComponent(parsedUri.hostAddr, flags, 0x2);
            string path             = getUriComponent(parsedUri.pathAddr, flags, 0x8);
            string query            = getUriComponent(parsedUri.queryAddr, flags, 0x40);
            string fragment         = getUriComponent(parsedUri.fragmentAddr, flags, 0x80);
            int    port             = (flags & 0x4) != 0 ? parsedUri.port : -1;

            // Build the complete URI
            string uri = "";

            if (!string.ReferenceEquals(scheme, null) && scheme.Length > 0)
            {
                uri += scheme + ":";
            }
            if (parsedUri.noSlash == 0)
            {
                uri += "//";
            }
            if (!string.ReferenceEquals(userInfoUserName, null))
            {
                uri += userInfoUserName;
            }
            if (!string.ReferenceEquals(userInfoPassword, null) && userInfoPassword.Length > 0)
            {
                uri += ":" + userInfoPassword;
            }
            if (!string.ReferenceEquals(host, null))
            {
                uri += host;
            }
            if (port > 0)
            {
                int defaultPort = -1;
                if (parsedUri.schemeAddr != 0)
                {
                    string protocol = Utilities.readStringZ(parsedUri.schemeAddr);
                    defaultPort = Utilities.getDefaultPortForProtocol(protocol);
                }
                if (port > 0 && port != defaultPort)
                {
                    uri += ":" + port;
                }
            }
            if (!string.ReferenceEquals(path, null))
            {
                uri += path;
            }
            if (!string.ReferenceEquals(query, null))
            {
                uri += query;
            }
            if (!string.ReferenceEquals(fragment, null))
            {
                uri += fragment;
            }

            // Return the URI and its size
            if (workArea.NotNull)
            {
                workArea.setStringNZ(workAreaSize, uri);

                //if (log.DebugEnabled)
                {
                    Console.WriteLine(string.Format("sceUriBuild returning '{0}'", uri));
                }
            }
            workAreaSizeAddr.setValue(uri.Length + 1);

            return(0);
        }