1 
2 /*
3 
4 
5 
6 					W3C Sample Code Library libwww Link Class
7 
8 
9 
10 !The Link Class!
11 */
12 /*
13 **        (c) COPYRIGHT MIT 1995.
14 **        Please first read the full copyright statement in the file COPYRIGH.
15 */
16 /*
17 
18 The HTLink class represents links between anchor objects. By keeping the link as a object and
19 not as part of the anchor we are capable of handling link semantics in a much
20 more organized way. For example, we can then search for link types among all
21 the link objects that we have created. Anchor
22 objects are bound together using Link objects. Each anchor can be the
23 source or destination of zero, one, or more links from and to other
24 anchors.
25 
26 Link information can come from many places - two classic examples are the
27 HTML LINK element and the HTTP Link header field.
28 Libwww supports both - the HTML LINK element is handled by the HTML parser and the HTTP Link header field
29 is handled by the MIME parser.
30 
31 The Webbot uses the link class to maintain the
32 information of the Web that it is seeing when traversing the Web as a
33 robot.
34 
35 This module is implemented by HTLink.c, and it is a
36 part of the  W3C Sample Code
37 Library.
38 */
39 
40 #ifndef HTLINK_H
41 #define HTLINK_H
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 typedef struct _HTLink        HTLink;
48 
49 #include "WWWUtil.h"
50 #include "HTMethod.h"
51 #include "HTAnchor.h"
52 /*
53 
54 .Creation and Deletion Methods.
55 
56 These are the methods for crating and deleting new link objects
57 
58 (Create a new Link Object)
59 */
60 typedef HTAtom *         HTLinkType;
61 
62 typedef enum _HTLinkResult {
63     HT_LINK_INVALID = -1,
64     HT_LINK_NONE = 0,
65     HT_LINK_ERROR,
66     HT_LINK_OK
67 } HTLinkResult;
68 
69 struct _HTLink {
70     HTAnchor *          dest;              /* The anchor to which this leads */
71     HTLinkType          type;                      /* Semantics of this link */
72     HTMethod            method;            /* Method for this link, e.g. PUT */
73     HTLinkResult        result;    /* Result of any attempt to get this link */
74 };
75 
76 HTLink * HTLink_new (void);
77 /*
78 
79 (Delete a Link Object)
80 
81 A link can be removed as any other object
82 */
83 BOOL HTLink_delete (HTLink * link);
84 /*
85 
86 (Remove All Link Information from an Anchor)
87 
88 This is normally a part of deleting anchor objects.
89 */
90 extern BOOL HTLink_removeAll (HTAnchor * me);
91 /*
92 
93 .Predefined Link Types.
94 
95 Just for ease of use, we define a seet of commonly used link types. You can
96 ofcourse use any other link type you want.
97 */
98 #define HT_LR_PERM_REDIRECT        HTAtom_for("PERMANENT_REDIRECTION")
99 #define HT_LR_TEMP_REDIRECT        HTAtom_for("TEMPORARY_REDIRECTION")
100 #define HT_LR_SEE_OTHER            HTAtom_for("SEE_OTHER")
101 /*
102 
103 .Handle Link Between Anchors.
104 
105 As mentioned, link objects are the ones that bind anchor objects together
106 in a Web like structure
107 
108 (Add a Link between two Anchors)
109 
110 This method creates a new link between two anchor
111 objects.
112 */
113 extern BOOL HTLink_add (
114         HTAnchor *        source,
115         HTAnchor *        destination,
116         HTLinkType        type,
117         HTMethod          method);
118 /*
119 
120 (Remove All Links Between two Anchors)
121 
122 Removes link information from one anchor to another.
123 */
124 extern BOOL HTLink_remove (
125         HTAnchor *        source,
126         HTAnchor *        destination);
127 /*
128 
129 (Find a Link)
130 
131 Find the anchor object between a destination and a source ancher. Return
132 link object if any, else NULL
133 */
134 extern HTLink * HTLink_find (HTAnchor * source, HTAnchor * destination);
135 /*
136 
137 (Find a Link with a given link type)
138 
139 Returns a link with a given link type or NULL if nothing found
140 */
141 extern HTLink * HTLink_findType (HTAnchor * me, HTLinkType type);
142 /*
143 
144 .Link Information.
145 
146 This is the set of methods for accessing the information carried by a link
147 object
148 
149 (Link Destination)
150 
151 The link destination is the destination anchor pointed to by the link.
152 */
153 extern BOOL HTLink_setDestination (HTLink * link, HTAnchor * dest);
154 extern HTAnchor * HTLink_destination (HTLink * link);
155 /*
156 
157 (Link Types and Semantic Links)
158 
159 Each link has a sematic representation associated with it. This means that
160 the application can distinguish between pages based on the semantics of the
161 link. This is very similar to the LINK tag in HTML pages which
162 indicates the meaning if this pages to other pages.
163 */
164 extern BOOL HTLink_setType (HTLink * link, HTLinkType type);
165 extern HTLinkType HTLink_type (HTLink * link);
166 /*
167 
168 (Link Method)
169 
170 The link method is the HTTP method we have performed between the two links.
171 For example, it can be a POST operation, or a PUT operation where the
172 operation on the first anchor created a new anchor.
173 */
174 extern BOOL HTLink_setMethod (HTLink * link, HTMethod method);
175 extern HTMethod HTLink_method (HTLink * link);
176 /*
177 
178 (Link Result)
179 
180 When a link has been used for posting an object from a source to a
181 destination link, the result of the operation is stored as part of the link
182 information. This means that we can keep track of which operations we have
183 performed on a link and hence the application can ask the user whether he or
184 she wants to do a re-post, for example.
185 */
186 extern BOOL HTLink_setResult (HTLink * link, HTLinkResult result);
187 extern HTLinkResult HTLink_result (HTLink * link);
188 /*
189 */
190 
191 #ifdef __cplusplus
192 }
193 #endif
194 
195 #endif /* HTLINK_H */
196 
197 /*
198 
199 
200 
201 
202 
203 @(#) $Id$
204 
205 */
206