HTAnchor.h
Upload User: zlh9724
Upload Date: 2007-01-04
Package Size: 1991k
Code Size: 15k
Category:

Browser Client

Development Platform:

Unix_Linux

  1. /*                                                                       Public Anchor Object
  2.                                    PUBLIC ANCHOR OBJECT
  3.                                              
  4.  */
  5. /*
  6. **      (c) COPYRIGHT MIT 1995.
  7. **      Please first read the full copyright statement in the file COPYRIGH.
  8. */
  9. /*
  10.    An anchor represents a region of a hypertext document which is linked to another anchor
  11.    in the same or a different document. As always we must emulate the fancy features of
  12.    C++ by hand :-(. In this module you find:
  13.    
  14.       Creation and deletion methods
  15.       
  16.       Manipulation of Links
  17.       
  18.       Access Methods for information
  19.       
  20.    This module is implemented by HTAnchor.c, and it is a part of the  W3C Reference
  21.    Library.
  22.    
  23.  */
  24. #ifndef HTANCHOR_H
  25. #define HTANCHOR_H
  26. #include "HTList.h"
  27. #include "HTAtom.h"
  28. #include "HTMethod.h"
  29. /*
  30. Types defined by the Anchor Object
  31.    This is a set of videly used type definitions used through out the Library:
  32.    
  33.  */
  34. typedef struct _HTLink          HTLink;
  35. typedef HTAtom * HTFormat;
  36. typedef HTAtom * HTLevel;                      /* Used to specify HTML level */
  37. typedef HTAtom * HTEncoding;                             /* Content Encoding */
  38. typedef HTAtom * HTCte;                         /* Content transfer encoding */
  39. typedef HTAtom * HTCharset;
  40. typedef HTAtom * HTLanguage;
  41. typedef struct _HTAnchor        HTAnchor;
  42. typedef struct _HTParentAnchor  HTParentAnchor;
  43. typedef struct _HTChildAnchor   HTChildAnchor;
  44. /*
  45. The Link Object
  46.    Anchors are bound together using link objects. Each anchor can be the source or
  47.    destination of zero, one, or more links from and to other anchors.
  48.    
  49.   LINK DESTINATION
  50.   
  51.  */
  52. extern BOOL HTLink_setDestination (HTLink * link, HTAnchor * dest);
  53. extern HTAnchor * HTLink_destination (HTLink * link);
  54. /*
  55.   LINK RESULT
  56.   
  57.    When a link has been used for posting an object from a source to a destination link,
  58.    the result of the operation is stored as part of the link information.
  59.    
  60.  */
  61. typedef enum _HTLinkResult {
  62.     HT_LINK_INVALID = -1,
  63.     HT_LINK_NONE = 0,
  64.     HT_LINK_ERROR,
  65.     HT_LINK_OK
  66. } HTLinkResult;
  67. extern BOOL HTLink_setResult (HTLink * link, HTLinkResult result);
  68. extern HTLinkResult HTLink_result (HTLink * link);
  69. /*
  70.   LINK METHOD
  71.   
  72.    The method used in a link can be PUT, or POST, for example
  73.    
  74.  */
  75. extern BOOL HTLink_setMethod (HTLink * link, HTMethod method);
  76. extern HTMethod HTLink_method (HTLink * link);
  77. /*
  78.   LINK TYPE
  79.   
  80.    This is used for typed links.
  81.    
  82.  */
  83. typedef HTAtom * HTLinkType;
  84. extern BOOL HTLink_setType (HTLink * link, HTLinkType type);
  85. extern HTLinkType HTLink_type (HTLink * link);
  86. /*
  87. Relations between Links and Anchors
  88.   LINK THIS ANCHOR TO ANOTHER GIVEN ONE
  89.   
  90.    A single anchor may have many outgoing links of which the default is the main link. If
  91.    one already exists then this new link is simply added to the list.
  92.    
  93.  */
  94. extern BOOL HTAnchor_link       (HTAnchor *     source,
  95.                                  HTAnchor *     destination,
  96.                                  HTLinkType     type,
  97.                                  HTMethod       method);
  98. /*
  99.   FIND THE LINK OBJECT THAT BINDS TWO ANCHORS
  100.   
  101.    If the destination anchor is a target of a link from the source anchor then return the
  102.    link object, else NULL.
  103.    
  104.  */
  105. extern HTLink * HTAnchor_findLink (HTAnchor *src, HTAnchor *dest);
  106. /*
  107.   FIND DESTINATION WITH GIVEN RELATIONSHIP
  108.   
  109.    Return the anchor with a given typed link.
  110.    
  111.  */
  112. extern HTAnchor * HTAnchor_followTypedLink (HTAnchor *me, HTLinkType type);
  113. /*
  114.   HANDLING THE MAIN LINK
  115.   
  116.    Any outgoing link can at any time be the main destination.
  117.    
  118.  */
  119. extern BOOL HTAnchor_setMainLink        (HTAnchor * anchor, HTLink * link);
  120. extern HTLink * HTAnchor_mainLink       (HTAnchor * anchor);
  121. extern HTAnchor * HTAnchor_followMainLink (HTAnchor * anchor);
  122. /*
  123.   HANDLING THE SUB LINKS
  124.   
  125.  */
  126. extern BOOL HTAnchor_setSubLinks        (HTAnchor * anchor, HTList * list);
  127. extern HTList * HTAnchor_subLinks       (HTAnchor * anchor);
  128. /*
  129.   MOVE LINK INFORMATION
  130.   
  131.    Move all link information form one anchor to another. This is useful when we get a
  132.    redirection on a request and want to inherit the link information to the new anchor and
  133.    change the link information in the old one to "redirect".
  134.    
  135.  */
  136. extern BOOL HTAnchor_moveAllLinks       (HTAnchor *src, HTAnchor *dest);
  137. /*
  138.   REMOVE LINK INFORMATION
  139.   
  140.    Delete link information between two or more anchors
  141.    
  142.  */
  143. extern BOOL HTAnchor_removeLink         (HTAnchor *src, HTAnchor *dest);
  144. extern BOOL HTAnchor_removeAllLinks     (HTAnchor * me);
  145. /*
  146.   MOVE A CHILD ANCHOR TO THE HEAD OF THE LIST OF ITS SIBLINGS
  147.   
  148.    This is to ensure that an anchor which might have already existed is put in the correct
  149.    order as we load the document.
  150.    
  151.  */
  152. extern void HTAnchor_makeLastChild      (HTChildAnchor *me);
  153. /*
  154. Anchor Objects
  155.    We have three variants of the Anchor object - I guess some would call them superclass
  156.    and subclasses ;-)
  157.    
  158.   GENERIC ANCHOR TYPE
  159.   
  160.    This is the super class of anchors. We often use this as an argument to the functions
  161.    that both accept parent anchors and child anchors. We separate the first link from the
  162.    others to avoid too many small mallocs involved by a list creation. Most anchors only
  163.    point to one place.
  164.    
  165.   ANCHOR FOR A PARENT OBJECT
  166.   
  167.    These anchors points to the whole contents of a graphic object (document). The parent
  168.    anchor of a parent anchor is itself. The parent anchor now contains all meta
  169.    information about the object. This is largely the entity headers in the HTTP
  170.    specification.
  171.    
  172.   ANCHOR FOR A CHILD OBJECT
  173.   
  174.    A child anchor is a anchor object that points to a subpart of a graphic object
  175.    (document)
  176.    
  177. Creation and Deletion Methods
  178.    After we have defined the data structures we must define the methods that can be used
  179.    on them. All anchors are kept in an internal hash table so that they are easier to find
  180.    again.
  181.    
  182.   FIND/CREATE A PARENT ANCHOR
  183.   
  184.    This one is for a reference (link) which is found in a document, and might not be
  185.    already loaded. The parent anchor returned can either be created on the spot or is
  186.    already in the hash table.
  187.    
  188.  */
  189. extern HTAnchor * HTAnchor_findAddress          (CONST char * address);
  190. /*
  191.   FIND/CREATE A CHILD ANCHOR
  192.   
  193.    This one is for a new child anchor being edited into an existing document. The parent
  194.    anchor must already exist but the child returned can either be created on the spot or
  195.    is already in the hash table. The tag is the part that's after the '#' sign in a URI.
  196.    
  197.  */
  198. extern HTChildAnchor * HTAnchor_findChild       (HTParentAnchor *parent,
  199.                                                  CONST char *   tag);
  200. /*
  201.   FIND/CREATE A CHILD ANCHOR AND LINK TO ANOTHER PARENT
  202.   
  203.    Find a child anchor anchor with a given parent and possibly a tag, and (if passed) link
  204.    this child to the URI given in the href. As we really want typed links to the caller
  205.    should also indicate what the type of the link is (see HTTP spec for more information).
  206.    The link is relative to the address of the parent anchor.
  207.    
  208.  */
  209. extern HTChildAnchor * HTAnchor_findChildAndLink
  210.                 (HTParentAnchor * parent,               /* May not be 0 */
  211.                 CONST char * tag,                       /* May be "" or 0 */
  212.                 CONST char * href,                      /* May be "" or 0 */
  213.                 HTLinkType ltype);                      /* May be 0 */
  214. /*
  215.   DELETE AN ANCHOR
  216.   
  217.    All outgoing links from parent and children are deleted, and this anchor is removed
  218.    from the sources list of all its targets. We also delete the targets. If this anchor's
  219.    source list is empty, we delete it and its children.
  220.    
  221.  */
  222. extern BOOL HTAnchor_delete     (HTParentAnchor *me);
  223. /*
  224.   DELETE ALL ANCHORS
  225.   
  226.    Deletes all anchors and return a list of all the objects (hyperdoc) hanging of the
  227.    parent anchors found while doing it. The application may keep its own list of
  228.    HyperDocs, but this function returns it anyway.  It is always for the application to
  229.    delete any HyperDocs. If NULL then no hyperdocs are returned. Return YES if OK, else
  230.    NO.
  231.    
  232.    Note: This function is different from cleaning up the history list!
  233.    
  234.  */
  235. extern BOOL HTAnchor_deleteAll  (HTList * objects);
  236. /*
  237. Access Methods of an Anchor
  238.    These functions should be used to access information within the anchor structures.
  239.    
  240.   RELATIONS TO OTHER ANCHORS
  241.   
  242.     Who is Parent?
  243.     
  244.    For parent anchors this returns the anchor itself
  245.    
  246.  */
  247. extern HTParentAnchor * HTAnchor_parent (HTAnchor *me);
  248. /*
  249.     Does it have any Anchors within it?
  250.     
  251.  */
  252. extern BOOL HTAnchor_hasChildren        (HTParentAnchor *me);
  253. /*
  254.   BINDING A DATA OBJECT TO AN ANCHOR
  255.   
  256.    A parent anchor can have a data object bound to it. This data object does can for
  257.    example be a parsed version of a HTML that knows how to present itself to the user, or
  258.    it can be an unparsed data object. It's completely free for the application to use this
  259.    possibility, but a typical usage would to manage the data object as part of a memory
  260.    cache.
  261.    
  262.  */
  263. extern void HTAnchor_setDocument        (HTParentAnchor *me, void * doc);
  264. extern void * HTAnchor_document         (HTParentAnchor *me);
  265. /*
  266.   URI INFORMATION OF ANCHORS
  267.   
  268.    There are two addresses of an anchor. The URI that was passed when the anchor was
  269.    crated and the physical address that's used when the URI is going to be requested. The
  270.    two addresses may be different if the request is going through a proxy or a gateway.
  271.    
  272.     Get URI Address
  273.     
  274.    Returns the full URI of the anchor, child or parent as a malloc'd string to be freed by
  275.    the caller as when the anchor was created.
  276.    
  277.  */
  278. extern char * HTAnchor_address          (HTAnchor *me);
  279. /*
  280.   CACHE INFORMATION
  281.   
  282.    If the cache manager finds a cached object, it is registered in the anchor object. This
  283.    way the file loader knows that it is a MIME data object. The cache manager does not
  284.    know whether the data object is out of date (for example if a Expires: header is in the
  285.    MIME header. This is for the MIME parser to find out.
  286.    
  287.  */
  288. extern BOOL HTAnchor_cacheHit           (HTParentAnchor *me);
  289. extern void HTAnchor_setCacheHit        (HTParentAnchor *me, BOOL cacheHit);
  290. /*
  291.   PHYSICAL ADDRESS
  292.   
  293.    Contains the physical address after we haved looked for proxies etc.
  294.    
  295.  */
  296. extern char * HTAnchor_physical         (HTParentAnchor * me);
  297. extern void HTAnchor_setPhysical        (HTParentAnchor * me, char * protocol);
  298. /*
  299.   IS THE ANCHOR SEARCHABLE?
  300.   
  301.  */
  302. extern void HTAnchor_clearIndex         (HTParentAnchor *me);
  303. extern void HTAnchor_setIndex           (HTParentAnchor *me);
  304. extern BOOL HTAnchor_isIndex            (HTParentAnchor *me);
  305. /*
  306.   TITLE HANDLING
  307.   
  308.    We keep the title in the anchor as we then can refer to it later in the history list
  309.    etc. We can also obtain the title element if it is passed as a HTTP header in the
  310.    response. Any title element found in an HTML document will overwrite a title given in a
  311.    HTTP header.
  312.    
  313.  */
  314. extern CONST char * HTAnchor_title      (HTParentAnchor *me);
  315. extern void HTAnchor_setTitle           (HTParentAnchor *me,
  316.                                          CONST char *   title);
  317. extern void HTAnchor_appendTitle        (HTParentAnchor *me,
  318.                                          CONST char *   title);
  319. /*
  320.   MEDIA TYPES (CONTENT-TYPE)
  321.   
  322.  */
  323. extern HTFormat HTAnchor_format         (HTParentAnchor *me);
  324. extern void HTAnchor_setFormat          (HTParentAnchor *me,
  325.                                          HTFormat       form);
  326. /*
  327.   CHARSET PARAMETER TO CONTENT-TYPE
  328.   
  329.  */
  330. extern HTCharset HTAnchor_charset       (HTParentAnchor *me);
  331. extern void HTAnchor_setCharset         (HTParentAnchor *me,
  332.                                          HTCharset      charset);
  333. /*
  334.   LEVEL PARAMETER TO CONTENT-TYPE
  335.   
  336.  */
  337. extern HTLevel HTAnchor_level           (HTParentAnchor * me);
  338. extern void HTAnchor_setLevel           (HTParentAnchor * me,
  339.                                          HTLevel        level);
  340. /*
  341.   CONTENT LANGUAGE
  342.   
  343.  */
  344. extern HTLanguage HTAnchor_language     (HTParentAnchor *me);
  345. extern void HTAnchor_setLanguage        (HTParentAnchor *me,
  346.                                          HTLanguage     language);
  347. /*
  348.   CONTENT ENCODING
  349.   
  350.  */
  351. extern HTEncoding HTAnchor_encoding     (HTParentAnchor *me);
  352. extern void HTAnchor_setEncoding        (HTParentAnchor *me,
  353.                                          HTEncoding     encoding);
  354. /*
  355.   CONTENT TRANSFER ENCODING
  356.   
  357.  */
  358. extern HTCte HTAnchor_cte               (HTParentAnchor *me);
  359. extern void HTAnchor_setCte             (HTParentAnchor *me,
  360.                                          HTCte          cte);
  361. /*
  362.   CONTENT LENGTH
  363.   
  364.  */
  365. extern long int HTAnchor_length         (HTParentAnchor *me);
  366. extern void HTAnchor_setLength          (HTParentAnchor *me,
  367.                                          long int       length);
  368. /*
  369.   ALLOWED METHODS (ALLOW)
  370.   
  371.  */
  372. extern int HTAnchor_methods             (HTParentAnchor *me);
  373. extern void HTAnchor_setMethods         (HTParentAnchor *me,
  374.                                          int            methodset);
  375. extern void HTAnchor_appendMethods      (HTParentAnchor *me,
  376.                                          int            methodset);
  377. /*
  378.   VERSION
  379.   
  380.  */
  381. extern char * HTAnchor_version  (HTParentAnchor * me);
  382. extern void HTAnchor_setVersion (HTParentAnchor * me, CONST char * version);
  383. /*
  384.   DATE
  385.   
  386.    Returns the date that was registered in the RFC822 header "Date"
  387.    
  388.  */
  389. extern time_t HTAnchor_date             (HTParentAnchor * me);
  390. extern void HTAnchor_setDate            (HTParentAnchor * me, CONST time_t date);
  391. /*
  392.   LAST MODIFIED DATE
  393.   
  394.    Returns the date that was registered in the RFC822 header "Last-Modified"
  395.    
  396.  */
  397. extern time_t HTAnchor_lastModified     (HTParentAnchor * me);
  398. extern void HTAnchor_setLastModified    (HTParentAnchor * me, CONST time_t lm);
  399. /*
  400.   EXPIRES DATE
  401.   
  402.  */
  403. extern time_t HTAnchor_expires          (HTParentAnchor * me);
  404. extern void HTAnchor_setExpires         (HTParentAnchor * me, CONST time_t exp);
  405. /*
  406.   DERIVED FROM
  407.   
  408.  */
  409. extern char * HTAnchor_derived  (HTParentAnchor *me);
  410. extern void HTAnchor_setDerived (HTParentAnchor *me, CONST char *derived_from);
  411. /*
  412.   EXTRA HEADERS
  413.   
  414.    List of unknown headers coming in from the network. Do not use the HTAnchor_addExtra()
  415.    function to extra headers here, but use the field in the request structure for sending
  416.    test headers.
  417.    
  418.  */
  419. extern HTList * HTAnchor_Extra          (HTParentAnchor *me);
  420. extern void HTAnchor_addExtra           (HTParentAnchor *me,
  421.                                          CONST char *   header);
  422. /*
  423.   STATUS OF HEADER PARSING
  424.   
  425.    These are primarily for internal use
  426.    
  427.  */
  428. extern BOOL HTAnchor_headerParsed       (HTParentAnchor *me);
  429. extern void HTAnchor_setHeaderParsed    (HTParentAnchor *me);
  430. /*
  431.   WE WANT TO CLEAR THE HEADER INFORMATION...
  432.   
  433.  */
  434. extern void HTAnchor_clearHeader        (HTParentAnchor *me);
  435. #endif /* HTANCHOR_H */
  436. /*
  437.     */