private bool ParseRequestLine() { // throw new NotImplementedException(); String[] FLine = requestLines[0].Split(' '); if (FLine.Length < 3) { return(false); } method = (RequestMethod)Enum.Parse(typeof(RequestMethod), FLine[0]); relativeURI = FLine[1].Substring(1); if (FLine[2] == "HTTP/1.0") { httpVersion = HTTPVersion.HTTP10; } else if (FLine[2] == "HTTP/1.1") { httpVersion = HTTPVersion.HTTP11; } else { httpVersion = HTTPVersion.HTTP09; } if (!ValidateIsURI(relativeURI)) { return(false); } return(true); }
private bool ParseRequestLine(string RequestLine) { //throw new NotImplementedException(); string[] words = RequestLine.Split(' '); if (words[0].ToLower() == "get") { method = RequestMethod.GET; } else if (words[0].ToLower() == "head") { method = RequestMethod.HEAD; } else { method = RequestMethod.POST; } relativeURI = words[1]; if (!ValidateIsURI(relativeURI)) { return(false); } if (words[2].ToLower() == "http/1.0") { httpVersion = HTTPVersion.HTTP10; } else if (words[2].ToLower() == "http/1.1") { httpVersion = HTTPVersion.HTTP11; } else { httpVersion = HTTPVersion.HTTP09; } return(true); }
private bool SetHTTPVer(string httpString) { string[] http = httpString.Split('/'); if (http[0] != "HTTP") { return(false); } else if (http.Length == 1) { httpVersion = HTTPVersion.HTTP09; return(false); } else { switch (http[1]) { case "1.0": httpVersion = HTTPVersion.HTTP10; return(false); case "1.1": httpVersion = HTTPVersion.HTTP11; break; default: return(false); } } return(true); }
protected void HandleNotifyRequest(SimpleHTTPRequest header, EndpointConfiguration config, IPEndPoint remoteEndPoint) { if (header.Param != "*") { // Invalid message return; } HTTPVersion httpVersion; if (!HTTPVersion.TryParse(header.HttpVersion, out httpVersion)) { // Invalid message return; } // HOST not interesting //string host = header["HOST"]; string cacheControl = header["CACHE-CONTROL"]; string location = header["LOCATION"]; string server = header["SERVER"]; // NT is not evaluated, we get all information from the USN header //string nt = header["NT"]; string nts = header["NTS"]; string usn = header["USN"]; string bi = header["BOOTID.UPNP.ORG"]; string ci = header["CONFIGID.UPNP.ORG"]; string sp = header["SEARCHPORT.UPNP.ORG"]; HandleNotifyPacket(config, remoteEndPoint, httpVersion, DateTime.Now.ToUniversalTime().ToString("R"), cacheControl, location, server, nts, usn, bi, ci, sp); }
private bool ParseRequestLine() { string[] lines = this.requestLines[0].Split(' '); if (lines.Length < 3) { return(false); } this.method = (RequestMethod)Enum.Parse(typeof(RequestMethod), lines[0]); this.relativeURI = lines[1].Substring(1); switch (lines[2]) { case "HTTP/0.9": this.httpVersion = HTTPVersion.HTTP09; break; case "HTTP/1.0": this.httpVersion = HTTPVersion.HTTP10; break; case "HTTP/1.1": this.httpVersion = HTTPVersion.HTTP11; break; } if (!ValidateIsURI(relativeURI)) { return(false); } return(true); }
/// <summary> /// Creates a new link configuration for the communication with a UPnP device. /// </summary> /// <param name="endpoint">UPnP endpoint where the advertisement was received.</param> /// <param name="descriptionLocation">Location of the description document for this link.</param> /// <param name="httpVersion">HTTP version our partner is using.</param> /// <param name="searchPort">Search port used in the new link.</param> public LinkData(EndpointConfiguration endpoint, string descriptionLocation, HTTPVersion httpVersion, int searchPort) { _endpoint = endpoint; _descriptionLocation = descriptionLocation; _descriptionServer = new Uri(_descriptionLocation).Host; _httpVersion = httpVersion; _searchPort = searchPort; }
//done private bool ParseRequestLine() { //throw new NotImplementedException(); requestLines = contentLines[0].Split(' '); if (requestLines.Length != 3) { return(false); } //Method if (requestLines[0] == RequestMethod.GET.ToString()) { method = RequestMethod.GET; } else if (requestLines[0] == RequestMethod.HEAD.ToString()) { method = RequestMethod.HEAD; Console.WriteLine(method.ToString()); } else if (requestLines[0] == RequestMethod.POST.ToString()) { method = RequestMethod.POST; } else { return(false); } //HTTP version //if (requestLines[2] != HTTPVersion.HTTP09.ToString() && requestLines[2] != HTTPVersion.HTTP10.ToString() && requestLines[2] != HTTPVersion.HTTP11.ToString()) // return false; if (requestLines[2] == "HTTP/0.9") { httpVersion = HTTPVersion.HTTP09; } else if (requestLines[2] == "HTTP/1.0") { httpVersion = HTTPVersion.HTTP10; } else if (requestLines[2] == "HTTP/1.1") { httpVersion = HTTPVersion.HTTP11; } else { return(false); } //URI if (ValidateIsURI(requestLines[1])) { relativeURI = requestLines[1]; } else { return(false); } return(true); }
private bool ParseRequestLine() { //throw new NotImplementedException(); string [] req_line; string[] uri; req_line = splitRequestString[0].Split(' '); if (req_line[0].ToLower() == "get") { this.method = RequestMethod.GET; } else if (req_line[0].ToLower() == "head") { this.method = RequestMethod.HEAD; } else if (req_line[0].ToLower() == "post") { this.method = RequestMethod.POST; } else { return(false); } uri = req_line[1].Split('/'); this.relativeURI = uri[1]; if (ValidateIsURI(req_line[1]) != true) { return(false); } if (req_line[2].ToLower() == "http/0.9") { this.httpVersion = HTTPVersion.HTTP09; } else if (req_line[2].ToLower() == "http/1.0") { this.httpVersion = HTTPVersion.HTTP10; } else if (req_line[2].ToLower() == "http/1.1") { this.httpVersion = HTTPVersion.HTTP11; } else { return(false); } return(true); }
private bool ParseRequestLine() // Done { this.contentLines = this.requestString.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); if (this.contentLines.Length < 4) { return(false); } else { this.requestLines = this.contentLines[0].Split(' '); if (this.requestLines.Length != 3) { return(false); } switch (this.requestLines[0]) { case "GET": method = RequestMethod.GET; break; case "POST": method = RequestMethod.POST; break; default: method = RequestMethod.HEAD; break; } if (!this.ValidateIsURI(this.requestLines[1])) { return(false); } this.relativeURI = this.requestLines[1].Remove(0, 1); switch (this.requestLines[2]) { case "HTTP/1.1": this.httpVersion = HTTPVersion.HTTP11; break; case "HTTP/1.0": this.httpVersion = HTTPVersion.HTTP10; break; default: this.httpVersion = HTTPVersion.HTTP09; break; } } return(true); }
private bool ParseRequestLine() { //throw new NotImplementedException(); if (requestLines[0] == "GET") { method = RequestMethod.GET; } else if (requestLines[0] == "HEAD") { method = RequestMethod.HEAD; } else if (requestLines[0] == "POST") { method = RequestMethod.POST; } else { return(false); } bool valid_URI = ValidateIsURI(requestLines[1]); if (valid_URI == false) { return(false); } else { relativeURI = requestLines[1]; } if (requestLines[2] == "HTTP/1.0") { httpVersion = HTTPVersion.HTTP10; } else if (requestLines[2] == "HTTP/1.1") { httpVersion = HTTPVersion.HTTP11; } else if (requestLines[2] == "HTTP/0.9" || requestLines[2] == "HTTP") { httpVersion = HTTPVersion.HTTP09; } else { return(false); } return(true); }
private bool ParseRequestLine() { if (requestLines.Length != 3) { return(false); } if (requestLines[0] == "GET") { method = RequestMethod.GET; } else if (requestLines[0] == "POST") { method = RequestMethod.POST; } else if (requestLines[0] == "HEAD") { method = RequestMethod.HEAD; } else { return(false); } if (requestLines[2] == " HTTP/1.0") { httpVersion = HTTPVersion.HTTP10; } else if (requestLines[2] == "HTTP/1.1") { httpVersion = HTTPVersion.HTTP11; } else if (requestLines[2] == "HTTP/0.9") { httpVersion = HTTPVersion.HTTP09; } else { return(false); } //if (ValidateIsURI(relativeURI) == false) if (ValidateIsURI(requestLines[1]) == false) { return(false); } else { relativeURI = requestLines[1]; } return(true); }
/// <summary> /// Adds a physical link to the device of this root entry. /// </summary> /// <param name="endpoint">Local endpoint to be used for this link.</param> /// <param name="descriptionLocation">Location to retrieve the description from for this link.</param> /// <param name="httpVersion">HTTP version to use to retrieve the description for this link.</param> /// <param name="searchPort">Search port to use for search queries at the device for this link.</param> /// <returns>Created <see cref="LinkData"/> instance.</returns> internal LinkData AddOrUpdateLink(EndpointConfiguration endpoint, string descriptionLocation, HTTPVersion httpVersion, int searchPort) { LinkData result; if (!_linkConfigurations.TryGetValue(descriptionLocation, out result)) { _linkConfigurations.Add(descriptionLocation, result = new LinkData(endpoint, descriptionLocation, httpVersion, searchPort)); } if (_preferredLink == null || result.IsNearer(_preferredLink)) { _preferredLink = result; } return(result); }
// Esraa private bool ParseRequestLine() { string[] requestLine_parts = requestLines[0].Split(' '); if (requestLine_parts[0] == "GET") { method = RequestMethod.GET; } else if (requestLine_parts[0] == "POST") { method = RequestMethod.POST; } else if (requestLine_parts[0] == "HEAD") { method = RequestMethod.HEAD; } else { return(false); } if (ValidateIsURI(requestLine_parts[1])) { relativeURI = requestLine_parts[1].Split('/')[1]; } else { return(false); } if (requestLine_parts[2] == "HTTP/0.9") { httpVersion = HTTPVersion.HTTP09; } else if (requestLine_parts[2] == "HTTP/1.0") { httpVersion = HTTPVersion.HTTP10; } else if (requestLine_parts[2] == "HTTP/1.1") { httpVersion = HTTPVersion.HTTP11; } else { return(false); } return(true); }
private bool ParseRequestLine() { //throw new NotImplementedException(); string[] requestLine = requestLines[0].Split(' '); bool setMethod = Enum.TryParse(requestLine[0], out method); if (!setMethod) { return(false); } bool testURI = ValidateIsURI(requestLine[1]); if (!testURI) { return(false); } relativeURI = requestLine[1]; //requestLine[2] = requestLine[2].Remove(requestLine[2].Length - 1, 2); //bool setVersion = Enum.TryParse(requestLine[2], out httpVersion); if (requestLine[2].Contains("HTTP/1.1")) { httpVersion = HTTPVersion.HTTP11; } else if (requestLine[2].Contains("HTTP/1.0")) { httpVersion = HTTPVersion.HTTP10; } else if (requestLine[2].Contains("HTTP/0.9")) { httpVersion = HTTPVersion.HTTP09; } else { return(false); } return(true); }
private bool ParseRequestLine() { string[] req_line = requestLines[0].Split(' '); if (req_line[0] == "GET") { method = RequestMethod.GET; } else if (req_line[0] == "POST") { method = RequestMethod.POST; } else if (req_line[0] == "HEAD") { method = RequestMethod.HEAD; } else { return(false); } if (!ValidateIsURI(req_line[1])) { return(false); } relativeURI = req_line[1]; string[] http_version = req_line[2].Split('/'); if (http_version[1] == "1.0") { httpVersion = HTTPVersion.HTTP10; } else if (http_version[1] == "1.1") { httpVersion = HTTPVersion.HTTP11; } else { httpVersion = HTTPVersion.HTTP09; } return(true); }
private bool ParseRequestLine() { // throw new NotImplementedException(); string[] requestLineTokens = requestLines[0].Split(' '); method = (RequestMethod)Enum.Parse(typeof(RequestMethod), requestLineTokens[0]); relativeURI = requestLineTokens[1]; if (requestLineTokens[2].Equals("HTTP/1.0")) //SlaamComment HTTP 0.9 { httpVersion = HTTPVersion.HTTP10; } else if (requestLineTokens[2].Equals("HTTP/1.1")) { httpVersion = HTTPVersion.HTTP11; } else if (requestLineTokens[2].Equals("HTTP/0.9") || requestLineTokens.Contains("HTTP")) { httpVersion = HTTPVersion.HTTP09; } return(method == RequestMethod.GET); }
private bool ParseRequestLine() { //throw new NotImplementedException(); string[] method = request_lines[0].Split(' '); if (method[2] == "HTTP/1.1") { this.httpVersion = HTTPVersion.HTTP11; } else if (method[2] == "HTTP/1.0") { this.httpVersion = HTTPVersion.HTTP10; } else if (method[2] == "HTTP/0.9") { this.httpVersion = HTTPVersion.HTTP09; } if (method[0] == "GET") { this.method = RequestMethod.GET; } else if (method[0] == "POST") { this.method = RequestMethod.POST; } else if (method[0] == "HEAD") { this.method = RequestMethod.HEAD; } else { return(false); } this.relativeURI = method[1].Remove(0, 1); return(ValidateIsURI(this.relativeURI)); }
private bool ParseRequestLine() { try { if (requestLines[0] == "GET") { method = RequestMethod.GET; } else if (requestLines[0] == "HEAD") { method = RequestMethod.HEAD; } else if (requestLines[0] == "POST") { method = RequestMethod.POST; } relativeURI = requestLines[1].Trim('/'); if (requestLines[2] == "HTTP/0.9") { httpVersion = HTTPVersion.HTTP09; } if (requestLines[2] == "HTTP/1.0") { httpVersion = HTTPVersion.HTTP10; } if (requestLines[2] == "HTTP/1.1") { httpVersion = HTTPVersion.HTTP11; } } catch { return(false); } return(true); }
private bool ParseRequestLine() { try { string[] parts = this.requestLines[0].Split(' '); /*================= METHOD =================*/ this.method = (parts[0].ToUpper() == "GET") ? RequestMethod.GET : (parts[0].ToUpper() == "POST") ? RequestMethod.POST : RequestMethod.HEAD; /*================= URI ==================*/ this.relativeURI = (this.ValidateIsURI(parts[1])) ? parts[1] : "/"; /*================= HTTP VER ===============*/ this.httpVersion = (parts[2] == "HTTP/1.0") ? HTTPVersion.HTTP10 : (parts[2] == "HTTP/1.1") ? HTTPVersion.HTTP11 : HTTPVersion.HTTP09; } catch (Exception ex) { Console.WriteLine("Error while parsing request line please check the log file."); Logger.LogException(ex); return(false); } return(true); }
protected void HandleSSDPResponse(SimpleHTTPResponse header, EndpointConfiguration config, IPEndPoint remoteEndPoint) { HTTPVersion httpVersion; if (!HTTPVersion.TryParse(header.HttpVersion, out httpVersion)) { // Invalid response return; } string cacheControl = header["CACHE-CONTROL"]; string date = header["DATE"]; // EXT is not used //string ext = header["EXT"]; string location = header["LOCATION"]; string server = header["SERVER"]; // ST is not used //string st = header["ST"]; string usn = header["USN"]; string bi = header["BOOTID.UPNP.ORG"]; string ci = header["CONFIGID.UPNP.ORG"]; string sp = header["SEARCHPORT.UPNP.ORG"]; HandleNotifyPacket(config, remoteEndPoint, httpVersion, date, cacheControl, location, server, "ssdp:alive", usn, bi, ci, sp); }
private bool ParseRequestLine() { // throw new NotImplementedException(); string[] reqline = this.requestLines[0].Split(' '); //// check single space between parameters int len = reqline.Length; if (len < 3) //Check at least request line and host header and blank lines exist. { return(false); } this.relativeURI = reqline[1].Substring(1); /// get Relative url switch (reqline[2]) // check httpVersion { case "HTTP/0.9": this.httpVersion = HTTPVersion.HTTP09; break; case "HTTP/1.0": this.httpVersion = HTTPVersion.HTTP10; break; case "HTTP/1.1": this.httpVersion = HTTPVersion.HTTP11; break; } if (!ValidateIsURI(relativeURI)) // Validate Url { return(false); } return(true); }
protected void HandleUpdatePacket(SimpleHTTPRequest header, EndpointConfiguration config) { if (header.Param != "*") { // Invalid message return; } HTTPVersion httpVersion; if (!HTTPVersion.TryParse(header.HttpVersion, out httpVersion)) { // Invalid message return; } // Host, NT, NTS, USN are not interesting //string host = header["HOST"]; //string nt = header["NT"]; //string nts = header["NTS"]; string usn = header["USN"]; //string location = header["LOCATION"]; string bi = header["BOOTID.UPNP.ORG"]; uint bootID; if (!uint.TryParse(bi, out bootID)) { // Invalid message return; } string nbi = header["NEXTBOOTID.UPNP.ORG"]; uint nextBootID; if (!uint.TryParse(nbi, out nextBootID)) { // Invalid message return; } if (!usn.StartsWith("uuid:")) { // Invalid usn return; } int separatorIndex = usn.IndexOf("::"); if (separatorIndex < 6) // separatorIndex == -1 or separatorIndex not after "uuid:" prefix with at least one char UUID // We only use messages containing a "::" substring and discard the "uuid:device-UUID" message { return; } string deviceUUID = usn.Substring(5, separatorIndex - 5); RootEntry rootEntry = GetRootEntryByContainedDeviceUUID(deviceUUID); if (rootEntry == null) { return; } if (rootEntry.BootID > bootID) { // Invalid message return; } bool fireDeviceRebooted = false; lock (_cpData.SyncObj) { if (rootEntry.BootID < bootID) { // Device reboot fireDeviceRebooted = true; } rootEntry.BootID = nextBootID; } if (fireDeviceRebooted) { InvokeDeviceRebooted(rootEntry, false); } }
protected void HandleNotifyPacket(EndpointConfiguration config, IPEndPoint remoteEndPoint, HTTPVersion httpVersion, string date, string cacheControl, string location, string server, string nts, string usn, string bi, string ci, string sp) { uint bootID = 0; if (bi != null && !uint.TryParse(bi, out bootID)) { // Invalid message return; } uint configID = 0; if (ci != null && !uint.TryParse(ci, out configID)) { // Invalid message return; } if (!usn.StartsWith("uuid:")) { // Invalid usn return; } string deviceUUID; string messageType; if (!ParserHelper.TryParseUSN(usn, out deviceUUID, out messageType)) { // We only use messages of the type "uuid:device-UUID::..." and discard the "uuid:device-UUID" message return; } if (nts == "ssdp:alive") { if (server == null) { // Invalid message return; } int maxAge; if (!TryParseMaxAge(cacheControl, out maxAge)) { // Invalid message return; } DateTime d; if (!DateTime.TryParse(date, out d)) { d = DateTime.Now; } DateTime expirationTime = d.AddSeconds(maxAge); // The specification says the SERVER header should contain three entries, separated by space, like // "SERVER: OS/version UPnP/1.1 product/version". // Unfortunately, some clients send entries separated by ", ", like "Linux/2.x.x, UPnP/1.0, pvConnect UPnP SDK/1.0". // We try to handle all situations correctly here, that's the reason for this ugly code. // What we've seen until now: // SERVER: Linux/2.x.x, UPnP/1.0, pvConnect UPnP SDK/1.0 => tokens separated by ',' // SERVER: Windows 2003, UPnP/1.0 DLNADOC/1.50, Serviio/0.5.2 => tokens separated by ',' and additional info in UPnP version token // SERVER: 3Com-ADSL-11g/1.0 UPnP/1.0 => only two tokens string[] versionInfos = server.Contains(", ") ? server.Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries) : server.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); string upnpVersionInfo = versionInfos.FirstOrDefault(v => v.StartsWith(UPnPVersion.VERSION_PREFIX)); if (upnpVersionInfo == null) { // Invalid message return; } // upnpVersionInfo = 'UPnP/1.0', 'UPnP/1.1', 'UPnP/1.0 DLNADOC/1.50', ..., the UPnP version is always the first token string[] upnpVersionInfoTokens = upnpVersionInfo.Split(' '); string upnpVersionInfoToken = upnpVersionInfoTokens[0]; UPnPVersion upnpVersion; if (!UPnPVersion.TryParse(upnpVersionInfoToken, out upnpVersion)) { // Invalid message return; } if (upnpVersion.VerMax != 1) { // Incompatible UPnP version return; } int searchPort = 1900; if (upnpVersion.VerMin >= 1) { if (bi == null || ci == null) { // Invalid message return; } if (sp != null && (!int.TryParse(sp, out searchPort) || searchPort < 49152 || searchPort > 65535)) { // Invalid message return; } } RootEntry rootEntry; DeviceEntry deviceEntry = null; string serviceType = null; bool fireDeviceRebooted = false; bool fireConfigurationChanged = false; bool fireRootDeviceAdded = false; bool fireDeviceAdded = false; bool fireServiceAdded = false; lock (_cpData.SyncObj) { bool rootEntryAdded; // Use fail-safe code, see comment above about the different SERVER headers string osVersion = versionInfos.Length < 1 ? string.Empty : versionInfos[0]; string productVersion = versionInfos.Length < 3 ? string.Empty : versionInfos[2]; rootEntry = GetOrCreateRootEntry(deviceUUID, location, upnpVersion, osVersion, productVersion, expirationTime, config, httpVersion, searchPort, out rootEntryAdded); if (bi != null && rootEntry.BootID > bootID) { // Invalid message return; } uint currentConfigId = rootEntry.GetConfigID(remoteEndPoint); if (currentConfigId != 0 && currentConfigId != configID) { fireConfigurationChanged = true; } rootEntry.SetConfigID(remoteEndPoint, configID); if (!rootEntryAdded && bi != null && rootEntry.BootID < bootID) { // Device reboot // A device, which has rebooted, has lost all its links, so we must forget about the old link registrations and wait for new registrations in alive messages rootEntry.ClearLinks(); fireDeviceRebooted = true; } // Don't add the link before a reboot was detected and thus, rootEntry.ClearLinks() was called rootEntry.AddOrUpdateLink(config, location, httpVersion, searchPort); rootEntry.BootID = bootID; if (messageType == "upnp:rootdevice") { rootEntry.GetOrCreateDeviceEntry(deviceUUID); object value; if (!rootEntry.ClientProperties.TryGetValue("RootDeviceSetUp", out value)) { rootEntry = MergeOrMoveRootEntry(rootEntry, deviceUUID); fireRootDeviceAdded = true; rootEntry.ClientProperties["RootDeviceSetUp"] = true; } } else if (messageType.StartsWith("urn:")) { if (messageType.IndexOf(":device:") > -1) { string deviceType; int deviceTypeVersion; if (!ParserHelper.TryParseTypeVersion_URN(messageType, out deviceType, out deviceTypeVersion)) { // Invalid message return; } deviceEntry = rootEntry.GetOrCreateDeviceEntry(deviceUUID); fireDeviceAdded = string.IsNullOrEmpty(deviceEntry.DeviceType); deviceEntry.DeviceType = deviceType; deviceEntry.DeviceTypeVersion = deviceTypeVersion; } else if (messageType.IndexOf(":service:") > -1) { deviceEntry = rootEntry.GetOrCreateDeviceEntry(deviceUUID); serviceType = messageType; if (deviceEntry.Services.Contains(serviceType)) { return; } deviceEntry.Services.Add(serviceType); fireServiceAdded = true; } } else { // Invalid message return; } } // Raise events after returning the lock if (fireDeviceRebooted) { InvokeDeviceRebooted(rootEntry, fireConfigurationChanged); } else if (fireConfigurationChanged) { InvokeDeviceConfigurationChanged(rootEntry); } if (fireRootDeviceAdded) { InvokeRootDeviceAdded(rootEntry); } if (fireDeviceAdded) { InvokeDeviceAdded(rootEntry, deviceEntry); } if (fireServiceAdded) { InvokeServiceAdded(rootEntry, deviceEntry, serviceType); } } else if (nts == "ssdp:byebye") { RootEntry rootEntry = GetRootEntryByContainedDeviceUUID(deviceUUID); if (rootEntry != null) { if (bi != null && rootEntry.BootID > bootID) { // Invalid message return; } RemoveRootEntry(rootEntry); InvokeRootDeviceRemoved(rootEntry); } } }
private bool ParseRequestLine() { string[] RequestLineDel = new string[] {" "}; string[] splittedRequestLine = splittedRequest[0].Split(RequestLineDel, StringSplitOptions.None); string methodCheck = splittedRequestLine[0]; if (methodCheck == "GET") { this.method = RequestMethod.GET; } if (methodCheck == "POST") { this.method = RequestMethod.POST; } if (methodCheck == "HEAD") { this.method = RequestMethod.HEAD; } string version = splittedRequestLine[2]; if (version == "HTTP/1.0") { this.httpVersion = HTTPVersion.HTTP10; } else if (version == "HTTP/1.1") { this.httpVersion = HTTPVersion.HTTP11; } else { this.httpVersion = HTTPVersion.HTTP09; } relativeURI = splittedRequestLine[1]; bool URI = ValidateIsURI(relativeURI); if (URI == true) { return true; } else { return false; } // throw new NotImplementedException(); }
protected RootEntry GetOrCreateRootEntry(string deviceUUID, string descriptionLocation, UPnPVersion upnpVersion, string osVersion, string productVersion, DateTime expirationTime, EndpointConfiguration endpoint, HTTPVersion httpVersion, int searchPort, out bool wasAdded) { // Because the order of the UDP advertisement packets isn't guaranteed (and even not really specified by the UPnP specification), // in the general case it is not possible to find the correct root entry for each advertisement message. // - We cannot search by root device UUID because the upnp:rootdevice message might not be the first message, so before that message, we don't know the root device ID and // thus we cannot use the root device id as unique key to find the root entry // - We cannot use the device description because for multi-homed devices, more than one device description can belong to the same root device // // Assume the message arrive in an order so that device A over network interface N1 is announced first. Second, device B over network interface N2 is announced. // In that case, we cannot judge if those two devices belong to the same root device or not. // // To face that situation, we first add all advertised devices to _pendingDeviceEntries. When a upnp:rootdevice message is received, // we either simply move the root entry from _pendingDeviceEntries into _cpData.DeviceEntries or we merge the pending entry with an already existing // entry in _cpData.DeviceEntries. At that time the merge is possible because we then have the root device id for both root entries. lock (_cpData.SyncObj) { RootEntry result = GetRootEntryByContainedDeviceUUID(deviceUUID) ?? GetRootEntryByDescriptionLocation(descriptionLocation); if (result != null) { result.ExpirationTime = expirationTime; wasAdded = false; } else { result = new RootEntry(_cpData.SyncObj, upnpVersion, osVersion, productVersion, expirationTime); _pendingDeviceEntries.Add(result); wasAdded = true; } return(result); } }
private bool ParseRequestLine() { string[] requestLine = requestLines[0].Split(' '); if (requestLine.Length == 3) { requestLine[0] = requestLine[0].ToUpper(); switch (requestLine[0]) { case "GET": method = RequestMethod.GET; break; case "POST": method = RequestMethod.POST; break; default: return(false); } if (ValidateIsURI(requestLine[1])) { string[] tmp = requestLine[1].Split('/'); relativeURI = tmp[1]; } else { Logger.LogException(new Exception("Relative Uri " + requestLines[1] + " is Invalid")); return(false); } requestLine[2] = requestLine[2].ToUpper(); switch (requestLine[2]) { case "HTTP/1.1": httpVersion = HTTPVersion.HTTP11; break; case "HTTP/1.0": httpVersion = HTTPVersion.HTTP10; break; default: return(false); } } else { Logger.LogException(new Exception("RequstLine " + requestLines[0] + " is missing informations")); return(false); } return(true); // throw new NotImplementedException(); }
private bool ParseRequestLine() { if (requestLines.Length < 2) { return false; } if (requestLines.Length == 2) { httpVersion = HTTPVersion.HTTP09; } else { if (requestLines[2] == "HTTP/1.0") { httpVersion = HTTPVersion.HTTP10; } else if (requestLines[2] == "HTTP/1.1") { httpVersion = HTTPVersion.HTTP11; } else { return false; } } switch (requestLines[0].ToUpper()) { case "GET": method = RequestMethod.GET; break; case "POST": method = RequestMethod.POST; break; case "HEAD": method = RequestMethod.HEAD; break; default: return false; } relativeURI = requestLines[1]; return ValidateIsURI(relativeURI); }
/// <summary> /// Set the protocol version. /// </summary> /// <param name="ProtocolVersion">The protocol version.</param> public HTTPRequestBuilder SetProtocolVersion(HTTPVersion ProtocolVersion) { this.ProtocolVersion = ProtocolVersion; return this; }
private bool ParseRequestLine() { try { if (requestLines[0] == "GET") method = RequestMethod.GET; else if (requestLines[0] == "HEAD") method = RequestMethod.HEAD; else if (requestLines[0] == "POST") method = RequestMethod.POST; relativeURI = requestLines[1].Trim('/'); if (requestLines[2] == "HTTP/0.9") httpVersion = HTTPVersion.HTTP09; if (requestLines[2] == "HTTP/1.0") httpVersion = HTTPVersion.HTTP10; if (requestLines[2] == "HTTP/1.1") httpVersion = HTTPVersion.HTTP11; } catch { return false; } return true; }
private bool ParseRequestLine(string []arr1) { //throw new NotImplementedException(); string[] arr2 = arr1[0].Split(' '); method = (RequestMethod)Enum.Parse(typeof(RequestMethod), arr2[0]); relativeURI = arr2[1]; if (arr2[2] == "HTTP/1.1") { arr2[2] = "HTTP11"; } if (arr2[2] == "HTTP/1.0") { arr2[2] = "HTTP10"; } if (arr2[2] == "HTTP/0.9") { arr2[2] = "HTTP09"; } httpVersion = (HTTPVersion)Enum.Parse(typeof(HTTPVersion), arr2[2]); if (ValidateIsURI(relativeURI)) { return true; } return true; }