Exemple #1
0
/*
**	Scan the request line for METHOD, URI and VERSION
**	Returns:	HT_OK		if 1.x request and OK
**			HT_LOADED     	if 0.9 request and OK
**			HT_ERROR	if invalid request line
*/
PRIVATE int ParseRequest (HTStream * me)
{
    HTRequest * client = HTList_firstObject(me->http->clients);
    char * line = HTChunk_data(me->buffer);
    char * method_str = HTNextField(&line);
    char * request_uri = HTNextField(&line);
    char * version_str = HTNextField(&line);
    HTMethod method;

    /* Check if method is allowed */
    if (!method_str || (method = HTMethod_enum(method_str))==METHOD_INVALID) {
        HTRequest_addError(client, ERR_FATAL, NO, HTERR_NOT_ALLOWED,
                           NULL, 0, "ParseRequest");
        return HT_ERROR;
    }
    HTRequest_setMethod(client, method);

    /* Find an anchor for the request URI */
    if (request_uri) {
        char * uri = HTParse(request_uri, "file:", PARSE_ALL);
        HTRequest_setAnchor(client, HTAnchor_findAddress(uri));
        HT_FREE(uri);
    } else {
        HTRequest_addError(client, ERR_FATAL, NO, HTERR_BAD_REQUEST,
                           NULL, 0, "ParseRequest");
        return HT_ERROR;
    }

    /* Get ready to get the rest of the request */
    if (version_str) {
        me->target = HTStreamStack(WWW_MIME_HEAD,
                                   HTRequest_debugFormat(client),
                                   HTRequest_debugStream(client),
                                   client, NO);
        return HT_OK;
    } else {
        HTRequest_addError(client, ERR_FATAL, NO, HTERR_BAD_VERSION,
                           NULL, 0, "ParseRequest");
        return HT_ERROR;
    }
}
Exemple #2
0
/*
**	Allowed methods	(Allow)
*/
PUBLIC HTMethod HTAnchor_allow (HTParentAnchor * me)
{
    if (me) {
	if (me->allow == 0 && me->headers) {
	    char * value = HTAssocList_findObject(me->headers, "allow");
	    char * field;

	    /*
	    **  We treat methods allowed on this object as case insensitive
	    **  in case we receive the information over the net - that is -
	    **  in the Allow header.
	    */
	    while ((field = HTNextField(&value)) != NULL) {
		HTMethod new_method;
		if ((new_method = HTMethod_enum(field)) != METHOD_INVALID)
		    me->allow |= new_method;
	    }
	}
	return me->allow;
    }	
    return METHOD_INVALID;
}