Annotation of libwww/Library/src/HTProfil.c, revision 2.30

2.1       frystyk     1: /*
                      2: **     APPLICATION PROFILES INITALIZATION
                      3: **
                      4: **     (c) COPYRIGHT MIT 1995.
                      5: **     Please first read the full copyright statement in the file COPYRIGH.
2.30    ! kahan       6: **     @(#) $Id: HTProfil.c,v 2.29 1999/04/12 20:34:02 frystyk Exp $
2.1       frystyk     7: **
                      8: **     Defines a set of application profiles
                      9: */
                     10: 
                     11: /* Library include files */
2.18      frystyk    12: #include "wwwsys.h"
2.1       frystyk    13: #include "WWWUtil.h"
                     14: #include "WWWCore.h"
2.6       frystyk    15: #include "WWWCache.h"
2.25      frystyk    16: #include "WWWStream.h"
2.27      frystyk    17: #include "HTInit.h"
2.1       frystyk    18: #include "HTProfil.h"                                   /* Implemented here */
                     19: 
                     20: PRIVATE HTList * converters = NULL;
2.13      frystyk    21: PRIVATE HTList * transfer_encodings = NULL;
                     22: PRIVATE HTList * content_encodings = NULL;
2.1       frystyk    23: PRIVATE BOOL preemptive = NO;
                     24: 
                     25: /* ------------------------------------------------------------------------- */
                     26: 
                     27: PUBLIC void HTProfile_delete (void)
                     28: {
2.4       eric       29:     if (!preemptive) HTEventTerminate();
2.1       frystyk    30:     if (HTLib_isInitialized()) {
2.6       frystyk    31: 
                     32:        /* Clean up the persistent cache (if any) */
2.7       frystyk    33:        HTCacheTerminate();
2.6       frystyk    34: 
                     35:        /* Clean up all the global preferences */
2.1       frystyk    36:        HTFormat_deleteAll();
2.24      frystyk    37: 
2.25      frystyk    38:        /* The following lists have been cleaned up by HTFormat_deleteAll */
                     39:        transfer_encodings = 0;
                     40:        content_encodings = 0;
                     41:        converters = 0;
                     42: 
                     43:        /* Remove bindings between suffixes, media types */
                     44:        HTBind_deleteAll();
2.6       frystyk    45: 
                     46:        /* Terminate libwww */
2.1       frystyk    47:        HTLibTerminate();
                     48:     }
                     49: }
                     50: 
2.7       frystyk    51: PRIVATE void client_profile (const char * AppName, const char * AppVersion,
2.21      frystyk    52:                             BOOL preemptive, BOOL cache, BOOL HTMLParser)
2.1       frystyk    53: {
                     54:     /* If the Library is not already initialized then do it */
                     55:     if (!HTLib_isInitialized()) HTLibInit(AppName, AppVersion);
                     56: 
2.16      frystyk    57:     /* Register the default set of messages and dialog functions */
                     58:     HTAlertInit();
                     59:     HTAlert_setInteractive(YES);
                     60: 
2.1       frystyk    61:     if (!converters) converters = HTList_new();
2.13      frystyk    62:     if (!transfer_encodings) transfer_encodings = HTList_new();
                     63:     if (!content_encodings) content_encodings = HTList_new();
2.1       frystyk    64: 
                     65:     /* Register the default set of transport protocols */
                     66:     HTTransportInit();
                     67: 
2.7       frystyk    68:     /* Register the default set of application protocol modules */
                     69:     if (preemptive)
                     70:        HTProtocolPreemptiveInit();
                     71:     else
                     72:        HTProtocolInit();
                     73: 
2.25      frystyk    74:     /* Initialize suffix bindings for local files */
                     75:     HTBind_init();
                     76: 
2.19      frystyk    77:     /* Set max number of sockets we want open simultanously */ 
2.23      frystyk    78:     HTNet_setMaxSocket(32);
2.19      frystyk    79: 
2.14      frystyk    80:     /* The persistent cache does not work in preemptive mode */
2.17      frystyk    81:     if (cache) HTCacheInit(NULL, 20);
2.1       frystyk    82: 
                     83:     /* Register the default set of BEFORE and AFTER filters */
                     84:     HTNetInit();
2.6       frystyk    85: 
2.1       frystyk    86:     /* Set up the default set of Authentication schemes */
                     87:     HTAAInit();
                     88: 
                     89:     /* Get any proxy or gateway environment variables */
                     90:     HTProxy_getEnvVar();
                     91: 
                     92:     /* Register the default set of converters */
                     93:     HTConverterInit(converters);
2.21      frystyk    94: 
                     95:     /* Register the default libwww HTML parser */
                     96:     if (HTMLParser) HTMLInit(converters);
                     97: 
                     98:     /* Set the convertes as global converters for all requests */
2.1       frystyk    99:     HTFormat_setConversion(converters);
                    100: 
                    101:     /* Register the default set of transfer encoders and decoders */
2.13      frystyk   102:     HTTransferEncoderInit(transfer_encodings);
                    103:     HTFormat_setTransferCoding(transfer_encodings);
2.1       frystyk   104: 
2.13      frystyk   105:     /* Register the default set of content encoders and decoders */
                    106:     HTContentEncoderInit(content_encodings);
                    107:     if (HTList_count(content_encodings) > 0)
                    108:        HTFormat_setContentCoding(content_encodings);
                    109:     else {
                    110:        HTList_delete(content_encodings);
                    111:        content_encodings = NULL;
                    112:     }
                    113: 
2.1       frystyk   114:     /* Register the default set of MIME header parsers */
                    115:     HTMIMEInit();
                    116: 
                    117:     /* Register the default set of file suffix bindings */
                    118:     HTFileInit();
                    119: 
                    120:     /* Register the default set of Icons for directory listings */
                    121:     HTIconInit(NULL);
                    122: }
                    123: 
                    124: PUBLIC void HTProfile_newClient (const char * AppName, const char * AppVersion)
2.4       eric      125: {
2.5       frystyk   126:     /* Do the default setup */
2.21      frystyk   127:     client_profile(AppName, AppVersion, NO, YES, NO);
                    128: 
                    129:     /* Set up default event loop */
                    130:     HTEventInit();
                    131: }
                    132: 
                    133: PUBLIC void HTProfile_newHTMLClient (const char * AppName, const char * AppVersion)
                    134: {
                    135:     /* Do the default setup */
                    136:     client_profile(AppName, AppVersion, NO, YES, YES);
2.5       frystyk   137: 
                    138:     /* Set up default event loop */
2.4       eric      139:     HTEventInit();
2.1       frystyk   140: }
                    141: 
                    142: PUBLIC void HTProfile_newPreemptiveClient (const char * AppName,
                    143:                                           const char * AppVersion)
                    144: {
2.5       frystyk   145:     /* Do the default setup */
2.21      frystyk   146:     client_profile(AppName, AppVersion, YES, NO, NO);
2.1       frystyk   147: 
2.30    ! kahan     148:     /* Set up default event loop */
2.26      frystyk   149:     HTEventInit();
2.1       frystyk   150:     /* Remember that we are loading preemptively */
                    151:     preemptive = YES;
2.17      frystyk   152: }
                    153: 
                    154: PUBLIC void HTProfile_newNoCacheClient (const char * AppName,
                    155:                                        const char * AppVersion)
                    156: {
                    157:     /* Do the default setup */
2.21      frystyk   158:     client_profile(AppName, AppVersion, NO, NO, NO);
                    159: 
                    160:     /* Set up default event loop */
                    161:     HTEventInit();
                    162: }
                    163: 
                    164: PUBLIC void HTProfile_newHTMLNoCacheClient (const char * AppName,
                    165:                                            const char * AppVersion)
                    166: {
                    167:     /* Do the default setup */
                    168:     client_profile(AppName, AppVersion, NO, NO, YES);
2.17      frystyk   169: 
                    170:     /* Set up default event loop */
                    171:     HTEventInit();
2.1       frystyk   172: }
                    173: 
                    174: PRIVATE void robot_profile (const char * AppName, const char * AppVersion)
                    175: {
                    176:     /* If the Library is not already initialized then do it */
                    177:     if (!HTLib_isInitialized()) HTLibInit(AppName, AppVersion);
                    178: 
                    179:     if (!converters) converters = HTList_new();
2.13      frystyk   180:     if (!transfer_encodings) transfer_encodings = HTList_new();
                    181:     if (!content_encodings) content_encodings = HTList_new();
2.1       frystyk   182: 
                    183:     /* Register the default set of transport protocols */
                    184:     HTTransportInit();
                    185: 
                    186:     /* Register the default set of application protocol modules */
                    187:     HTProtocolInit();
2.25      frystyk   188: 
                    189:     /* Initialize suffix bindings for local files */
                    190:     HTBind_init();
2.1       frystyk   191: 
                    192:     /* Set max number of sockets we want open simultanously */ 
2.23      frystyk   193:     HTNet_setMaxSocket(32);
2.1       frystyk   194: 
                    195:     /* Register some default set of BEFORE and AFTER filters */
2.10      frystyk   196:     HTNet_addBefore(HTRuleFilter, NULL, NULL, HT_FILTER_MIDDLE); 
                    197:     HTNet_addBefore(HTProxyFilter, NULL, NULL, HT_FILTER_MIDDLE); 
                    198:     HTNet_addAfter(HTInfoFilter, NULL, NULL, HT_ALL, HT_FILTER_LATE); 
2.1       frystyk   199: 
                    200:     /* Get any proxy or gateway environment variables */
                    201:     HTProxy_getEnvVar();
                    202: 
                    203:     /* Register the default set of converters including the HTML parser */
                    204:     HTConverterInit(converters);
2.21      frystyk   205:     HTMLInit(converters);
                    206: 
                    207:     /* Set the convertes as global converters for all requests */
2.1       frystyk   208:     HTFormat_setConversion(converters);
2.13      frystyk   209: 
2.1       frystyk   210:     /* Register the default set of transfer encoders and decoders */
2.13      frystyk   211:     HTTransferEncoderInit(transfer_encodings);
                    212:     HTFormat_setTransferCoding(transfer_encodings);
2.1       frystyk   213: 
2.13      frystyk   214:     /* Register the default set of content encoders and decoders */
                    215:     HTContentEncoderInit(content_encodings);
                    216:     if (HTList_count(content_encodings) > 0)
                    217:        HTFormat_setContentCoding(content_encodings);
                    218:     else {
                    219:        HTList_delete(content_encodings);
                    220:        content_encodings = NULL;
                    221:     }
                    222: 
2.1       frystyk   223:     /* Register the default set of MIME header parsers */
                    224:     HTMIMEInit();
                    225: 
                    226:     /* Register the default set of file suffix bindings */
                    227:     HTFileInit();
                    228: 
                    229:     /* Register the default set of Icons for directory listings */
                    230:     HTIconInit(NULL);
                    231: 
                    232:     /* Register some default messages and dialog functions */
                    233:     if (HTAlert_interactive()) {
                    234:        HTAlert_add(HTError_print, HT_A_MESSAGE);
                    235:        HTAlert_add(HTConfirm, HT_A_CONFIRM);
                    236:        HTAlert_add(HTPrompt, HT_A_PROMPT);
                    237:        HTAlert_add(HTPromptPassword, HT_A_SECRET);
                    238:        HTAlert_add(HTPromptUsernameAndPassword, HT_A_USER_PW);
                    239:     }
                    240:     HTAlert_setInteractive(YES);
                    241: }
                    242: 
                    243: PUBLIC void HTProfile_newRobot (const char * AppName, const char * AppVersion)
                    244: {    
2.4       eric      245:   /* set up default event loop */
                    246:     HTEventInit();
2.1       frystyk   247:     robot_profile(AppName, AppVersion);
                    248: 
                    249:     /* Register the default set of application protocol modules */
                    250:     HTProtocolInit();
                    251: }
                    252: 
                    253: PUBLIC void HTProfile_newPreemptiveRobot (const char * AppName,
                    254:                                          const char * AppVersion)
                    255: {
                    256:     robot_profile(AppName, AppVersion);
                    257: 
                    258:     /* Register the default set of application protocol modules */
                    259:     HTProtocolPreemptiveInit();
                    260: 
                    261:     /* Remember that we are loading preemptively */
                    262:     preemptive = YES;
                    263: }
                    264: 
                    265: 
                    266: 
                    267: 
                    268: 
                    269: 
                    270: 

Webmaster