public static Parse ( ITextReader reader ) : SipUri | ||
reader | ITextReader | Reader containing the string that should be parsed. |
Résultat | SipUri |
/// <summary> /// Parse a message value. /// </summary> /// <param name="name">Name of header being parsed.</param> /// <param name="reader">Reader containing the string that should be parsed.</param> /// <returns>Newly created header.</returns> /// <exception cref="ParseException">Header value is malformed.</exception> public IHeader Parse(string name, ITextReader reader) { var route = new Route(name); try { SipUri uri = UriParser.Parse(reader); route.Items.Add(new RouteEntry(name) { Uri = uri }); while (reader.Current == ',') { reader.ConsumeWhiteSpaces(','); if (!reader.EOF) { uri = UriParser.Parse(reader); } route.Items.Add(new RouteEntry(name) { Uri = uri }); } } catch (FormatException err) { throw new ParseException("Failed to parse header '" + name + "'.", err); } return(route); }
/// <summary> /// Parse a message value. /// </summary> /// <param name="name">Name of header being parsed.</param> /// <param name="reader">Reader containing the string that should be parsed.</param> /// <returns>Newly created header.</returns> /// <exception cref="ParseException">Header value is malformed.</exception> /// <example> /// Authorization: Digest username="******", /// realm="biloxi.com", /// nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", /// uri="sip:[email protected]", /// qop=auth, /// nc=00000001, /// cnonce="0a4f113b", /// response="6629fae49393a05397450978507c4ef1", /// opaque="5ccc069c403ebaf9f0171e9517f40e41" /// </example> public IHeader Parse(string name, ITextReader reader) { reader.ConsumeWhiteSpaces(); string digest = reader.ReadWord().ToLower(); if (digest != "digest") { throw new ParseException("Authorization header is not digest authentication"); } reader.ConsumeWhiteSpaces(); var parameters = new KeyValueCollection(); UriParser.ParseParameters(parameters, reader, ','); var header = new Authorization(name) { UserName = parameters["username"], Realm = parameters["realm"], Nonce = parameters["nonce"], Qop = parameters["qop"], ClientNonce = parameters["cnonce"], Opaque = parameters["opaque"], Response = parameters["response"], Uri = UriParser.Parse(parameters["uri"]) }; try { header.NonceCounter = int.Parse(parameters["nc"]); } catch (Exception err) { throw new ParseException("Failed to parse 'nc' in Authorization header.", err); } return(header); }
/// <summary> /// Parse a message value. /// </summary> /// <param name="name">Name of header being parsed.</param> /// <param name="reader">Reader containing the string that should be parsed.</param> /// <returns>Newly created header.</returns> /// <exception cref="ParseException">Header value is malformed.</exception> /// <example> /// Digest realm="atlanta.com", /// domain="sip:boxesbybob.com", qop="auth", /// nonce="f84f1cec41e6cbe5aea9c8e88d359", /// opaque="", stale=FALSE, algorithm=MD5 /// </example> public IHeader Parse(string name, ITextReader reader) { reader.ConsumeWhiteSpaces(); string digest = reader.ReadWord().ToLower(); if (digest != "digest") { throw new ParseException("Authorization header is not digest authentication"); } reader.ConsumeWhiteSpaces(); var parameters = new KeyValueCollection(); UriParser.ParseParameters(parameters, reader, ','); var header = new Authenticate(name) { Algortihm = parameters["algorithm"], Domain = UriParser.Parse(parameters["domain"]), Realm = parameters["realm"], Nonce = parameters["nonce"], Qop = parameters["qop"], Opaque = parameters["opaque"] }; try { header.Stale = bool.Parse(parameters["stale"]); } catch (Exception err) { throw new ParseException("Failed to parse 'stale' in WWW-Authenticate header.", err); } return(header); }