File: URL.h

package info (click to toggle)
htdig 1%3A3.2.0b6-12
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 14,996 kB
  • ctags: 9,373
  • sloc: ansic: 49,626; cpp: 46,470; sh: 20,694; xml: 4,180; perl: 2,543; makefile: 887; php: 79; asm: 14
file content (100 lines) | stat: -rw-r--r-- 3,005 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//
// URL.h
//
// URL: A URL parsing class, implementing as closely as possible the standard
//      laid out in RFC2396 (e.g. http://www.faqs.org/rfcs/rfc2396.html)
//      including support for multiple schemes.
//
// Part of the ht://Dig package   <http://www.htdig.org/>
// Copyright (c) 1995-2004 The ht://Dig Group
// For copyright details, see the file COPYING in your distribution
// or the GNU Library General Public License (LGPL) version 2 or later 
// <http://www.gnu.org/copyleft/lgpl.html>
//
// $Id: URL.h,v 1.8 2004/05/28 13:15:12 lha Exp $
//

#ifndef _URL_h_
#define _URL_h_

#include "htString.h"

class URL
{
public:
    URL();
    URL(const String &url);
    URL(const URL& rhs);
    URL(const String &ref, const URL &parent);

    void parse(const String &url);

    const String &host() const      {return _host;}
    void host(const String &h)      {_host = h;}
    
    int port() const                {return _port;}
    void port(const int p)          {_port = p;}
    int DefaultPort();
    
    const String &service() const   {return _service;}
    void service(const String &s)   {_service = s;}

    const String &path() const      {return _path;}
    void path(const String &p);
    
    int hopcount() const            {return _hopcount;}
    void hopcount(int h)            {_hopcount = h;}
    
    const String &user() const      {return _user;}
    void user(const String &u)      {_user = u;}

    const String &get() const {return _url;}
    void		dump();
    void		normalize();
    void		rewrite();
    const String &signature();

    const URL &operator = (const URL &rhs);

private:
    String		_url;
    String		_path;
    String		_service;
    String		_host;
    int			_port;
    int			_normal;
    int			_hopcount;
    String		_signature;
    String		_user;

    void		removeIndex(String &, String &);
    void                normalizePath();
    void		ServerAlias();
    void		constructURL();
    // Number of slashes following service specifier.  eg service("http")=2
    static int		slashes(const String &);
};


// Unreserved punctuation allowed unencoded in URLs.  We use a more restricted
// list of unreserved characters than allowed by RFC 2396 (which revises and
// replaces RFC 1738), because it can't hurt to encode any of these
// characters, and they can pose problems in some contexts.  RFC 2396 says
// that only alphanumerics, the unreserved characters "-_.!~*'(),", and
// reserved characters used for their reserved purposes may be used
// unencoded within a URL.  We encode reserved characters because we now
// encode URL parameter values individually before piecing together the whole
// query string using reserved characters.

#define UNRESERVED	"-_.!~*"

//String &encodeURL(String &, char *valid = "?_@.=&/:");
//String &encodeURL(String &, char *reserved = ";/?:@&=+$,");
//	       	              char *unreserved = "-_.!~*'()");
String &encodeURL(String &, char *valid = (char *)UNRESERVED);

String &decodeURL(String &);

#endif