Esempio n. 1
0
/*
**  Check whether the application provides us with a cookie or more.
*/
PRIVATE int HTCookie_beforeFilter (HTRequest * request, void * param, int mode)
{
    if ((CookieMode & HT_COOKIE_SEND) && FindCookie) {
        HTAssocList * cookies = (*FindCookie)(request, FindCookieContext);
        if (cookies) {
            HTChunk * cookie_header = HTChunk_new(64);
            HTAssocList * cur = cookies;
            HTAssoc * pres;
            BOOL first=YES;
            while ((pres = (HTAssoc *) HTAssocList_nextObject(cur))) {
                if (!first) HTChunk_putc(cookie_header, ';');
                HTChunk_puts(cookie_header, HTAssoc_name(pres));
                HTChunk_putc(cookie_header, '=');
                HTChunk_puts(cookie_header, HTAssoc_value(pres));
                first = NO;
            }
            HTRequest_addExtraHeader(request, "Cookie", HTChunk_data(cookie_header));
            HTChunk_delete(cookie_header);

            /* Also delete the association list */
            HTAssocList_delete(cookies);
        }
    }
    return HT_OK;
}
Esempio n. 2
0
/*	Clear Header Information
**	------------------------
*/
PUBLIC void HTAnchor_clearHeader (HTParentAnchor * me)
{
    HTTRACE(ANCH_TRACE, "HTAnchor.... Clear all header information\n");
    me->allow = METHOD_INVALID;
    if (me->content_encoding) {
	HTList_delete(me->content_encoding);
	me->content_encoding = NULL;
    }
    if (me->content_language) {
	HTList_delete(me->content_language);
	me->content_language = NULL;
    }
    HT_FREE(me->content_base);
    HT_FREE(me->content_location);
    me->content_length = -1;					  /* Invalid */

    /* Delete the title */
    HT_FREE(me->title);

    /* Clear the content type */
    me->content_type = WWW_UNKNOWN;
    if (me->type_parameters) {
	HTAssocList_delete(me->type_parameters);
	me->type_parameters = NULL;
    }    

    /* Meta tags */
    if (me->meta_tags) {
	HTAssocList_delete(me->meta_tags);
	me->meta_tags = NULL;
    }    

    /* Dates etc. */
    me->date = (time_t) -1;
    me->expires = (time_t) -1;
    me->last_modified = (time_t) -1;
    me->age = (time_t) -1;
    
    HT_FREE(me->derived_from);
    HT_FREE(me->version);
    HT_FREE(me->etag);

    /* Delete any original headers */
    if (me->headers) HTAssocList_delete(me->headers);
    me->headers = NULL;
}
Esempio n. 3
0
/*
**  Take the relevant infomration from the response object and cache it
**  in the anchor object. We inherit the information that is already
**  parsed in the response along with the unparsed headers.
*/
PUBLIC BOOL HTAnchor_update (HTParentAnchor * me, HTResponse * response)
{
    if (me && response) {
	HTCachable cachable = HTResponse_isCachable(response);

	if (cachable == HT_CACHE_ETAG) {
	    char * etag = HTResponse_etag(response);
	    HTTRACE(ANCH_TRACE, "HTAnchor.... Updating etag for %p\n" _ me);
	    if (etag) {
		HTAnchor_setEtag(me, etag);
		return YES;
	    }

	} else if (cachable == HT_CACHE_NOT_MODIFIED) {
	    HTTRACE(ANCH_TRACE, "HTAnchor.... Information is up to date for %p\n" _ me);
	    return YES;

	} else if (cachable == HT_CACHE_ALL) {
	    char * etag = HTResponse_etag(response);
	    HTTRACE(ANCH_TRACE, "HTAnchor.... Updating metainformation for %p\n" _ me);

	    /*
	    **  The content length and type is already parsed at this point
	    **  in time. We also check for format parameters like charset etc.
	    **  and copy the contents in the anchor object
	    */
	    me->content_length = HTResponse_length(response);
	    me->content_type = HTResponse_format(response);
	    me->type_parameters = HTResponse_formatParam(response);
	    me->content_encoding = HTResponse_encoding(response);
	
            /* Don't forget the etag as well */
       	    if (etag) HTAnchor_setEtag(me, etag);

	    /*
	    **  Inherit all the unparsed headers - we may need them later!
	    */
	    if (me->headers) HTAssocList_delete(me->headers);
	    me->headers = HTResponse_handOverHeader(response);

	    /*
	    **  Notifify the response object not to delete the lists that we
	    **  have inherited in the anchor object
	    */
	    HTResponse_isCached(response, YES);

	    /*
	    **  Set the datestamp of when the anchor was updated if we didn't
	    **  get any in the response
	    */
	    if (!HTAssocList_findObject(me->headers, "date"))
		HTAnchor_setDate(me, time(NULL));

	    return YES;
	}
    }
    return NO;
}
Esempio n. 4
0
PUBLIC BOOL HTResponse_deleteVariantAll (HTResponse * me)
{
    if (me && me->variants) {
        HTAssocList_delete(me->variants);
        me->variants = NULL;
        return YES;
    }
    return NO;
}
Esempio n. 5
0
/*
**  Cache control directives received in the response
*/
PUBLIC BOOL HTResponse_deleteCacheControlAll (HTResponse * me)
{
    if (me && me->cache_control) {
        HTAssocList_delete(me->cache_control);
        me->cache_control = NULL;
        return YES;
    }
    return NO;
}
Esempio n. 6
0
PUBLIC BOOL HTResponse_deleteProtocolRequestAll (HTResponse * me)
{
    if (me && me->protocol_request) {
        HTAssocList_delete(me->protocol_request);
        me->protocol_request = NULL;
        return YES;
    }
    return NO;
}
Esempio n. 7
0
PUBLIC BOOL HTResponse_deleteTrailerAll (HTResponse * me)
{
    if (me && me->trailer) {
        HTAssocList_delete(me->trailer);
        me->trailer = NULL;
        return YES;
    }
    return NO;
}
Esempio n. 8
0
PUBLIC BOOL HTResponse_deleteConnectionAll (HTResponse * me)
{
    if (me && me->connection) {
        HTAssocList_delete(me->connection);
        me->connection = NULL;
        return YES;
    }
    return NO;
}
Esempio n. 9
0
PUBLIC BOOL HTResponse_deleteChallengeAll (HTResponse * me)
{
    if (me && me->challenge) {
        HTAssocList_delete(me->challenge);
        me->challenge = NULL;
        return YES;
    }
    return NO;
}
Esempio n. 10
0
PUBLIC BOOL HTResponse_deleteHeaderAll (HTResponse * me)
{
    if (me && me->headers) {
        HTAssocList_delete(me->headers);
        me->headers = NULL;
        return YES;
    }
    return NO;
}
Esempio n. 11
0
/*
**  Byte ranges
*/
PUBLIC BOOL HTResponse_deleteRangeAll (HTResponse * me)
{
    if (me && me->byte_ranges) {
        HTAssocList_delete(me->byte_ranges);
        me->byte_ranges = NULL;
        return YES;
    }
    return NO;
}
Esempio n. 12
0
PUBLIC BOOL HTResponse_deleteProtocolInfoAll (HTResponse * me)
{
    if (me && me->protocol_info) {
        HTAssocList_delete(me->protocol_info);
        me->protocol_info = NULL;
        return YES;
    }
    return NO;
}
Esempio n. 13
0
int HTAssocList_delete_tcl(ClientData clientData, Tcl_Interp *interp, 
			   int argc, char **argv) {
  if (argc == 2) {
    char *keyname 	      = argv[1];
    if (keyname) {
      Tcl_HashEntry *entryPtr = Tcl_FindHashEntry(&HTableAssoc, keyname);
      if (entryPtr) {
 	HTAssocList *list    = Tcl_GetHashValue(entryPtr);
	HTAssocList_delete(list);
	Tcl_DeleteHashEntry(entryPtr);
	return TCL_OK;
      }
    }
    Tcl_AppendResult(interp, bad_vars, NULL);
    return TCL_ERROR;
  }
  else {
    Tcl_AppendResult(interp, err_string, argv[0], " associated-list",  NULL);
    return TCL_ERROR;
  }
}
Esempio n. 14
0
int main (int argc, char ** argv)
{
    int		status = 0;	
    int		arg;
    int		tokencount = 0;
    BOOL	formdata = NO;
    HTChunk *	keywords = NULL;			/* From command line */
    HTAssocList*formfields = NULL;
    HTMethod	method = METHOD_GET;			    /* Default value */
    ComLine *	cl = ComLine_new();
    BOOL	cache = NO;			     /* Use persistent cache */
    BOOL	flush = NO;		       /* flush the persistent cache */
    char *	cache_root = NULL;

    /* Starts Mac GUSI socket library */
#ifdef GUSI
    GUSISetup(GUSIwithSIOUXSockets);
    GUSISetup(GUSIwithInternetSockets);
#endif

#ifdef __MWERKS__ /* STR */
    InitGraf((Ptr) &qd.thePort); 
    InitFonts(); 
    InitWindows(); 
    InitMenus(); TEInit(); 
    InitDialogs(nil); 
    InitCursor();
    SIOUXSettings.asktosaveonclose = false;
    argc=ccommand(&argv);
#endif

    /* Initiate W3C Reference Library with a client profile */
    HTProfile_newNoCacheClient(APP_NAME, APP_VERSION);

    /* Need our own trace and print functions */
    HTPrint_setCallback(printer);
    HTTrace_setCallback(tracer);

    /*
    ** Delete the default Username/password handler so that we can handle
    ** parameters handed to us from the command line. The default is set
    ** by the profile.
    */
    HTAlert_deleteOpcode(HT_A_USER_PW);
    HTAlert_add(PromptUsernameAndPassword, HT_A_USER_PW);

    /*
    ** Add default content decoder. We insert a through line as it doesn't
    ** matter that we get an encoding that we don't know.
    */
    HTFormat_addCoding("*", HTIdentityCoding, HTIdentityCoding, 0.3);

    /* Scan command Line for parameters */
    for (arg=1; arg<argc; arg++) {
	if (*argv[arg] == '-') {
	    
	    /* - alone => filter */
	    if (argv[arg][1] == '\0') {
		cl->flags |= CL_FILTER;	   
	    
	    /* -? or -help: show the command line help page */
	    } else if (!strcmp(argv[arg],"-?") || !strcmp(argv[arg],"-help")) {
		cl->anchor = (HTParentAnchor *) HTAnchor_findAddress(W3C_HELP);
		tokencount = 1;

	    /* non-interactive */
	    } else if (!strcmp(argv[arg], "-n")) {
		HTAlert_setInteractive(NO);

	    /* Treat the keywords as form data with a <name> "=" <value> */
	    } else if (!strcmp(argv[arg], "-form")) {
		formdata = YES;

	    /* from -- Initial represntation (only with filter) */
	    } else if (!strcmp(argv[arg], "-from")) {
		cl->format = (arg+1 < argc && *argv[arg+1] != '-') ?
		    HTAtom_for(argv[++arg]) : WWW_HTML;

	    /* to -- Final representation */
	    } else if (!strcmp(argv[arg], "-to")) {
		HTFormat format = (arg+1 < argc && *argv[arg+1] != '-') ?
		    HTAtom_for(argv[++arg]) : DEFAULT_FORMAT;
		HTRequest_setOutputFormat(cl->request, format);

	    /* destination for PUT, POST etc. */
	    } else if (!strcmp(argv[arg], "-dest")) {
		if (arg+1 < argc && *argv[arg+1] != '-') {
		    char * dest = HTParse(argv[++arg], cl->cwd, PARSE_ALL);
		    cl->dest = (HTParentAnchor *) HTAnchor_findAddress(dest);
		    HT_FREE(dest);
		}

	    /* source please */
	    } else if (!strcmp(argv[arg], "-source")) {
		HTRequest_setOutputFormat(cl->request, WWW_RAW);

	    /* log file */
	    } else if (!strcmp(argv[arg], "-l")) {
		cl->logfile = (arg+1 < argc && *argv[arg+1] != '-') ?
		    argv[++arg] : DEFAULT_LOG_FILE;

	    /* Max forward hops in case of TRACE request */
	    } else if (!strcmp(argv[arg], "-hops") ||
		       !strcmp(argv[arg], "-maxforwards")) {
		int hops = (arg+1 < argc && *argv[arg+1] != '-') ?
		    atoi(argv[++arg]) : DEFAULT_HOPS;
		if (hops >= 0) HTRequest_setMaxForwards(cl->request, hops);

	    /* automated authentication of format user:password@realm */
	    } else if (!strncmp(argv[arg], "-auth", 5)) {
		char * credentials = (arg+1 < argc && *argv[arg+1] != '-') ?
		    argv[++arg] : NULL;
		if (credentials) ParseCredentials(cl, credentials);

	    /* rule file */
	    } else if (!strcmp(argv[arg], "-r")) {
		cl->rules = (arg+1 < argc && *argv[arg+1] != '-') ?
		    argv[++arg] : DEFAULT_RULE_FILE;

	    /* output filename */
	    } else if (!strcmp(argv[arg], "-o")) { 
		cl->outputfile = (arg+1 < argc && *argv[arg+1] != '-') ?
		    argv[++arg] : DEFAULT_OUTPUT_FILE;

	    /* timeout -- Change the default request timeout */
	    } else if (!strcmp(argv[arg], "-timeout")) {
		int timeout = (arg+1 < argc && *argv[arg+1] != '-') ?
		    atoi(argv[++arg]) : DEFAULT_TIMEOUT;
		if (timeout >= 1) cl->timer = timeout*MILLIES;

	    /* preemptive or non-preemptive access */
	    } else if (!strcmp(argv[arg], "-single")) {
		HTRequest_setPreemptive(cl->request, YES);

	    /* content Length Counter */
	    } else if (!strcmp(argv[arg], "-cl")) { 
		cl->flags |= CL_COUNT;

	    /* print version and exit */
	    } else if (!strcmp(argv[arg], "-version")) { 
		VersionInfo(argv[0]);
		Cleanup(cl, 0);

	    /* run in quiet mode */
	    } else if (!strcmp(argv[arg], "-q")) { 
		cl->flags |= CL_QUIET;

	    /* Start the persistent cache */
	    } else if (!strcmp(argv[arg], "-cache")) {
		cache = YES;

	    /* Determine the cache root */
	    } else if (!strcmp(argv[arg], "-cacheroot")) { 
		cache_root = (arg+1 < argc && *argv[arg+1] != '-') ?
		    argv[++arg] : NULL;

	    /* Persistent cache flush */
	    } else if (!strcmp(argv[arg], "-flush")) {
		flush = YES;

	    /* Do a cache validation */
	    } else if (!strcmp(argv[arg], "-validate")) {
		cl->flags |= CL_VALIDATE;

	    /* Do an end-to-end cache-validation */
	    } else if (!strcmp(argv[arg], "-endvalidate")) {
		cl->flags |= CL_END_VALIDATE;

	    /* Force complete reload */
	    } else if (!strcmp(argv[arg], "-nocache")) {
		cl->flags |= CL_CACHE_FLUSH;

#ifdef WWWTRACE
	    /* trace flags */
	    } else if (!strncmp(argv[arg], "-v", 2)) {
		HTSetTraceMessageMask(argv[arg]+2);
#endif

	    /* GET method */
	    } else if (!strcasecomp(argv[arg], "-get")) {
		method = METHOD_GET;

	    /* HEAD method */
	    } else if (!strcasecomp(argv[arg], "-head")) {
		method = METHOD_HEAD;

	    /* DELETE method */
	    } else if (!strcasecomp(argv[arg], "-delete")) {
		method = METHOD_DELETE;

	    /* POST Method */
	    } else if (!strcasecomp(argv[arg], "-post")) {
		method = METHOD_POST;

	    /* PUT Method */
	    } else if (!strcasecomp(argv[arg], "-put")) {
		method = METHOD_PUT;

	    /* OPTIONS Method */
	    } else if (!strcasecomp(argv[arg], "-options")) {
		method = METHOD_OPTIONS;

	    /* TRACE Method */
	    } else if (!strcasecomp(argv[arg], "-trace")) {
		method = METHOD_TRACE;

	    } else {
		if (SHOW_MSG) HTPrint("Bad Argument (%s)\n", argv[arg]);
	    }
	} else {	 /* If no leading `-' then check for URL or keywords */
    	    if (!tokencount) {
		char * ref = HTParse(argv[arg], cl->cwd, PARSE_ALL);
		cl->anchor = (HTParentAnchor *) HTAnchor_findAddress(ref);
		tokencount = 1;
		HT_FREE(ref);
	    } else if (formdata) {		   /* Keywords are form data */
		char * string = argv[arg];
		if (tokencount++ <= 1) formfields = HTAssocList_new();
		HTParseFormInput(formfields, string);
	    } else {		   	       /* keywords are search tokens */
		char * escaped = HTEscape(argv[arg], URL_XALPHAS);
		if (tokencount++ <= 1)
		    keywords = HTChunk_new(128);
		else
		    HTChunk_putc(keywords, ' ');
		HTChunk_puts(keywords, HTStrip(escaped));
		HT_FREE(escaped);
	    }
	}
    }

    if (!tokencount && !cl->flags & CL_FILTER) {
	VersionInfo(argv[0]);
	Cleanup(cl, 0);
    }

    /* Should we use persistent cache? */
    if (cache) {
	HTCacheInit(cache_root, 20);

	/* Should we start by flushing? */
	if (flush) HTCache_flushAll();
    }

    /*
    ** Check whether we should do some kind of cache validation on
    ** the load
    */
    if (cl->flags & CL_VALIDATE)
	HTRequest_setReloadMode(cl->request, HT_CACHE_VALIDATE);
    else if (cl->flags & CL_END_VALIDATE)
	HTRequest_setReloadMode(cl->request, HT_CACHE_END_VALIDATE);
    else if (cl->flags & CL_CACHE_FLUSH)
	HTRequest_setReloadMode(cl->request, HT_CACHE_FLUSH);

    /* Add progress notification */
    if (cl->flags & CL_QUIET) HTAlert_deleteOpcode(HT_A_PROGRESS);

    /* Output file specified? */
    if (cl->outputfile) {
	if ((cl->output = fopen(cl->outputfile, "wb")) == NULL) {
	    if (SHOW_MSG) HTPrint("Can't open `%s'\\n",cl->outputfile);
	    cl->output = OUTPUT;
	}
    }

    /*
    ** Set up the output. Even though we don't use this explicit, it is
    ** required in order to show the stream stack that we know that we are
    ** getting raw data output on the output stream of the request object.
    */
    HTRequest_setOutputStream(cl->request,
			      HTFWriter_new(cl->request, cl->output, YES));

    /* Setting event timeout */
    HTHost_setEventTimeout(cl->timer);

    /*
    ** Make sure that the first request is flushed immediately and not
    ** buffered in the output buffer
    */
    HTRequest_setFlush(cl->request, YES);

    /* Log file specifed? */
    if (cl->logfile) {
	cl->log = HTLog_open(cl->logfile, YES, YES);
        if (cl->log) HTNet_addAfter(HTLogFilter, NULL, cl->log, HT_ALL, HT_FILTER_LATE);
    }

    /* Just convert formats */
    if (cl->flags & CL_FILTER) {
#ifdef STDIN_FILENO
	HTRequest_setAnchor(cl->request, (HTAnchor *) cl->anchor);
	HTRequest_setPreemptive(cl->request, YES);
	HTLoadSocket(STDIN_FILENO, cl->request);
#endif
	Cleanup(cl, 0);
    }
    
    /* Content Length Counter */
    if (cl->flags & CL_COUNT) {
	HTRequest_setOutputStream(cl->request,
				  HTContentCounter(HTBlackHole(),
						   cl->request, 0x2000));
    }

    /* Rule file specified? */
    if (cl->rules) {
	char * rules = HTParse(cl->rules, cl->cwd, PARSE_ALL);
	if (!HTLoadRulesAutomatically(rules))
	    if (SHOW_MSG) HTPrint("Can't access rules\n");
	HT_FREE(rules);
    }

    /* Add our own filter to update the history list */
    HTNet_addAfter(terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);

    /* Start the request */
    switch (method) {
    case METHOD_GET:

	if (formdata)
	    status = HTGetFormAnchor(formfields, (HTAnchor *) cl->anchor,
				     cl->request);
	else if (keywords)
	    status = HTSearchAnchor(keywords, (HTAnchor *) cl->anchor,
				    cl->request);
	else
	    status = HTLoadAnchor((HTAnchor *) cl->anchor, cl->request);
	break;

    case METHOD_HEAD:
	if (formdata) {
	    HTRequest_setMethod(cl->request, METHOD_HEAD);
	    status = HTGetFormAnchor(formfields, (HTAnchor *) cl->anchor,
				     cl->request);
	} else if (keywords) {
	    HTRequest_setMethod(cl->request, METHOD_HEAD);
	    status = HTSearchAnchor(keywords, (HTAnchor *) cl->anchor,
				    cl->request);
	} else
	    status = HTHeadAnchor((HTAnchor *) cl->anchor, cl->request);
	break;

    case METHOD_DELETE:
	status = HTDeleteAnchor((HTAnchor *) cl->anchor, cl->request);
	break;

    case METHOD_POST:
	if (formdata) {
	    HTParentAnchor * posted = NULL;
#if 1
	    posted = HTPostFormAnchor(formfields, (HTAnchor *) cl->anchor,
				      cl->request);
	    status = posted ? YES : NO;
#else
	    /* If we want output to a chunk instead */
	    post_result = HTPostFormAnchorToChunk(formfields, (HTAnchor *) cl->anchor,
						  cl->request);
	    status = post_result ? YES : NO;
#endif
	} else {
	    if (SHOW_MSG) HTPrint("Nothing to post to this address\n");
	    status = NO;	    
	}
	break;

    case METHOD_PUT:
	status = HTPutDocumentAnchor(cl->anchor, (HTAnchor *) cl->dest,
				     cl->request);
	break;

    case METHOD_OPTIONS:
	status = HTOptionsAnchor((HTAnchor *) cl->anchor, cl->request);
	break;	

    case METHOD_TRACE:
	status = HTTraceAnchor((HTAnchor *) cl->anchor, cl->request);
	break;	

    default:
	if (SHOW_MSG) HTPrint("Don't know this method\n");
	break;
    }

    if (keywords) HTChunk_delete(keywords);
    if (formfields) HTAssocList_delete(formfields);
    if (status != YES) {
	if (SHOW_MSG) HTPrint("Sorry, can't access resource\n");
	Cleanup(cl, -1);
    }

    /* Go into the event loop... */
    HTEventList_loop(cl->request);

    /* Only gets here if event loop fails */
    Cleanup(cl, 0);
    return 0;
}
Esempio n. 15
0
PUBLIC void HTRequest_delete (HTRequest * me)
{
    if (me) {
	HTTRACE(CORE_TRACE, "Request..... Delete %p\n" _ me);
	if (me->net) HTNet_setRequest(me->net, NULL);

	/*
	** Make sure we don't delete the same stream twice, when the output
	** stream and the debug stream are the same.
	*/
	if (me->orig_output_stream == me->orig_debug_stream)
	{
	    me->orig_debug_stream = NULL;
	}

	/* Should we delete the output stream? */
	if (me->orig_output_stream) {
	    HTTRACE(CORE_TRACE, "Request..... Deleting dangling output stream\n");
	    (*me->orig_output_stream->isa->_free)(me->orig_output_stream);
	    me->orig_output_stream = NULL;
	    HTNoFreeStream_delete(me->output_stream);
	    me->output_stream = NULL;
	}

	/* Should we delete the debug stream? */
	if (me->orig_debug_stream) {
	    HTTRACE(CORE_TRACE, "Request..... Deleting dangling debug stream\n");
	    (*me->orig_debug_stream->isa->_free)(me->orig_debug_stream);
	    me->orig_debug_stream = NULL;
	    HTNoFreeStream_delete(me->debug_stream);
	    me->debug_stream = NULL;
	}

	/* Clean up the error stack */
	if (me->error_stack) HTError_deleteAll(me->error_stack);

	/* Before and After Filters */
	if (me->afters) HTNetCall_deleteAfterAll(me->afters);
	if (me->befores) HTNetCall_deleteBeforeAll(me->befores);

        /* default PUT name */
        if (me->default_put_name)
          HTRequest_deleteDefaultPutName (me);

	/* Access Authentication */
	HT_FREE(me->realm);
	if (me->credentials) HTAssocList_delete(me->credentials);

	/* Cache control headers */
	if (me->cache_control)
	    HTAssocList_delete(me->cache_control);

	/* Byte ranges */
	if (me->byte_ranges) HTAssocList_delete(me->byte_ranges);

	/* Connection headers */
	if (me->connection) HTAssocList_delete(me->connection);

	/* Connection headers */
	if (me->expect) HTAssocList_delete(me->expect);

	/* Proxy information */
	HT_FREE(me->proxy);

	/* Extra header fields */
	if (me->extra_headers) HTAssocList_delete(me->extra_headers);

	/* HTTP Extension Information */
	if (me->optional) HTAssocList_delete(me->optional);
	if (me->mandatory) HTAssocList_delete(me->mandatory);

	/* Any response object */
	if (me->response) HTResponse_delete(me->response);

#ifdef HT_EXT
        if (me->messageBody) HTRequest_deleteMessageBody(me); /* MKP: clear message body*/      
        me->messageBodyFormat = NULL;
        me->messageBodyLength = -1;     
#endif
        
	HT_FREE(me);
    }
}
Esempio n. 16
0
int main (int argc, char ** argv)
{
    HTRequest * request = NULL;
    HTAnchor * anchor = NULL;
    HTAssocList * formfields = NULL;
    char * uri = NULL;

    /* Create a new premptive client */
    HTProfile_newNoCacheClient("TestApp", "1.0");

    /* Need our own trace and print functions */
    HTPrint_setCallback(printer);
    HTTrace_setCallback(tracer);

    /* Get trace messages */
#if 0
    HTSetTraceMessageMask("sop");
#endif

    /* Add our own filter to update the history list */
    HTNet_addAfter(terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);

    /* Set the timeout for long we are going to wait for a response */
    HTHost_setEventTimeout(20000);

    /* Handle command line args */
    if (argc >= 2) {
	int arg;
	uri = argv[1];
	for (arg=2; arg<argc; arg++) {
	    char * string = argv[arg];
	    
	    /* Create a list to hold the form arguments */
	    if (!formfields) formfields = HTAssocList_new();

	    /* Parse the content and add it to the association list */
	    HTParseFormInput(formfields, string);
	}
    }

    if (uri && formfields) {

	/* Create a request */
	request = HTRequest_new();

	/* Set the default output to "asis" */
	HTRequest_setOutputFormat(request, WWW_SOURCE);

	/* Get an anchor object for the URI */
	anchor = HTAnchor_findAddress(uri);

	/* Post the data and get the result in a chunk */
	result = HTPostFormAnchorToChunk(formfields, anchor, request);

	/* Clean up the form fields */
	HTAssocList_delete(formfields);

	/* Go into the event loop... */
	HTEventList_loop(request);

    } else {
	HTPrint("Type the URI to post to and the arguments for the POST operation. Encode spaces as '+'\n");
	HTPrint("\t%s <uri> 'a=1' 'b=+2+' 'c=3 ...'\n", argv[0]);
    }

    return 0;
}
Esempio n. 17
0
PUBLIC BOOL HTResponse_delete (HTResponse * me)
{
    if (me) {
        HTTRACE(CORE_TRACE, "Response.... Delete %p\n" _ me);

        /* Access Authentication */
        HT_FREE(me->realm);
        HT_FREE(me->scheme);
        if (me->challenge) HTAssocList_delete(me->challenge);

        /* Connection headers */
        if (me->connection) HTAssocList_delete(me->connection);

        /* PEP Information */
        if (me->protocol) HTAssocList_delete(me->protocol);
        if (me->protocol_request) HTAssocList_delete(me->protocol_request);
        if (me->protocol_info) HTAssocList_delete(me->protocol_info);

        /* Cache control headers */
        if (me->cache_control) HTAssocList_delete(me->cache_control);

        /* Byte ranges */
        if (me->byte_ranges) HTAssocList_delete(me->byte_ranges);

        /* Transfer Encodings */
        if (me->transfer_encoding) HTList_delete(me->transfer_encoding);

        /* Trailers */
        if (me->trailer) HTAssocList_delete(me->trailer);

        /* Variants */
        if (me->variants) HTAssocList_delete(me->variants);

        /*
        ** Only delete Content Type parameters and original headers if the
        ** information is not used elsewhere, for example by the anchor
        ** object.
        */
        if (!me->cached) {

            /* Content type parameters */
            if (me->type_parameters) HTAssocList_delete(me->type_parameters);

            /* Content Encodings */
            if (me->content_encoding) HTList_delete(me->content_encoding);

            /* List of all headers */
            if (me->headers) HTAssocList_delete(me->headers);
        }

        /* HTTP reason string */
        if (me->reason)  HT_FREE (me->reason);

        HT_FREE(me);
        return YES;
    }
    return NO;
}