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

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.26    ! frystyk     6: **     @(#) $Id: HTProfil.c,v 2.25 1999/02/07 18:31:24 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: 
2.26    ! frystyk   147:     /* On windows we need the initialization anyway */
        !           148: #ifdef WWW_WIN_ASYNC
        !           149:     HTEventInit();
        !           150: #else
2.1       frystyk   151:     /* Remember that we are loading preemptively */
                    152:     preemptive = YES;
2.26    ! frystyk   153: #endif
        !           154: 
2.17      frystyk   155: }
                    156: 
                    157: PUBLIC void HTProfile_newNoCacheClient (const char * AppName,
                    158:                                        const char * AppVersion)
                    159: {
                    160:     /* Do the default setup */
2.21      frystyk   161:     client_profile(AppName, AppVersion, NO, NO, NO);
                    162: 
                    163:     /* Set up default event loop */
                    164:     HTEventInit();
                    165: }
                    166: 
                    167: PUBLIC void HTProfile_newHTMLNoCacheClient (const char * AppName,
                    168:                                            const char * AppVersion)
                    169: {
                    170:     /* Do the default setup */
                    171:     client_profile(AppName, AppVersion, NO, NO, YES);
2.17      frystyk   172: 
                    173:     /* Set up default event loop */
                    174:     HTEventInit();
2.1       frystyk   175: }
                    176: 
                    177: PRIVATE void robot_profile (const char * AppName, const char * AppVersion)
                    178: {
                    179:     /* If the Library is not already initialized then do it */
                    180:     if (!HTLib_isInitialized()) HTLibInit(AppName, AppVersion);
                    181: 
                    182:     if (!converters) converters = HTList_new();
2.13      frystyk   183:     if (!transfer_encodings) transfer_encodings = HTList_new();
                    184:     if (!content_encodings) content_encodings = HTList_new();
2.1       frystyk   185: 
                    186:     /* Register the default set of transport protocols */
                    187:     HTTransportInit();
                    188: 
                    189:     /* Register the default set of application protocol modules */
                    190:     HTProtocolInit();
2.25      frystyk   191: 
                    192:     /* Initialize suffix bindings for local files */
                    193:     HTBind_init();
2.1       frystyk   194: 
                    195:     /* Set max number of sockets we want open simultanously */ 
2.23      frystyk   196:     HTNet_setMaxSocket(32);
2.1       frystyk   197: 
                    198:     /* Register some default set of BEFORE and AFTER filters */
2.10      frystyk   199:     HTNet_addBefore(HTRuleFilter, NULL, NULL, HT_FILTER_MIDDLE); 
                    200:     HTNet_addBefore(HTProxyFilter, NULL, NULL, HT_FILTER_MIDDLE); 
                    201:     HTNet_addAfter(HTInfoFilter, NULL, NULL, HT_ALL, HT_FILTER_LATE); 
2.1       frystyk   202: 
                    203:     /* Get any proxy or gateway environment variables */
                    204:     HTProxy_getEnvVar();
                    205: 
                    206:     /* Register the default set of converters including the HTML parser */
                    207:     HTConverterInit(converters);
2.21      frystyk   208:     HTMLInit(converters);
                    209: 
                    210:     /* Set the convertes as global converters for all requests */
2.1       frystyk   211:     HTFormat_setConversion(converters);
2.13      frystyk   212: 
2.1       frystyk   213:     /* Register the default set of transfer encoders and decoders */
2.13      frystyk   214:     HTTransferEncoderInit(transfer_encodings);
                    215:     HTFormat_setTransferCoding(transfer_encodings);
2.1       frystyk   216: 
2.13      frystyk   217:     /* Register the default set of content encoders and decoders */
                    218:     HTContentEncoderInit(content_encodings);
                    219:     if (HTList_count(content_encodings) > 0)
                    220:        HTFormat_setContentCoding(content_encodings);
                    221:     else {
                    222:        HTList_delete(content_encodings);
                    223:        content_encodings = NULL;
                    224:     }
                    225: 
2.1       frystyk   226:     /* Register the default set of MIME header parsers */
                    227:     HTMIMEInit();
                    228: 
                    229:     /* Register the default set of file suffix bindings */
                    230:     HTFileInit();
                    231: 
                    232:     /* Register the default set of Icons for directory listings */
                    233:     HTIconInit(NULL);
                    234: 
                    235:     /* Register some default messages and dialog functions */
                    236:     if (HTAlert_interactive()) {
                    237:        HTAlert_add(HTError_print, HT_A_MESSAGE);
                    238:        HTAlert_add(HTConfirm, HT_A_CONFIRM);
                    239:        HTAlert_add(HTPrompt, HT_A_PROMPT);
                    240:        HTAlert_add(HTPromptPassword, HT_A_SECRET);
                    241:        HTAlert_add(HTPromptUsernameAndPassword, HT_A_USER_PW);
                    242:     }
                    243:     HTAlert_setInteractive(YES);
                    244: }
                    245: 
                    246: PUBLIC void HTProfile_newRobot (const char * AppName, const char * AppVersion)
                    247: {    
2.4       eric      248:   /* set up default event loop */
                    249:     HTEventInit();
2.1       frystyk   250:     robot_profile(AppName, AppVersion);
                    251: 
                    252:     /* Register the default set of application protocol modules */
                    253:     HTProtocolInit();
                    254: }
                    255: 
                    256: PUBLIC void HTProfile_newPreemptiveRobot (const char * AppName,
                    257:                                          const char * AppVersion)
                    258: {
                    259:     robot_profile(AppName, AppVersion);
                    260: 
                    261:     /* Register the default set of application protocol modules */
                    262:     HTProtocolPreemptiveInit();
                    263: 
                    264:     /* Remember that we are loading preemptively */
                    265:     preemptive = YES;
                    266: }
                    267: 
                    268: 
                    269: 
                    270: 
                    271: 
                    272: 
                    273: 

Webmaster