Esempio n. 1
0
void HText_beginAnchor (HText * text, HTChildAnchor * anchor)
{
    TextAnchor * a;
    if (text && anchor) {
	Robot * mr = (Robot *) HTRequest_context(text->request);
	HTAnchor * dest = HTAnchor_followMainLink((HTAnchor *) anchor);
	HTParentAnchor * dest_parent = HTAnchor_parent(dest);
	char * uri = HTAnchor_address((HTAnchor *) dest_parent);

#if 0
	if (SHOW_MSG) HTTrace("Robot....... Found `%s\' \n", uri ? uri : "NULL");
#endif	
	if (uri) {
	    HTList_addObject(mr->urilist, (void *) uri);
	    mr->count++;
	}

	if ((a = (TextAnchor  *) HT_MALLOC(sizeof(*a))) == NULL)
	    HT_OUTOFMEM("HText_beginAnchor");
	if (text->last_anchor) {
	    text->last_anchor->next = a;
	} else {
	    text->first_anchor = a;
	}
	a->next = 0;
	a->anchor = anchor;
	text->last_anchor = a;
    
	if (HTAnchor_followMainLink((HTAnchor*)anchor)) {
	    a->number = ++(text->anchors);
	} else {
	    a->number = 0;
	}
    }
}
Esempio n. 2
0
PRIVATE void rdf_delete_userData(void *userdata)
{
  prolog_term parsed_result, status_term;
  USERDATA *me = (USERDATA *)userdata;
  HTRequest *request = me->request;

  if (request) {
    parsed_result =
      ((REQUEST_CONTEXT *)HTRequest_context(request))->request_result;
    status_term =
      ((REQUEST_CONTEXT *)HTRequest_context(request))->status_term;
  }
  else return;

#ifdef LIBWWW_DEBUG
  xsb_dbgmsg((LOG_DEBUG,"***In rdf_delete_userData(%s)", RequestID(request)));
#endif

#ifdef LIBWWW_DEBUG_VERBOSE
  print_prolog_term(me->parsed_term, "Current parse value");
#endif

  /* terminate the parsed prolog terms list */
  extern_c2p_nil(me->parsed_term_tail);

  /* pass the result to the outside world */
  if (is_var(me->parsed_term))
    extern_p2p_unify(parsed_result, me->parsed_term);
  else
    xsb_abort("[LIBWWW_REQUEST] Request %s: Arg 4 (Result) must be unbound variable",
	      RequestID(request));

  HT_FREE(me);

#ifdef LIBWWW_DEBUG
  xsb_dbgmsg((LOG_DEBUG,"***Request %s: freed the USERDATA object", RequestID(request)));
#endif

  return;
}
Esempio n. 3
0
PUBLIC BOOL UserProgress (HTRequest * request, HTAlertOpcode op,
                          int msgnum, const char * dfault, void * input,
                          HTAlertPar * reply)
{
    char * msg = HTDialog_progressMessage(request, op, msgnum, dfault, input);
    CRequest * req = (CRequest *) HTRequest_context(request);
    ASSERT(request != NULL);
    ASSERT(req != NULL);
    CProgressCtrl * progress = req->GetProgressBar();

    switch (op) {
    case HT_PROG_READ:
        {
            long cl = HTAnchor_length(HTRequest_anchor(request));
            if (cl > 0) {
                long b_read = HTRequest_bodyRead(request);
                double pro = (double) b_read/cl*100;
		progress->SetPos((int) pro);
            }
        }
        break;
        
    case HT_PROG_WRITE:
        {
            long cl = HTAnchor_length(HTRequest_entityAnchor(request));
            if (cl > 0) {
                long b_written = HTRequest_bodyWritten(request);
                double pro = (double) b_written/cl*100;
		progress->SetPos((int) pro);
            }
        }
        break;
    }

    // Update pane 0 of the status bar
    if (msg) {
	CWinComDoc * doc = req->m_pDoc;
	if (doc) {
	    POSITION pos = doc->GetFirstViewPosition();
	    CView * view = doc->GetNextView( pos );
	    CMainFrame * mainframe = (CMainFrame *) view->GetParentFrame();
	    mainframe->m_wndStatusBar.SetPaneText(ID_SEPARATOR, msg);
	}
	HT_FREE(msg);
    }
    return YES;
}
Esempio n. 4
0
HText * HText_new2 (HTRequest * request, HTParentAnchor * anchor,
		    HTStream * stream)
{
    HText * me;
    Robot * mr = (Robot *) HTRequest_context(request);
    if ((me = (HText *) HT_CALLOC(1, sizeof(HText))) == NULL)
        HT_OUTOFMEM("HText_new2");

    /* Bind the HText object together with the Request Object */
    me->request = request;
    me->first_anchor = me->last_anchor = 0;
    me->anchors = 0;

    /* Add this HText object to our list */
    mr->htext = me;
    return me;
}
Esempio n. 5
0
/*	terminate_handler
**	-----------------
**	This function is registered to handle the result of the request
*/
PRIVATE int terminate_handler (HTRequest * request, HTResponse * response,
			       void * param, int status) 
{
    ComLine * cl = (ComLine *) HTRequest_context(request);
    if (status == HT_LOADED) {
	if (cl) {
	    if (cl->flags & CL_COUNT) {
		HTPrint("Content Length found to be %ld\n",
			 HTAnchor_length(cl->anchor));
	    }
	}
    } else {
	HTAlertCallback *cbf = HTAlert_find(HT_A_MESSAGE);
	if (cbf) (*cbf)(request, HT_A_MESSAGE, HT_MSG_NULL, NULL,
			HTRequest_error(request), NULL);
    }
    Cleanup(cl, (status/100 == 2) ? 0 : -1);
    return HT_OK;
}
Esempio n. 6
0
PRIVATE USERDATA *rdf_create_userData(HTRDF     *parser,
				      HTRequest *request,
				      HTStream  *target_stream)
{
  USERDATA *me = NULL;
#ifdef LIBWWW_DEBUG
  xsb_dbgmsg((LOG_DEBUG,"***Start rdf_create_userData: Request %s", RequestID(request)));
#endif
  if (parser) {
    /* make sure that MIME type is appropriate for RDF */
    if (!verifyMIMEformat(request, RDFPARSE)) {
      /*
	HTStream * input = HTRequest_inputStream(request);
	(*input->isa->abort)(input, NULL);
	HTRequest_setInputStream(request,NULL);
	HTRequest_kill(request);
	return NULL;
      */
      xsb_abort("[LIBWWW_REQUEST] Bug: Request type/MIME type mismatch");
    }
    if ((me = (USERDATA *) HT_CALLOC(1, sizeof(USERDATA))) == NULL)
      HT_OUTOFMEM("libwww_parse_rdf");
    me->delete_method = rdf_delete_userData;
    me->parser = parser;
    me->request = request;
    me->target = target_stream;
    me->parsed_term = extern_p2p_new();
    extern_c2p_list(me->parsed_term);
    me->parsed_term_tail = me->parsed_term;
  }
  
#ifdef LIBWWW_DEBUG
  xsb_dbgmsg((LOG_DEBUG,"***End rdf_create_userData: Request %s", RequestID(request)));
#endif

  /* Hook up userdata to the request context */
  ((REQUEST_CONTEXT *)HTRequest_context(request))->userdata = (void *)me;

  return me;
}
Esempio n. 7
0
PRIVATE BOOL PromptUsernameAndPassword (HTRequest * request, HTAlertOpcode op,
					int msgnum, const char * dfault,
					void * input, HTAlertPar * reply)
{
    ComLine * cl = (ComLine *) HTRequest_context(request);
    char * realm = (char *) input;
    if (request && cl) {

	/*
	**  If we have a realm then check that it matches the realm
	**  that we got from the server.
	*/
	if (realm && cl->realm && !strcmp(cl->realm, realm)) {
	    HTAlert_setReplyMessage(reply, cl->user ? cl->user : "");
	    HTAlert_setReplySecret(reply, cl->password ? cl->password : "");
	    return YES;
	} else {
	    BOOL status = HTPrompt(request, op, msgnum, dfault, input, reply);
	    return status ?
		HTPromptPassword(request, op, HT_MSG_PW, dfault, input, reply) : NO;
	}
    }
    return NO;
}
Esempio n. 8
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;
        }
    }
}