Exemplo n.º 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;
    }
}
Exemplo n.º 2
0
void * HTQueue_headOfQueue(HTList *me)
{
  return HTList_firstObject(me);
}