Ejemplo n.º 1
0
int main()
{
    HTList * converters = HTList_new();		/* List of converters */
    HTList * encodings = HTList_new();		/* List of encoders */

    /* Set up the application's event loop. We use the 
       example event loop that comes with the Library.  */
    HTEventInit();

    /* Initialize libwww core */
    HTLibInit("TestApp", "1.0");

    /* Turn on TRACE so we can see what is going on */
    HTSetTraceMessageMask("sop");

    /* Register the default set of transport protocols */
    HTTransportInit();

    /* Register the default set of protocol modules */
    HTProtocolInit();

    /* Register the default set of BEFORE and AFTER filters */
    HTNetInit();

    /* Register the default set of converters */
    HTConverterInit(converters);
    HTFormat_setConversion(converters);

    /* Register the default set of transfer encoders and decoders */
    HTTransferEncoderInit(encodings);
    HTFormat_setTransferCoding(encodings);

    /* Register the default set of file suffix bindings */
    HTFileInit();

    /* Register the default set of MIME header parsers */
    HTMIMEInit();

    /* Register the default set of Icons for directory listings */
    HTIconInit(NULL);

    /* Register the default set of messages and dialog functions */
    HTAlertInit();

    /* Terminate the Library */
    HTLibTerminate();
    return 0;
}
Ejemplo n.º 2
0
/*	Determine a suitable suffix, given the representation
**	-----------------------------------------------------
**
** On entry,
**	rep	is the atomized MIME style representation
**
** On exit,
**	returns	a pointer to a suitable suffix string if one has been
**		found, else "".
*/
PUBLIC WWW_CONST char * HTFileSuffix ARGS1(HTAtom*, rep)
{
    HTSuffix * suff;
    int n;
    int i;

    if (!HTSuffixes) HTFileInit();
    n = HTList_count(HTSuffixes);
    for(i=0; i<n; i++) {
	suff = HTList_objectAt(HTSuffixes, i);
	if (suff->rep == rep) {
	    return suff->suffix;		/* OK -- found */
	}
    }
    return "";		/* Dunno */
}
Ejemplo n.º 3
0
PUBLIC float HTFileValue ARGS1 (WWW_CONST char *,filename)

{
    HTSuffix * suff;
    int n;
    int i;
    int lf = strlen(filename);

    if (!HTSuffixes) HTFileInit();
    n = HTList_count(HTSuffixes);
    for(i=0; i<n; i++) {
        int ls;
	suff = HTList_objectAt(HTSuffixes, i);
	ls = strlen(suff->suffix);
	if ((ls <= lf) && 0==strcmp(suff->suffix, filename + lf - ls)) {
#ifndef DISABLE_TRACE
	    if (www2Trace) fprintf(stderr, "File: Value of %s is %.3f\n",
			       filename, suff->quality);
#endif
	    return suff->quality;		/* OK -- found */
	}
    }
    return 0.3;		/* Dunno! */
}
Ejemplo n.º 4
0
PRIVATE void client_profile (const char * AppName, const char * AppVersion,
			     BOOL preemptive, BOOL cache, BOOL HTMLParser)
{
    /* If the Library is not already initialized then do it */
    if (!HTLib_isInitialized()) HTLibInit(AppName, AppVersion);

    /* Register the default set of messages and dialog functions */
    HTAlertInit();
    HTAlert_setInteractive(YES);

    if (!converters) {
      converters = HTList_new();
      /* Register the default set of converters */
      HTConverterInit(converters);
      /* Register the default libwww HTML parser */
      if (HTMLParser) HTMLInit(converters);
      /* Set the converters as global converters for all requests */
      HTFormat_setConversion(converters);
    }

    if (!transfer_encodings) {
      transfer_encodings = HTList_new();
      /* Register the default set of transfer encoders and decoders */
      HTTransferEncoderInit(transfer_encodings);
      HTFormat_setTransferCoding(transfer_encodings);
    }

    if (!content_encodings) {
      content_encodings = HTList_new();
      /* Register the default set of content encoders and decoders */
      HTContentEncoderInit(content_encodings);
      if (HTList_count(content_encodings) > 0)
	HTFormat_setContentCoding(content_encodings);
      else {
	HTList_delete(content_encodings);
	content_encodings = NULL;
      }
    }

    /* Register the default set of transport protocols */
    HTTransportInit();

    /* Register the default set of application protocol modules */
    if (preemptive)
	HTProtocolPreemptiveInit();
    else
	HTProtocolInit();

    /* Initialize suffix bindings for local files */
    HTBind_init();

    /* Set max number of sockets we want open simultanously */ 
    HTNet_setMaxSocket(32);

    /* The persistent cache does not work in preemptive mode */
    if (cache) HTCacheInit(NULL, 20);

    /* Register the default set of BEFORE and AFTER filters */
    HTNetInit();

    /* Set up the default set of Authentication schemes */
    HTAAInit();

    /* Get any proxy or gateway environment variables */
    HTProxy_getEnvVar();

    /* Register the default set of MIME header parsers */
    HTMIMEInit();

    /* Register the default set of file suffix bindings */
    HTFileInit();

    /* Register the default set of Icons for directory listings */
    HTIconInit(NULL);
}
Ejemplo n.º 5
0
PRIVATE void robot_profile (const char * AppName, const char * AppVersion)
{
    /* If the Library is not already initialized then do it */
    if (!HTLib_isInitialized()) HTLibInit(AppName, AppVersion);

    if (!converters) {
      converters = HTList_new();
      /* Register the default set of converters including the HTML parser */
      HTConverterInit(converters);
      HTMLInit(converters);
      /* Set the converters as global converters for all requests */
      HTFormat_setConversion(converters);
    }

    if (!transfer_encodings) {
      transfer_encodings = HTList_new();
      /* Register the default set of transfer encoders and decoders */
      HTTransferEncoderInit(transfer_encodings);
      HTFormat_setTransferCoding(transfer_encodings);
    }

    if (!content_encodings) {
      content_encodings = HTList_new();
      /* Register the default set of content encoders and decoders */
      HTContentEncoderInit(content_encodings);
      if (HTList_count(content_encodings) > 0)
	HTFormat_setContentCoding(content_encodings);
      else {
	HTList_delete(content_encodings);
	content_encodings = NULL;
      }
    }

    /* Register the default set of transport protocols */
    HTTransportInit();

    /* Register the default set of application protocol modules */
    HTProtocolInit();

    /* Initialize suffix bindings for local files */
    HTBind_init();

    /* Set max number of sockets we want open simultanously */ 
    HTNet_setMaxSocket(32);

    /* Register some default set of BEFORE and AFTER filters */
    HTNet_addBefore(HTRuleFilter, NULL, NULL, HT_FILTER_MIDDLE); 
    HTNet_addBefore(HTProxyFilter, NULL, NULL, HT_FILTER_MIDDLE); 
    HTNet_addAfter(HTInfoFilter, NULL, NULL, HT_ALL, HT_FILTER_LATE); 

    /* Get any proxy or gateway environment variables */
    HTProxy_getEnvVar();

    /* Register the default set of MIME header parsers */
    HTMIMEInit();

    /* Register the default set of file suffix bindings */
    HTFileInit();

    /* Register the default set of Icons for directory listings */
    HTIconInit(NULL);

    /* Register some default messages and dialog functions */
    if (HTAlert_interactive()) {
	HTAlert_add(HTError_print, HT_A_MESSAGE);
	HTAlert_add(HTConfirm, HT_A_CONFIRM);
	HTAlert_add(HTPrompt, HT_A_PROMPT);
	HTAlert_add(HTPromptPassword, HT_A_SECRET);
	HTAlert_add(HTPromptUsernameAndPassword, HT_A_USER_PW);
    }
    HTAlert_setInteractive(YES);
}
Ejemplo n.º 6
0
PUBLIC HTFormat HTFileFormat ARGS4 (
			char *,	filename,
			HTAtom **,	pencoding,
                        HTAtom *,       default_type,
                        int *, compressed)
{
  HTSuffix *suff;
  int n, i, lf;

  if (!filename)
    return NULL;

  /* Make a copy to hack and slash. */
  filename = strdup (filename);

  lf = strlen (filename);

  /* Step backward through filename, looking for '?'. */
  for (i = lf - 1; i >= 0; i--)
    {
      if (filename[i] == '?')
        {
          /* Clip query. */
          filename[i] = '\0';
          /* Get new strlen, since we just changed it. */
          lf = strlen (filename);
          goto ok_ready;
        }
    }

  *compressed = 0;

  /* Check for .Z and .z. */
  if (lf > 2)
    {
      if (strcmp (&(filename[lf-2]), ".Z") == 0)
        {
          *compressed = COMPRESSED_BIGZ;
          filename[lf-2] = '\0';
          lf = strlen (filename);
#ifndef DISABLE_TRACE
          if (www2Trace)
            fprintf (stderr, "[HTFileFormat] Got hit on .Z; filename '%s'\n",
                     filename);
#endif
          goto ok_ready;
        }
      else if (strcmp (&(filename[lf-2]), ".z") == 0)
        {
          *compressed = COMPRESSED_GNUZIP;
          filename[lf-2] = '\0';
          lf = strlen (filename);
#ifndef DISABLE_TRACE
          if (www2Trace)
            fprintf (stderr, "[HTFileFormat] Got hit on .z; filename '%s'\n",
                     filename);
#endif
          goto ok_ready;
        }
      else if (lf > 3)
        {
          if (strcmp (&(filename[lf-3]), ".gz") == 0)
            {
              *compressed = COMPRESSED_GNUZIP;
              filename[lf-3] = '\0';
              lf = strlen (filename);
#ifndef DISABLE_TRACE
              if (www2Trace)
                fprintf (stderr, 
                         "[HTFileFormat] Got hit on .gz; filename '%s'\n",
                         filename);
#endif
              goto ok_ready;
            }
        }      
    }      
  
 ok_ready:
  if (!HTSuffixes) 
    HTFileInit();

  *pencoding = NULL;

  n = HTList_count(HTSuffixes);

  for(i=0; i<n; i++) 
    {
      int ls;
      suff = HTList_objectAt(HTSuffixes, i);
      ls = strlen(suff->suffix);
      if ((ls <= lf) && 0==my_strcasecmp(suff->suffix, filename + lf - ls)) 
        {
          int j;
          *pencoding = suff->encoding;
          if (suff->rep) 
            goto done;
          
          for(j=0; j<n; j++) 
            {  /* Got encoding, need representation */
              int ls2;
              suff = HTList_objectAt(HTSuffixes, j);
              ls2 = strlen(suff->suffix);
              if ((ls <= lf) && 
                  0==my_strncasecmp(suff->suffix, filename + lf - ls -ls2, ls2)) 
                if (suff->rep) 
                  goto done;
	    }
        }
    }
  
  suff = strchr(filename, '.') ? 	/* Unknown suffix */
    ( unknown_suffix.rep ? &unknown_suffix : &no_suffix)
      : &no_suffix;
  
  /* For now, assuming default is 8bit text/plain.
     We also want default 8bit text/html for http connections. */
  
  /* set default encoding unless found with suffix already */
  if (!*pencoding) *pencoding = suff->encoding ? suff->encoding
    : HTAtom_for("8bit");

 done:

  /* Free our copy. */
  free (filename);
  return suff->rep ? suff->rep : default_type;
}