Exemplo n.º 1
0
/*	HTTPMakeResponse
**	----------------
**	Makes a HTTP/1.0-1.1 response header.
*/
PRIVATE int HTTPMakeResponse (HTStream * me, HTRequest * request)
{
    char crlf[3];
    HTRsHd response_mask = HTRequest_rsHd(request);
    *crlf = CR; *(crlf+1) = LF; *(crlf+2) = '\0';

    if (response_mask & HT_S_LOCATION) {		/* @@@ */

    }
    if (response_mask & HT_S_PROXY_AUTH) {		/* @@@ */

    }
    if (response_mask & HT_S_PUBLIC) {			/* @@@ */

    }
    if (response_mask & HT_S_RETRY_AFTER) {		/* @@@ */

    }
    if (response_mask & HT_S_SERVER) {
	PUTS("Server: ");
	PUTS(HTLib_appName());
	PUTC('/');
	PUTS(HTLib_appVersion());
	PUTC(' ');
	PUTS(HTLib_name());
	PUTC('/');
	PUTS(HTLib_version());
	PUTBLOCK(crlf, 2);
    }
    if (response_mask & HT_S_WWW_AUTH) {		/* @@@ */

    }
    HTTRACE(PROT_TRACE, "HTTP........ Generating Response Headers\n");
    return HT_OK;
}
Exemplo n.º 2
0
PRIVATE int ServEvent (SOCKET soc, void * pVoid, HTEventType type)
{
    https_info * http = (https_info *)pVoid;
    int status = HT_ERROR;
    HTNet * net = http->net;
    HTRequest * request = HTNet_request(net);

    if (!net || !request) {
        HTTRACE(PROT_TRACE, "Serv HTTP... Invalid argument\n");
        return HT_ERROR;
    }

    if (type == HTEvent_CLOSE) {			      /* Interrupted */
        ServerCleanup(request, net, HT_INTERRUPTED);
        return HT_OK;
    } else
        http = (https_info *) HTNet_context(net);	/* Get existing copy */

    /* Now jump into the machine. We know the state from the previous run */
    while (1) {
        switch (http->state) {
        case HTTPS_BEGIN:
        {
            /*
            ** Create the request to handle the request and inherit the old
            ** context
            */
            HTRequest * client = HTRequest_new();
            void * context = HTRequest_context(request);
            if (context) HTRequest_setContext(client, context);
            HTRequest_setOutputConnected(client, NO);
            HTRequest_setGnHd(client, HTRequest_gnHd(request));
            HTRequest_setRsHd(client, HTRequest_rsHd(request));
            HTRequest_setEnHd(client, HTRequest_enHd(request));
            HTList_addObject(http->clients, client);

            /*
            ** Create the HTTP output stream for generating the reply
            ** FROM the client request to the channel
            */
            {
                HTOutputStream * output = HTNet_getOutput(net, NULL, 0);
                HTStream * app = HTTPReply_new(client, http,(HTStream*)output);
                HTRequest_setOutputStream(client, app);
                HTRequest_setOutputFormat(client, WWW_SOURCE);
            }
            http->state = HTTPS_NEED_REQUEST;
        }
        break;

        case HTTPS_NEED_REQUEST:
            if (type == HTEvent_READ || type == HTEvent_BEGIN) {
                status = HTHost_read(net->host, net);
                if (status == HT_WOULD_BLOCK)
                    return HT_OK;
                else if (status == HT_CLOSED)
                    http->state = HTTPS_OK;
                else if (status==HT_LOADED || status==HT_PAUSE) {
                    http->state = HTTPS_LOAD_CLIENT;
                } else
                    http->state = HTTPS_ERROR;
            } else
                http->state = HTTPS_ERROR;
            break;

        case HTTPS_LOAD_CLIENT:
        {
            HTRequest * client = HTList_removeFirstObject(http->clients);
            HTLoad(client, NO);
            http->state = HTTPS_BEGIN;
            break;
        }

        case HTTPS_OK:
            ServerCleanup(request, net, HT_IGNORE);
            return HT_OK;

        case HTTPS_ERROR:
            ServerCleanup(request, net, HT_ERROR);
            return HT_OK;
        }
    }
}