1 /*
2  * File : url.h - Dillo
3  *
4  * Copyright (C) 2001 Jorge Arellano Cid <jcid@dillo.org>
5  *
6  * Parse and normalize all URL's inside Dillo.
7  */
8 
9 #ifndef __URL_H__
10 #define __URL_H__
11 
12 #include "d_size.h"
13 #include "../dlib/dlib.h"
14 
15 
16 #define DILLO_URL_HTTP_PORT        80
17 #define DILLO_URL_HTTPS_PORT       443
18 #define DILLO_URL_FTP_PORT         21
19 #define DILLO_URL_MAILTO_PORT      25
20 #define DILLO_URL_NEWS_PORT        119
21 #define DILLO_URL_TELNET_PORT      23
22 #define DILLO_URL_GOPHER_PORT      70
23 
24 
25 /*
26  * Values for DilloUrl->flags.
27  * Specifies which which action to perform with an URL.
28  */
29 #define URL_Get                 (1 << 0)
30 #define URL_Post                (1 << 1)
31 #define URL_ISindex             (1 << 2)
32 #define URL_Ismap               (1 << 3)
33 #define URL_RealmAccess         (1 << 4)
34 
35 #define URL_E2EQuery            (1 << 5)
36 #define URL_ReloadImages        (1 << 6)
37 #define URL_ReloadPage          (1 << 7)
38 #define URL_ReloadFromCache     (1 << 8)
39 
40 #define URL_IgnoreScroll        (1 << 9)
41 #define URL_SpamSafe            (1 << 10)
42 
43 #define URL_MultipartEnc        (1 << 11)
44 
45 /*
46  * Access methods to fields inside DilloURL.
47  * (non '_'-ended macros MUST use these for initialization sake)
48  */
49 /* these MAY return NULL: */
50 #define URL_SCHEME_(u)              (u)->scheme
51 #define URL_AUTHORITY_(u)           (u)->authority
52 #define URL_PATH_(u)                (u)->path
53 #define URL_QUERY_(u)               (u)->query
54 #define URL_FRAGMENT_(u)            (u)->fragment
55 #define URL_HOST_(u)                a_Url_hostname(u)
56 #define URL_ALT_(u)                 (u)->alt
57 #define URL_STR_(u)                 a_Url_str(u)
58 /* this returns a Dstr* */
59 #define URL_DATA_(u)                (u)->data
60 /* these return an integer */
61 #define URL_PORT_(u)                (URL_HOST(u), (u)->port)
62 #define URL_FLAGS_(u)               (u)->flags
63 #define URL_ILLEGAL_CHARS_(u)       (u)->illegal_chars
64 #define URL_ILLEGAL_CHARS_SPC_(u)   (u)->illegal_chars_spc
65 
66 /*
67  * Access methods that never return NULL.
68  * When the "empty" and "undefined" concepts of RFC-2396 are irrelevant to
69  * the caller, and a string is required, use these methods instead:
70  */
71 #define NPTR2STR(p)                 ((p) ? (p) : "")
72 #define URL_SCHEME(u)               NPTR2STR(URL_SCHEME_(u))
73 #define URL_AUTHORITY(u)            NPTR2STR(URL_AUTHORITY_(u))
74 #define URL_PATH(u)                 NPTR2STR(URL_PATH_(u))
75 #define URL_QUERY(u)                NPTR2STR(URL_QUERY_(u))
76 #define URL_FRAGMENT(u)             NPTR2STR(URL_FRAGMENT_(u))
77 #define URL_HOST(u)                 NPTR2STR(URL_HOST_(u))
78 #define URL_DATA(u)                 URL_DATA_(u)
79 #define URL_ALT(u)                  NPTR2STR(URL_ALT_(u))
80 #define URL_STR(u)                  NPTR2STR(URL_STR_(u))
81 #define URL_PORT(u)                 URL_PORT_(u)
82 #define URL_FLAGS(u)                URL_FLAGS_(u)
83 #define URL_ILLEGAL_CHARS(u)        URL_ILLEGAL_CHARS_(u)
84 #define URL_ILLEGAL_CHARS_SPC(u)    URL_ILLEGAL_CHARS_SPC_(u)
85 
86 
87 #ifdef __cplusplus
88 extern "C" {
89 #endif /* __cplusplus */
90 
91 typedef struct {
92    Dstr  *url_string;
93    const char *buffer;
94    const char *scheme;            /**/
95    const char *authority;         /**/
96    const char *path;              /* These are references only */
97    const char *query;             /* (no need to free them) */
98    const char *fragment;          /**/
99    const char *hostname;          /**/
100    int port;
101    int flags;
102    Dstr *data;                    /* POST */
103    const char *alt;               /* "alt" text (used by image maps) */
104    int ismap_url_len;             /* Used by server side image maps */
105    int illegal_chars;             /* number of illegal chars */
106    int illegal_chars_spc;         /* number of illegal space chars */
107 } DilloUrl;
108 
109 
110 DilloUrl* a_Url_new(const char *url_str, const char *base_url);
111 void a_Url_free(DilloUrl *u);
112 char *a_Url_str(const DilloUrl *url);
113 const char *a_Url_hostname(const DilloUrl *u);
114 DilloUrl* a_Url_dup(const DilloUrl *u);
115 int a_Url_cmp(const DilloUrl *A, const DilloUrl *B);
116 void a_Url_set_flags(DilloUrl *u, int flags);
117 void a_Url_set_data(DilloUrl *u, Dstr **data);
118 void a_Url_set_alt(DilloUrl *u, const char *alt);
119 void a_Url_set_ismap_coords(DilloUrl *u, char *coord_str);
120 char *a_Url_decode_hex_str(const char *str);
121 char *a_Url_encode_hex_str(const char *str);
122 char *a_Url_string_strip_delimiters(const char *str);
123 bool_t a_Url_same_organization(const DilloUrl *u1, const DilloUrl *u2);
124 #ifdef __cplusplus
125 }
126 #endif /* __cplusplus */
127 
128 #endif /* __URL_H__ */
129