Annotation of libwww/Library/src/HTLib.c, revision 2.1
2.1 ! frystyk 1: /*
! 2: ** GENEREAL LIBRARY INFORMATION
! 3: **
! 4: ** (c) COPYRIGHT MIT 1995.
! 5: ** Please first read the full copyright statement in the file COPYRIGH.
! 6: ** @(#) $Id: HTAccess.c,v 1.121 1996/05/20 15:06:18 frystyk Exp $
! 7: **
! 8: ** Authors
! 9: ** HFN Henrik Frystyk Nielsen, frystyk@w3.org
! 10: */
! 11:
! 12: #if !defined(HT_DIRECT_WAIS) && !defined(HT_DEFAULT_WAIS_GATEWAY)
! 13: #define HT_DEFAULT_WAIS_GATEWAY "http://www.w3.org:8001/"
! 14: #endif
! 15:
! 16: /* Library include files */
! 17: #include "WWWUtil.h"
! 18: #include "HTBind.h"
! 19: #include "HTAnchor.h"
! 20: #include "HTProt.h"
! 21: #include "HTDNS.h"
! 22: #include "HTLib.h" /* Implemented here */
! 23:
! 24: #ifndef W3C_VERSION
! 25: #define W3C_VERSION "unknown"
! 26: #endif
! 27:
! 28: #ifndef HT_DEFAULT_USER
! 29: #define HT_DEFAULT_USER "LIBWWW_GENERIC_USER"
! 30: #endif
! 31:
! 32: PRIVATE char * HTAppName = NULL; /* Application name: please supply */
! 33: PRIVATE char * HTAppVersion = NULL; /* Application version: please supply */
! 34:
! 35: PRIVATE char * HTLibName = "libwww";
! 36: PRIVATE char * HTLibVersion = W3C_VERSION;
! 37:
! 38: PRIVATE BOOL HTSecure = NO; /* Can we access local file system? */
! 39:
! 40: PRIVATE HTUserProfile * UserProfile = NULL; /* Default user profile */
! 41:
! 42: /* --------------------------------------------------------------------------*/
! 43:
! 44: /* Information about the Application
! 45: ** ---------------------------------
! 46: */
! 47: PUBLIC const char * HTLib_appName (void)
! 48: {
! 49: return HTAppName ? HTAppName : "UNKNOWN";
! 50: }
! 51:
! 52: PUBLIC const char * HTLib_appVersion (void)
! 53: {
! 54: return HTAppVersion ? HTAppVersion : "0.0";
! 55: }
! 56:
! 57: /* Information about libwww
! 58: ** ------------------------
! 59: */
! 60: PUBLIC const char * HTLib_name (void)
! 61: {
! 62: return HTLibName ? HTLibName : "UNKNOWN";
! 63: }
! 64:
! 65: PUBLIC const char * HTLib_version (void)
! 66: {
! 67: return HTLibVersion ? HTLibVersion : "0.0";
! 68: }
! 69:
! 70: /* Default User Profile
! 71: ** --------------------
! 72: */
! 73: PUBLIC HTUserProfile * HTLib_userProfile (void)
! 74: {
! 75: return UserProfile;
! 76: }
! 77:
! 78: PUBLIC BOOL HTLib_setUserProfile (HTUserProfile * up)
! 79: {
! 80: if (up) {
! 81: UserProfile = up;
! 82: return YES;
! 83: }
! 84: return NO;
! 85: }
! 86:
! 87: /* Access Local File System
! 88: ** ------------------------
! 89: ** In this mode we do not tough the local file system at all
! 90: */
! 91: PUBLIC BOOL HTLib_secure (void)
! 92: {
! 93: return HTSecure;
! 94: }
! 95:
! 96: PUBLIC void HTLib_setSecure (BOOL mode)
! 97: {
! 98: HTSecure = mode;
! 99: }
! 100:
! 101: /* HTLibInit
! 102: **
! 103: ** This function initiates the Library and it MUST be called when
! 104: ** starting up an application. See also HTLibTerminate()
! 105: */
! 106: PUBLIC BOOL HTLibInit (const char * AppName, const char * AppVersion)
! 107: {
! 108: if (WWWTRACE)
! 109: HTTrace("WWWLibInit.. INITIALIZING LIBRARY OF COMMON CODE\n");
! 110:
! 111: /* Set the application name and version */
! 112: if (AppName) {
! 113: char *ptr;
! 114: StrAllocCopy(HTAppName, AppName);
! 115: ptr = HTAppName;
! 116: while (*ptr) {
! 117: if (WHITE(*ptr)) *ptr = '_';
! 118: ptr++;
! 119: }
! 120: }
! 121: if (AppVersion) {
! 122: char *ptr;
! 123: StrAllocCopy(HTAppVersion, AppVersion);
! 124: ptr = HTAppVersion;
! 125: while (*ptr) {
! 126: if (WHITE(*ptr)) *ptr = '_';
! 127: ptr++;
! 128: }
! 129: }
! 130:
! 131: /* Create a default user profile */
! 132: UserProfile = HTUserProfile_new(HT_DEFAULT_USER, NULL);
! 133:
! 134: /* Initialize bindings */
! 135: HTBind_init();
! 136:
! 137: #ifdef WWWLIB_SIG
! 138: /* On Solaris (and others?) we get a BROKEN PIPE signal when connecting
! 139: ** to a port where we should get `connection refused'. We ignore this
! 140: ** using the following function call
! 141: */
! 142: HTSetSignal(); /* Set signals in library */
! 143: #endif
! 144:
! 145:
! 146: #ifdef _WINSOCKAPI_
! 147: /*
! 148: ** Initialise WinSock DLL. This must also be shut down! PMH
! 149: */
! 150: {
! 151: WSADATA wsadata;
! 152: if (WSAStartup(DESIRED_WINSOCK_VERSION, &wsadata)) {
! 153: if (WWWTRACE)
! 154: HTTrace("WWWLibInit.. Can't initialize WinSoc\n");
! 155: WSACleanup();
! 156: return NO;
! 157: }
! 158: if (wsadata.wVersion < MINIMUM_WINSOCK_VERSION) {
! 159: if (WWWTRACE)
! 160: HTTrace("WWWLibInit.. Bad version of WinSoc\n");
! 161: WSACleanup();
! 162: return NO;
! 163: }
! 164: }
! 165: #endif /* _WINSOCKAPI_ */
! 166:
! 167: return YES;
! 168: }
! 169:
! 170:
! 171: /* HTLibTerminate
! 172: ** --------------
! 173: ** This function HT_FREEs memory kept by the Library and should be called
! 174: ** before exit of an application (if you are on a PC platform)
! 175: */
! 176: PUBLIC BOOL HTLibTerminate (void)
! 177: {
! 178: if (WWWTRACE) HTTrace("WWWLibTerm.. Cleaning up LIBRARY OF COMMON CODE\n");
! 179:
! 180: HT_FREE(HTAppName); /* Freed thanks to Wade Ogden <wade@ebt.com> */
! 181: HT_FREE(HTAppVersion);
! 182:
! 183: HTAtom_deleteAll(); /* Remove the atoms */
! 184: HTDNS_deleteAll(); /* Remove the DNS host cache */
! 185: HTAnchor_deleteAll(NULL); /* Delete anchors and drop hyperdocs */
! 186:
! 187: HTProtocol_deleteAll(); /* Remove bindings between access and protocols */
! 188: HTBind_deleteAll(); /* Remove bindings between suffixes, media types */
! 189:
! 190: HTUserProfile_delete(UserProfile); /* Free our default User profile */
! 191:
! 192: #ifdef _WINSOCKAPI_
! 193: WSACleanup();
! 194: #endif
! 195:
! 196: return YES;
! 197: }
! 198:
Webmaster