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

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

Webmaster