HTAABrow.h
上传用户:zlh9724
上传日期:2007-01-04
资源大小:1991k
文件大小:7k
源码类别:

浏览器

开发平台:

Unix_Linux

  1. /*                                                                   Browser side Access Auth
  2.                          BROWSER SIDE ACCESS AUTHORIZATION MODULE
  3.                                              
  4.  */
  5. /*
  6. **      (c) COPYRIGHT MIT 1995.
  7. **      Please first read the full copyright statement in the file COPYRIGH.
  8. */
  9. /*
  10.    This module is the browser side interface to Access Authorization (AA) package.  It
  11.    contains code only for browser.
  12.    
  13.    Important to know about memory allocation:
  14.    
  15.    Routines in this module use dynamic allocation, but free automatically all the memory
  16.    reserved by them.
  17.    
  18.    Therefore the caller never has to (and never should) free() any object returned by
  19.    these functions.
  20.    
  21.    Therefore also all the strings returned by this package are only valid until the next
  22.    call to the same function is made. This approach is selected, because of the nature of
  23.    access authorization: no string returned by the package needs to be valid longer than
  24.    until the next call.
  25.    
  26.    This also makes it easy to plug the AA package in: you don't have to ponder whether to
  27.    free() something here or is it done somewhere else (because it is always done somewhere
  28.    else).
  29.    
  30.    The strings that the package needs to store are copied so the original strings given as
  31.    parameters to AA functions may be freed or modified with no side effects.
  32.    
  33.    Also note: The AA package does not free() anything else than what it has itself
  34.    allocated.
  35.    
  36.    This module is implemented by HTAABrow.c, and it is a part of the W3C Reference
  37.    Library.
  38.    
  39.  */
  40. #ifndef HTAABROW_H
  41. #define HTAABROW_H
  42. #include "HTAAUtil.h"
  43. #include "HTList.h"
  44. #include "HTAssoc.h"
  45. #include "HTReq.h"
  46. /*
  47. ** Local datatype definitions
  48. **
  49. ** HTAAServer contains all the information about one server.
  50. */
  51. typedef struct _HTAAServer {
  52.     char *      hostname;       /* Host's name                  */
  53.     int         portnumber;     /* Port number                  */
  54.     HTList *    setups;         /* List of protection setups    */
  55.                                 /* on this server; i.e. valid   */
  56.                                 /* authentication schemes and   */
  57.                                 /* templates when to use them.  */
  58.                                 /* This is actually a list of   */
  59.                                 /* HTAASetup objects.           */
  60.     HTList *    realms;         /* Information about passwords  */
  61. } HTAAServer;
  62. /*
  63. ** HTAASetup contains information about one server's one
  64. ** protected tree of documents.
  65. */
  66. typedef struct _HTAASetup {
  67.     HTAAServer *server;         /* Which server serves this tree             */
  68.     char *      tmplate;        /* Template for this tree                    */
  69.     HTList *    valid_schemes;  /* Valid authentic.schemes                   */
  70.     HTAssocList**scheme_specifics;/* Scheme specific params                  */
  71.     BOOL        reprompt;       /* Failed last time -- reprompt (or whatever)*/
  72. } HTAASetup;
  73. /*
  74. ** Information about usernames and passwords in
  75. ** Basic and Pubkey authentication schemes;
  76. */
  77. typedef struct _HTAARealm {
  78.     char *      realmname;      /* Password domain name         */
  79.     char *      username;       /* Username in that domain      */
  80.     char *      password;       /* Corresponding password       */
  81. } HTAARealm;
  82. /*
  83. Routines for Browser Side Recording of AA Info
  84.    Most of the browser-side AA is done by the following two functions (which are called
  85.    from file HTTP.c so the browsers using libwww only need to be linked with the new
  86.    library and not be changed at all):
  87.    
  88.       HTAA_composeAuth() composes the Authorization: line contents, if the AA package
  89.       thinks that the given document is protected. Otherwise this function returns NULL.
  90.       This function also calls the functions HTPrompt(),HTPromptPassword() and HTConfirm()
  91.       to get the username, password and some confirmation from the user.
  92.       
  93.       HTAA_shouldRetryWithAuth() determines whether to retry the request with AA or with a
  94.       new AA (in case username or password was misspelled).
  95.       
  96.  */
  97. /* BROWSER PUBLIC                                       HTAA_composeAuth()
  98. **
  99. **      COMPOSE Authorization: HEADER LINE CONTENTS
  100. **      IF WE ALREADY KNOW THAT THE HOST REQUIRES AUTHENTICATION
  101. **
  102. ** ON ENTRY:
  103. **      req             request, which contains
  104. **      req->argument   document, that we're trying to access.
  105. **      req->setup      protection setup info on browser.
  106. **      req->scheme     selected authentication scheme.
  107. **      req->realm      for Basic scheme the username and password.
  108. **
  109. ** ON EXIT:
  110. **      returns NO, if no authorization seems to be needed, and
  111. **              req->authorization is NULL.
  112. **              YES, if it has composed Authorization field,
  113. **              in which case the result is in req->authorization,
  114. **              e.g.
  115. **
  116. **                 "Basic AkRDIhEF8sdEgs72F73bfaS=="
  117. */
  118. extern BOOL HTAA_composeAuth (HTRequest * req);
  119. /* BROWSER PUBLIC                                       HTAA_retryWithAuth()
  120. **
  121. **              RETRY THE SERVER WITH AUTHORIZATION (OR IF
  122. **              ALREADY RETRIED, WITH A DIFFERENT USERNAME
  123. **              AND/OR PASSWORD (IF MISSPELLED)) OR CANCEL
  124. ** ON ENTRY:
  125. **      req             request.
  126. **      req->valid_schemes
  127. **                      This function should only be called when
  128. **                      server has replied with a 401 (Unauthorized)
  129. **                      status code, and req structure has been filled
  130. **                      up according to server reply, especially the
  131. **                      req->valid_shemes list must have been set up
  132. **                      according to WWW-Authenticate: headers.
  133. **      callback        the function to call when username and
  134. **                      password have been entered (HTLoadHTTP()).
  135. ** ON EXIT:
  136. **      On GUI clients pops up a username/password dialog box
  137. **      with "Ok" and "Cancel".
  138. **      "Ok" button press should do a callback
  139. **
  140. **              HTLoadHTTP(req);
  141. **
  142. **      This actually done by function HTPasswordDialog(),
  143. **      which GUI clients redefine.
  144. **
  145. **      returns         YES, if dialog box was popped up.
  146. **                      NO, on failure.
  147. */
  148. extern BOOL HTAA_retryWithAuth (HTRequest *     req);
  149. /*
  150. Enabling Gateway httpds to Forward Authorization
  151.    These functions should only be called from daemon code, and HTAAForwardAuth_reset()
  152.    must be called before the next request is handled to make sure that authorization
  153.    string isn't cached in daemon so that other people can access private files using
  154.    somebody elses previous authorization information.
  155.    
  156.  */
  157. extern void HTAAForwardAuth_set (CONST char * scheme_name,
  158.                                  CONST char * scheme_specifics);
  159. extern void HTAAForwardAuth_reset (void);
  160. /*
  161. Setup HTTP access authentication
  162.  */
  163. extern BOOL HTAA_authentication (HTRequest * request);
  164. /*
  165.  */
  166. #endif  /* NOT HTAABROW_H */
  167. /*
  168.    End of file HTAABrow.h. */