1 /* 2 * $LynxId: HTAnchor.h,v 1.36 2012/08/15 10:48:24 tom Exp $ 3 * 4 * Hypertext "Anchor" Object HTAnchor.h 5 * ========================== 6 * 7 * An anchor represents a region of a hypertext document which is linked 8 * to another anchor in the same or a different document. 9 */ 10 11 #ifndef HTANCHOR_H 12 #define HTANCHOR_H 13 14 /* Version 0 (TBL) written in Objective-C for the NeXT browser */ 15 /* Version 1 of 24-Oct-1991 (JFG), written in C, browser-independent */ 16 17 #include <HTList.h> 18 #include <HTBTree.h> 19 #include <HTChunk.h> 20 #include <HTAtom.h> 21 #include <UCDefs.h> 22 23 typedef struct _HyperDoc HyperDoc; /* Ready for forward references */ 24 typedef struct _HTAnchor HTAnchor; 25 typedef struct _HTParentAnchor HTParentAnchor; 26 typedef struct _HTParentAnchor0 HTParentAnchor0; 27 28 #include <HTFormat.h> 29 30 #ifdef __cplusplus 31 extern "C" { 32 #endif 33 struct _HTAnchor { 34 /* Generic anchor */ 35 HTParentAnchor0 *parent; /* Parent of this anchor (self for adults) */ 36 }; 37 38 #define HASH_TYPE unsigned short 39 40 struct _HTParentAnchor0 { /* One for adult_table, 41 * generally not used outside HTAnchor.c */ 42 /* Common part from the generic anchor structure */ 43 HTParentAnchor0 *parent; /* (self) */ 44 45 /* ParentAnchor0-specific information */ 46 char *address; /* Absolute address of this node */ 47 HTParentAnchor *info; /* additional info, allocated on demand */ 48 49 HTBTree *children; /* Subanchors <a name="tag">, sorted by tag */ 50 HTList sources; /* List of anchors pointing to this, if any */ 51 52 HTList _add_adult; /* - just a memory for list entry:) */ 53 HASH_TYPE adult_hash; /* adult list number */ 54 BOOL underway; /* Document about to be attached to it */ 55 }; 56 57 /* 58 * Separated from the above to save memory: allocated on demand, 59 * it is nearly 1:1 to HText (well, sometimes without HText...), 60 * available for SGML, HTML, and HText stages. 61 * [being precise, we currently allocate it before HTLoadDocument(), 62 * in HTAnchor_findAddress() and HTAnchor_parent()]. 63 */ 64 struct _HTParentAnchor { 65 /* Common part from the generic anchor structure */ 66 HTParentAnchor0 *parent; /* Parent of this anchor */ 67 68 /* ParentAnchor-specific information */ 69 HTList children_notag; /* Subanchors <a href=...>, tag is NULL */ 70 HyperDoc *document; /* The document within which this is an anchor */ 71 72 char *address; /* parent->address, a pointer */ 73 bstring *post_data; /* Posting data */ 74 char *post_content_type; /* Type of post data */ 75 char *bookmark; /* Bookmark filename */ 76 HTFormat format; /* Pointer to node format descriptor */ 77 char *charset; /* Pointer to character set (kludge, for now */ 78 BOOL isIndex; /* Acceptance of a keyword search */ 79 char *isIndexAction; /* URL of isIndex server */ 80 char *isIndexPrompt; /* Prompt for isIndex query */ 81 char *title; /* Title of document */ 82 char *owner; /* Owner of document */ 83 char *RevTitle; /* TITLE in REV="made" or REV="owner" LINK */ 84 char *citehost; /* Citehost from REL="citehost" LINK */ 85 #ifdef USE_COLOR_STYLE 86 char *style; 87 #endif 88 89 HTList *methods; /* Methods available as HTAtoms */ 90 void *protocol; /* Protocol object */ 91 char *physical; /* Physical address */ 92 BOOL isISMAPScript; /* Script for clickable image map */ 93 BOOL isHEAD; /* Document is headers from a HEAD request */ 94 BOOL safe; /* Safe */ 95 #ifdef USE_SOURCE_CACHE 96 char *source_cache_file; 97 HTChunk *source_cache_chunk; 98 #endif 99 char *FileCache; /* Path to a disk-cached copy (see src/HTFWriter.c) */ 100 char *SugFname; /* Suggested filename */ 101 char *cache_control; /* Cache-Control */ 102 BOOL no_cache; /* Cache-Control, Pragma or META "no-cache"? */ 103 BOOL inBASE; /* duplicated from HTStructured (HTML.c/h) */ 104 #ifdef EXP_HTTP_HEADERS 105 HTChunk http_headers; 106 #endif 107 char *content_type_params; /* Content-Type (with parameters if any) */ 108 char *content_type; /* Content-Type */ 109 char *content_language; /* Content-Language */ 110 char *content_encoding; /* Compression algorithm */ 111 char *content_base; /* Content-Base */ 112 char *content_disposition; /* Content-Disposition */ 113 char *content_location; /* Content-Location */ 114 char *content_md5; /* Content-MD5 */ 115 char *message_id; /* Message-ID */ 116 char *subject; /* Subject */ 117 off_t content_length; /* Content-Length */ 118 off_t actual_length; /* actual length may differ */ 119 char *date; /* Date */ 120 char *expires; /* Expires */ 121 char *last_modified; /* Last-Modified */ 122 char *ETag; /* ETag (HTTP1.1 cache validator) */ 123 char *server; /* Server */ 124 UCAnchorInfo *UCStages; /* chartrans stages */ 125 HTList *imaps; /* client side image maps */ 126 }; 127 128 typedef HTAtom HTLinkType; 129 130 typedef struct { 131 /* Common part from the generic anchor structure */ 132 HTParentAnchor0 *parent; /* Parent of this anchor */ 133 134 /* ChildAnchor-specific information */ 135 char *tag; /* #fragment, relative to the parent */ 136 137 HTAnchor *dest; /* The anchor to which this leads */ 138 HTLinkType *type; /* Semantics of this link */ 139 140 HTList _add_children_notag; /* - just a memory for list entry:) */ 141 HTList _add_sources; /* - just a memory for list entry:) */ 142 } HTChildAnchor; 143 144 /* 145 * DocAddress structure is used for loading an absolute anchor with all 146 * needed information including posting data and post content type. 147 */ 148 typedef struct _DocAddress { 149 char *address; 150 bstring *post_data; 151 char *post_content_type; 152 char *bookmark; 153 BOOL isHEAD; 154 BOOL safe; 155 } DocAddress; 156 157 /* "internal" means "within the same document, with certainty". */ 158 extern HTLinkType *HTInternalLink; 159 160 /* Create or find a child anchor with a possible link 161 * -------------------------------------------------- 162 * 163 * Create new anchor with a given parent and possibly 164 * a name, and possibly a link to a _relatively_ named anchor. 165 * (Code originally in ParseHTML.h) 166 */ 167 extern HTChildAnchor *HTAnchor_findChildAndLink(HTParentAnchor *parent, /* May not be 0 */ 168 const char *tag, /* May be "" or 0 */ 169 const char *href, /* May be "" or 0 */ 170 HTLinkType *ltype); /* May be 0 */ 171 172 /* Create new or find old parent anchor 173 * ------------------------------------ 174 * 175 * This one is for a reference which is found in a document, and might 176 * not be already loaded. 177 * Note: You are not guaranteed a new anchor -- you might get an old one, 178 * like with fonts. 179 */ 180 extern HTParentAnchor *HTAnchor_findAddress(const DocAddress *address); 181 182 /* Create new or find old named anchor - simple form 183 * ------------------------------------------------- 184 * 185 * Like the previous one, but simpler to use for simple cases. 186 * No post data etc. can be supplied. - kw 187 */ 188 extern HTParentAnchor *HTAnchor_findSimpleAddress(const char *url); 189 190 /* Delete an anchor and possibly related things (auto garbage collection) 191 * -------------------------------------------- 192 * 193 * The anchor is only deleted if the corresponding document is not loaded. 194 * All outgoing links from children are deleted, and children are 195 * removed from the sources lists of their targets. 196 * We also try to delete the targets whose documents are not loaded. 197 * If this anchor's sources list is empty, we delete it and its children. 198 */ 199 extern BOOL HTAnchor_delete(HTParentAnchor0 *me); 200 201 /* 202 * Unnamed children (children_notag) have no sense without HText - 203 * delete them and their links if we are about to free HText. 204 * Document currently exists. Called within HText_free(). 205 */ 206 extern void HTAnchor_delete_links(HTParentAnchor *me); 207 208 #ifdef USE_SOURCE_CACHE 209 extern void HTAnchor_clearSourceCache(HTParentAnchor *me); 210 #endif 211 212 /* Data access functions 213 * --------------------- 214 */ 215 extern HTParentAnchor *HTAnchor_parent(HTAnchor * me); 216 217 extern void HTAnchor_setDocument(HTParentAnchor *me, 218 HyperDoc *doc); 219 220 extern HyperDoc *HTAnchor_document(HTParentAnchor *me); 221 222 /* Returns the full URI of the anchor, child or parent 223 * as a malloc'd string to be freed by the caller. 224 */ 225 extern char *HTAnchor_address(HTAnchor * me); 226 227 extern void HTAnchor_setFormat(HTParentAnchor *me, 228 HTFormat form); 229 230 extern HTFormat HTAnchor_format(HTParentAnchor *me); 231 232 extern void HTAnchor_setIndex(HTParentAnchor *me, 233 const char *address); 234 235 extern void HTAnchor_setPrompt(HTParentAnchor *me, 236 const char *prompt); 237 238 extern BOOL HTAnchor_isIndex(HTParentAnchor *me); 239 240 extern BOOL HTAnchor_isISMAPScript(HTAnchor * me); 241 242 #if defined(USE_COLOR_STYLE) 243 extern const char *HTAnchor_style(HTParentAnchor *me); 244 245 extern void HTAnchor_setStyle(HTParentAnchor *me, 246 const char *style); 247 #endif 248 249 /* Title handling. 250 */ 251 extern const char *HTAnchor_title(HTParentAnchor *me); 252 253 extern void HTAnchor_setTitle(HTParentAnchor *me, 254 const char *title); 255 256 extern void HTAnchor_appendTitle(HTParentAnchor *me, 257 const char *title); 258 259 /* Bookmark handling. 260 */ 261 extern const char *HTAnchor_bookmark(HTParentAnchor *me); 262 263 extern void HTAnchor_setBookmark(HTParentAnchor *me, 264 const char *bookmark); 265 266 /* Owner handling. 267 */ 268 extern const char *HTAnchor_owner(HTParentAnchor *me); 269 270 extern void HTAnchor_setOwner(HTParentAnchor *me, 271 const char *owner); 272 273 /* TITLE handling in LINKs with REV="made" or REV="owner". - FM 274 */ 275 extern const char *HTAnchor_RevTitle(HTParentAnchor *me); 276 277 extern void HTAnchor_setRevTitle(HTParentAnchor *me, 278 const char *title); 279 280 /* Citehost for bibp links from LINKs with REL="citehost". - RDC 281 */ 282 extern const char *HTAnchor_citehost(HTParentAnchor *me); 283 284 extern void HTAnchor_setCitehost(HTParentAnchor *me, 285 const char *citehost); 286 287 /* Suggested filename handling. - FM 288 * (will be loaded if we had a Content-Disposition 289 * header or META element with filename=name.suffix) 290 */ 291 extern const char *HTAnchor_SugFname(HTParentAnchor *me); 292 293 /* HTTP Headers. 294 */ 295 extern const char *HTAnchor_http_headers(HTParentAnchor *me); 296 297 /* Content-Type handling (parameter list). 298 */ 299 extern const char *HTAnchor_content_type_params(HTParentAnchor *me); 300 301 /* Content-Type handling. - FM 302 */ 303 extern const char *HTAnchor_content_type(HTParentAnchor *me); 304 305 /* Content-Encoding handling. - FM 306 * (will be loaded if we had a Content-Encoding 307 * header.) 308 */ 309 extern const char *HTAnchor_content_encoding(HTParentAnchor *me); 310 311 /* Last-Modified header handling. - FM 312 */ 313 extern const char *HTAnchor_last_modified(HTParentAnchor *me); 314 315 /* Date header handling. - FM 316 */ 317 extern const char *HTAnchor_date(HTParentAnchor *me); 318 319 /* Server header handling. - FM 320 */ 321 extern const char *HTAnchor_server(HTParentAnchor *me); 322 323 /* Safe header handling. - FM 324 */ 325 extern BOOL HTAnchor_safe(HTParentAnchor *me); 326 327 /* Content-Base header handling. - FM 328 */ 329 extern const char *HTAnchor_content_base(HTParentAnchor *me); 330 331 /* Content-Location header handling. - FM 332 */ 333 extern const char *HTAnchor_content_location(HTParentAnchor *me); 334 335 /* Message-ID, used for mail replies - kw 336 */ 337 extern const char *HTAnchor_messageID(HTParentAnchor *me); 338 339 extern BOOL HTAnchor_setMessageID(HTParentAnchor *me, 340 const char *messageid); 341 342 /* Subject, used for mail replies - kw 343 */ 344 extern const char *HTAnchor_subject(HTParentAnchor *me); 345 346 extern BOOL HTAnchor_setSubject(HTParentAnchor *me, 347 const char *subject); 348 349 /* Manipulation of links 350 * --------------------- 351 */ 352 extern HTAnchor *HTAnchor_followLink(HTChildAnchor *me); 353 354 extern HTAnchor *HTAnchor_followTypedLink(HTChildAnchor *me, 355 HTLinkType *type); 356 357 /* Read and write methods 358 * ---------------------- 359 */ 360 extern HTList *HTAnchor_methods(HTParentAnchor *me); 361 362 /* Protocol 363 * -------- 364 */ 365 extern void *HTAnchor_protocol(HTParentAnchor *me); 366 367 extern void HTAnchor_setProtocol(HTParentAnchor *me, 368 void *protocol); 369 370 /* Physical address 371 * ---------------- 372 */ 373 extern char *HTAnchor_physical(HTParentAnchor *me); 374 375 extern void HTAnchor_setPhysical(HTParentAnchor *me, 376 char *protocol); 377 378 extern LYUCcharset *HTAnchor_getUCInfoStage(HTParentAnchor *me, 379 int which_stage); 380 381 extern int HTAnchor_getUCLYhndl(HTParentAnchor *me, 382 int which_stage); 383 384 extern LYUCcharset *HTAnchor_setUCInfoStage(HTParentAnchor *me, 385 int LYhndl, 386 int which_stage, 387 int set_by); 388 389 extern LYUCcharset *HTAnchor_setUCInfoStage(HTParentAnchor *me, 390 int LYhndl, 391 int which_stage, 392 int set_by); 393 394 extern LYUCcharset *HTAnchor_resetUCInfoStage(HTParentAnchor *me, 395 int LYhndl, 396 int which_stage, 397 int set_by); 398 399 extern LYUCcharset *HTAnchor_copyUCInfoStage(HTParentAnchor *me, 400 int to_stage, 401 int from_stage, 402 int set_by); 403 404 extern void ImageMapList_free(HTList *list); 405 406 #ifdef __cplusplus 407 } 408 #endif 409 #endif /* HTANCHOR_H */ 410