1139826Simp/* 253541Sshin * Copyright 2010 Haiku Inc. All rights reserved. 353541Sshin * Distributed under the terms of the MIT License. 453541Sshin */ 553541Sshin#ifndef _B_URL_H_ 653541Sshin#define _B_URL_H_ 753541Sshin 853541Sshin 953541Sshin#include <Archivable.h> 1053541Sshin#include <Message.h> 1153541Sshin#include <String.h> 1253541Sshin 1353541Sshin 1453541Sshinclass BUrl : public BArchivable { 1553541Sshinpublic: 1653541Sshin BUrl(const char* url); 1753541Sshin BUrl(BMessage* archive); 1853541Sshin BUrl(const BUrl& other); 1953541Sshin BUrl(); 2053541Sshin virtual ~BUrl(); 2153541Sshin 2253541Sshin // URL fields modifiers 2353541Sshin BUrl& SetUrlString(const BString& url); 2453541Sshin BUrl& SetProtocol(const BString& scheme); 2553541Sshin BUrl& SetUserName(const BString& user); 2653541Sshin BUrl& SetPassword(const BString& password); 2753541Sshin BUrl& SetHost(const BString& host); 2853541Sshin BUrl& SetPort(int port); 29174510Sobrien BUrl& SetPath(const BString& path); 3053541Sshin BUrl& SetRequest(const BString& request); 3153541Sshin BUrl& SetFragment(const BString& fragment); 32139826Simp 3353541Sshin // URL fields access 3453541Sshin const BString& UrlString() const; 3553541Sshin const BString& Protocol() const; 3653541Sshin const BString& UserName() const; 3753541Sshin const BString& Password() const; 3853541Sshin const BString& UserInfo() const; 3953541Sshin const BString& Host() const; 4053541Sshin int Port() const; 4153541Sshin const BString& Authority() const; 4253541Sshin const BString& Path() const; 4353541Sshin const BString& Request() const; 4453541Sshin const BString& Fragment() const; 4553541Sshin 4653541Sshin // URL fields tests 4753541Sshin bool IsValid() const; 4853541Sshin bool HasProtocol() const; 4953541Sshin bool HasUserName() const; 5053541Sshin bool HasPassword() const; 5153541Sshin bool HasUserInfo() const; 5253541Sshin bool HasHost() const; 5353541Sshin bool HasPort() const; 5453541Sshin bool HasAuthority() const; 5553541Sshin bool HasPath() const; 5653541Sshin bool HasRequest() const; 5753541Sshin bool HasFragment() const; 5853541Sshin 5953541Sshin // Url encoding/decoding of needed fields 6053541Sshin void UrlEncode(bool strict = false); 6153541Sshin void UrlDecode(bool strict = false); 6253541Sshin 63174510Sobrien // Url encoding/decoding of strings 64174510Sobrien static BString UrlEncode(const BString& url, 65174510Sobrien bool strict = false, 6678064Sume bool directory = false); 6778064Sume static BString UrlDecode(const BString& url, 6855009Sshin bool strict = false); 69174717Srwatson 7053541Sshin // BArchivable members 7153541Sshin virtual status_t Archive(BMessage* into, 7253541Sshin bool deep = true) const; 7353541Sshin static BArchivable* Instantiate(BMessage* archive); 7453541Sshin 7555679Sshin // URL comparison 7653541Sshin bool operator==(BUrl& other) const; 7753541Sshin bool operator!=(BUrl& other) const; 7853541Sshin 7953541Sshin // URL assignment 8053541Sshin const BUrl& operator=(const BUrl& other); 8153541Sshin const BUrl& operator=(const BString& string); 82164033Srwatson const BUrl& operator=(const char* string); 8353541Sshin 8453541Sshin // URL to string conversion 8553541Sshin operator const char*() const; 8692767Sjeff 8753541Sshinprivate: 8853541Sshin void _ResetFields(); 8953541Sshin void _ExplodeUrlString(const BString& urlString); 9053541Sshin 9153541Sshin void _ExtractProtocol(const BString& urlString, 9253541Sshin int16* origin); 9353541Sshin void _ExtractAuthority(const BString& urlString, 9453541Sshin int16* origin); 9598102Shsu void _ExtractPath(const BString& urlString, 9662587Sitojun int16* origin); 9755679Sshin void _ExtractRequestAndFragment( 9853541Sshin const BString& urlString, int16* origin); 9953541Sshin 10053541Sshin static BString _DoUrlEncodeChunk(const BString& chunk, 10153541Sshin bool strict, bool directory = false); 102148385Sume static BString _DoUrlDecodeChunk(const BString& chunk, 10353541Sshin bool strict); 104171167Sgnn 105105199Ssam bool _IsProtocolValid(); 106105199Ssam static bool _IsAuthorityTerminator(char c); 107105199Ssam static bool _IsPathTerminator(char c); 108171167Sgnn static bool _IsRequestTerminator(char c); 109105199Ssam static bool _IsUnreserved(char c); 110174717Srwatson static bool _IsGenDelim(char c); 111174717Srwatson static bool _IsSubDelim(char c); 11253541Sshin 11353541Sshinprivate: 11453541Sshin mutable BString fUrlString; 115171259Sdelphij mutable BString fAuthority; 116171259Sdelphij mutable BString fUserInfo; 11753541Sshin 11853541Sshin BString fProtocol; 11953541Sshin BString fUser; 12053541Sshin BString fPassword; 12153541Sshin BString fHost; 12297658Stanimura int fPort; 12353541Sshin BString fPath; 124132714Srwatson BString fRequest; 125178285Srwatson BString fFragment; 126132714Srwatson 12753541Sshin mutable bool fUrlStringValid : 1; 12853541Sshin mutable bool fAuthorityValid : 1; 12953541Sshin mutable bool fUserInfoValid : 1; 130120856Sume 13153541Sshin bool fBasicUri : 1; 132160024Sbz 13353541Sshin bool fHasProtocol : 1; 134148385Sume bool fHasUserName : 1; 135148385Sume bool fHasPassword : 1; 13653541Sshin bool fHasUserInfo : 1; 13753541Sshin bool fHasHost : 1; 138120856Sume bool fHasPort : 1; 13953541Sshin bool fHasAuthority : 1; 14053541Sshin bool fHasPath : 1; 14153541Sshin bool fHasRequest : 1; 14253541Sshin bool fHasFragment : 1; 143120856Sume}; 14453541Sshin 145148385Sume#endif // _B_URL_H_ 146148385Sume