Ejemplo n.º 1
0
PUBLIC HText *	LMHText_new (
	HTRequest * request,
	HTParentAnchor * anchor,
	HTStream *outstrm)
{
    HTLine * line;
    HText * self;
    if ((self = (HText  *) HT_CALLOC(1, sizeof(*self))) == NULL)
/*        HT_OUTOFMEM("HText"); */
	return self;
    
    self->pLm = Context_getLineMode(request);
    if (!loaded_texts) loaded_texts = HTList_new();
    HTList_addObject(loaded_texts, self);
    if (HTList_count(loaded_texts) >= LOADED_LIMIT) {
        HTTRACE(CACHE_TRACE, "MemoryCache. Freeing off cached doc.\n"); 
        HText_free((HText *)HTList_removeFirstObject(loaded_texts));
    }
    
    if ((line = self->last_line = (HTLine *) HT_MALLOC(LINE_SIZE(MAX_LINE))) == NULL)
	HT_OUTOFMEM("HText_New");
    line->next = line->prev = line;
    line->offset = line->size = 0;
    self->lines = self->chars = 0;
    self->title = 0;
    self->first_anchor = self->last_anchor = self->current_anchor = 0;
    self->style = &default_style;
    self->top_of_screen = 0;
    self->node_anchor = anchor;
    self->last_anchor_number = 0;	/* Numbering of them for references */
    self->stale = YES;
    
    self->target = NULL;
    
    HTAnchor_setDocument(anchor, (void *) self);

    clear_screen();
    HTMainText = self;
    HTMainAnchor = anchor;
    self->display_on_the_fly = DISPLAY_LINES;
    self->all_pages = NO;	/* One page at a time on the fly */
    
    if (!space_string) {	/* Make a blank line */
        char *p;
	if ((space_string = (char  *) HT_MALLOC(HTScreenWidth+1)) == NULL)
	    HT_OUTOFMEM("HText_New");
        for (p=space_string; p<space_string+HTScreenWidth; p++) 
            *p = ' '; 		/* Used for printfs later */
        space_string[HTScreenWidth] = '\0'; 
    }
    
    return self;
}
Ejemplo 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;
        }
    }
}
Ejemplo n.º 3
0
BOOL HTQueue_dequeue(HTList *me)
{
  return HTList_removeFirstObject(me) ? YES : NO;
}