Home | History | Annotate | Download | only in libxml2

Lines Matching refs:ctxt

276  * @ctxt:  an HTTP context
284 xmlNanoHTTPScanURL(xmlNanoHTTPCtxtPtr ctxt, const char *URL) {
291 if (ctxt->protocol != NULL) {
292 xmlFree(ctxt->protocol);
293 ctxt->protocol = NULL;
295 if (ctxt->hostname != NULL) {
296 xmlFree(ctxt->hostname);
297 ctxt->hostname = NULL;
299 if (ctxt->path != NULL) {
300 xmlFree(ctxt->path);
301 ctxt->path = NULL;
303 if (ctxt->query != NULL) {
304 xmlFree(ctxt->query);
305 ctxt->query = NULL;
318 ctxt->protocol = xmlMemStrdup(uri->scheme);
323 ctxt->hostname = (char *) xmlCharStrndup(uri->server + 1, len -2);
325 ctxt->hostname = xmlMemStrdup(uri->server);
327 ctxt->hostname = xmlMemStrdup(uri->server);
329 ctxt->path = xmlMemStrdup(uri->path);
331 ctxt->path = xmlMemStrdup("/");
333 ctxt->query = xmlMemStrdup(uri->query);
335 ctxt->port = uri->port;
418 * @ctxt: an HTTP context
424 xmlNanoHTTPFreeCtxt(xmlNanoHTTPCtxtPtr ctxt) {
425 if (ctxt == NULL) return;
426 if (ctxt->hostname != NULL) xmlFree(ctxt->hostname);
427 if (ctxt->protocol != NULL) xmlFree(ctxt->protocol);
428 if (ctxt->path != NULL) xmlFree(ctxt->path);
429 if (ctxt->query != NULL) xmlFree(ctxt->query);
430 if (ctxt->out != NULL) xmlFree(ctxt->out);
431 if (ctxt->in != NULL) xmlFree(ctxt->in);
432 if (ctxt->contentType != NULL) xmlFree(ctxt->contentType);
433 if (ctxt->encoding != NULL) xmlFree(ctxt->encoding);
434 if (ctxt->mimeType != NULL) xmlFree(ctxt->mimeType);
435 if (ctxt->location != NULL) xmlFree(ctxt->location);
436 if (ctxt->authHeader != NULL) xmlFree(ctxt->authHeader);
438 if (ctxt->strm != NULL) {
439 inflateEnd(ctxt->strm);
440 xmlFree(ctxt->strm);
444 ctxt->state = XML_NANO_HTTP_NONE;
445 if (ctxt->fd != INVALID_SOCKET) closesocket(ctxt->fd);
446 ctxt->fd = INVALID_SOCKET;
447 xmlFree(ctxt);
452 * @ctxt: an HTTP context
459 xmlNanoHTTPSend(xmlNanoHTTPCtxtPtr ctxt, const char *xmt_ptr, int outlen)
469 if ((ctxt->state & XML_NANO_HTTP_WRITE) && (xmt_ptr != NULL)) {
471 int nsent = send(ctxt->fd, SEND_ARG2_CAST (xmt_ptr + total_sent),
494 if (ctxt->fd > FD_SETSIZE)
505 FD_SET(ctxt->fd, &wfd);
509 (void) select(ctxt->fd + 1, NULL, &wfd, NULL, &tv);
511 p.fd = ctxt->fd;
524 * @ctxt: an HTTP context
533 xmlNanoHTTPRecv(xmlNanoHTTPCtxtPtr ctxt)
543 while (ctxt->state & XML_NANO_HTTP_READ) {
544 if (ctxt->in == NULL) {
545 ctxt->in = (char *) xmlMallocAtomic(65000 * sizeof(char));
546 if (ctxt->in == NULL) {
548 ctxt->last = -1;
551 ctxt->inlen = 65000;
552 ctxt->inptr = ctxt->content = ctxt->inrptr = ctxt->in;
554 if (ctxt->inrptr > ctxt->in + XML_NANO_HTTP_CHUNK) {
555 int delta = ctxt->inrptr - ctxt->in;
556 int len = ctxt->inptr - ctxt->inrptr;
558 memmove(ctxt->in, ctxt->inrptr, len);
559 ctxt->inrptr -= delta;
560 ctxt->content -= delta;
561 ctxt->inptr -= delta;
563 if ((ctxt->in + ctxt->inlen) < (ctxt->inptr + XML_NANO_HTTP_CHUNK)) {
564 int d_inptr = ctxt->inptr - ctxt->in;
565 int d_content = ctxt->content - ctxt->in;
566 int d_inrptr = ctxt->inrptr - ctxt->in;
567 char *tmp_ptr = ctxt->in;
569 ctxt->inlen *= 2;
570 ctxt->in = (char *) xmlRealloc(tmp_ptr, ctxt->inlen);
571 if (ctxt->in == NULL) {
574 ctxt->last = -1;
577 ctxt->inptr = ctxt->in + d_inptr;
578 ctxt->content = ctxt->in + d_content;
579 ctxt->inrptr = ctxt->in + d_inrptr;
581 ctxt->last = recv(ctxt->fd, ctxt->inptr, XML_NANO_HTTP_CHUNK, 0);
582 if (ctxt->last > 0) {
583 ctxt->inptr += ctxt->last;
584 return (ctxt->last);
586 if (ctxt->last == 0) {
589 if (ctxt->last == -1) {
608 p.fd = ctxt->fd;
618 if (ctxt->fd > FD_SETSIZE)
631 FD_SET(ctxt->fd, &rfd);
637 if ((select(ctxt->fd + 1, &rfd, NULL, NULL, &tv) < 1)
650 * @ctxt: an HTTP context
660 xmlNanoHTTPReadLine(xmlNanoHTTPCtxtPtr ctxt) {
666 if (ctxt->inrptr == ctxt->inptr) {
667 if ( (rc = xmlNanoHTTPRecv(ctxt)) == 0) {
678 *bp = *ctxt->inrptr++;
693 * @ctxt: an HTTP context
706 xmlNanoHTTPScanAnswer(xmlNanoHTTPCtxtPtr ctxt, const char *line) {
741 ctxt->returnValue = ret;
742 ctxt->version = version;
747 if (ctxt->contentType != NULL)
748 xmlFree(ctxt->contentType);
749 ctxt->contentType = xmlMemStrdup(cur);
755 if (ctxt->mimeType != NULL)
756 xmlFree(ctxt->mimeType);
757 ctxt->mimeType = (char *) xmlStrndup(mime, last - mime);
758 charset = xmlStrstr(BAD_CAST ctxt->contentType, BAD_CAST "charset=");
765 if (ctxt->encoding != NULL)
766 xmlFree(ctxt->encoding);
767 ctxt->encoding = (char *) xmlStrndup(charset, last - charset);
772 if (ctxt->contentType != NULL) return;
774 ctxt->contentType = xmlMemStrdup(cur);
780 if (ctxt->mimeType != NULL)
781 xmlFree(ctxt->mimeType);
782 ctxt->mimeType = (char *) xmlStrndup(mime, last - mime);
783 charset = xmlStrstr(BAD_CAST ctxt->contentType, BAD_CAST "charset=");
790 if (ctxt->encoding != NULL)
791 xmlFree(ctxt->encoding);
792 ctxt->encoding = (char *) xmlStrndup(charset, last - charset);
797 if (ctxt->location != NULL)
798 xmlFree(ctxt->location);
802 xmlStrcat(tmp_http, (const xmlChar *) ctxt->hostname);
803 ctxt->location =
806 ctxt->location = xmlMemStrdup(cur);
811 if (ctxt->authHeader != NULL)
812 xmlFree(ctxt->authHeader);
813 ctxt->authHeader = xmlMemStrdup(cur);
817 if (ctxt->authHeader != NULL)
818 xmlFree(ctxt->authHeader);
819 ctxt->authHeader = xmlMemStrdup(cur);
825 ctxt->usesGzip = 1;
827 ctxt->strm = xmlMalloc(sizeof(z_stream));
829 if (ctxt->strm != NULL) {
830 ctxt->strm->zalloc = Z_NULL;
831 ctxt->strm->zfree = Z_NULL;
832 ctxt->strm->opaque = Z_NULL;
833 ctxt->strm->avail_in = 0;
834 ctxt->strm->next_in = Z_NULL;
836 inflateInit2( ctxt->strm, 31 );
842 ctxt->ContentLength = strtol( cur, NULL, 10 );
1275 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr) ctx;
1287 if (ctxt->usesGzip == 1) {
1288 if (ctxt->strm == NULL) return(0);
1290 ctxt->strm->next_out = dest;
1291 ctxt->strm->avail_out = len;
1292 ctxt->strm->avail_in = ctxt->inptr - ctxt->inrptr;
1294 while (ctxt->strm->avail_out > 0 &&
1295 (ctxt->strm->avail_in > 0 || xmlNanoHTTPRecv(ctxt) > 0)) {
1296 orig_avail_in = ctxt->strm->avail_in =
1297 ctxt->inptr - ctxt->inrptr - bytes_read;
1298 ctxt->strm->next_in = BAD_CAST (ctxt->inrptr + bytes_read);
1300 z_ret = inflate(ctxt->strm, Z_NO_FLUSH);
1301 bytes_read += orig_avail_in - ctxt->strm->avail_in;
1306 ctxt->inrptr += bytes_read;
1307 return(len - ctxt->strm->avail_out);
1311 while (ctxt->inptr - ctxt->inrptr < len) {
1312 if (xmlNanoHTTPRecv(ctxt) <= 0) break;
1314 if (ctxt->inptr - ctxt->inrptr < len)
1315 len = ctxt->inptr - ctxt->inrptr;
1316 memcpy(dest, ctxt->inrptr, len);
1317 ctxt->inrptr += len;
1330 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr) ctx;
1334 xmlNanoHTTPFreeCtxt(ctxt);
1359 xmlNanoHTTPCtxtPtr ctxt;
1375 ctxt = xmlNanoHTTPNewCtxt(URL);
1376 if (ctxt == NULL)
1379 ctxt = xmlNanoHTTPNewCtxt(redirURL);
1380 if (ctxt == NULL)
1382 ctxt->location = xmlMemStrdup(redirURL);
1385 if ((ctxt->protocol == NULL) || (strcmp(ctxt->protocol, "http"))) {
1387 xmlNanoHTTPFreeCtxt(ctxt);
1391 if (ctxt->hostname == NULL) {
1394 xmlNanoHTTPFreeCtxt(ctxt);
1399 blen = strlen(ctxt->hostname) * 2 + 16;
1403 blen = strlen(ctxt->hostname);
1404 ret = xmlNanoHTTPConnectHost(ctxt->hostname, ctxt->port);
1407 xmlNanoHTTPFreeCtxt(ctxt);
1411 ctxt->fd = ret;
1423 if (ctxt->query != NULL)
1425 blen += strlen(ctxt->query) + 1;
1426 blen += strlen(method) + strlen(ctxt->path) + 24;
1431 if (ctxt->port != 80) {
1440 xmlNanoHTTPFreeCtxt( ctxt );
1448 if (ctxt->port != 80) {
1450 method, ctxt->hostname,
1451 ctxt->port, ctxt->path );
1455 ctxt->hostname, ctxt->path);
1458 p += snprintf( p, blen - (p - bp), "%s %s", method, ctxt->path);
1460 if (ctxt->query != NULL)
1461 p += snprintf( p, blen - (p - bp), "?%s", ctxt->query);
1463 if (ctxt->port == 80) {
1465 ctxt->hostname);
1468 ctxt->hostname, ctxt->port);
1493 ctxt->outptr = ctxt->out = bp;
1494 ctxt->state = XML_NANO_HTTP_WRITE;
1495 blen = strlen( ctxt->out );
1497 xmt_bytes = xmlNanoHTTPSend(ctxt, ctxt->out, blen );
1503 ctxt->hostname );
1505 xmlNanoHTTPSend(ctxt, ctxt->out, blen );
1510 xmt_bytes = xmlNanoHTTPSend( ctxt, input, ilen );
1517 ctxt->hostname );
1519 xmlNanoHTTPSend( ctxt, input, ilen );
1523 ctxt->state = XML_NANO_HTTP_READ;
1525 while ((p = xmlNanoHTTPReadLine(ctxt)) != NULL) {
1527 ctxt->content = ctxt->inrptr;
1531 xmlNanoHTTPScanAnswer(ctxt, p);
1539 if ((ctxt->location != NULL) && (ctxt->returnValue >= 300) &&
1540 (ctxt->returnValue < 400)) {
1543 "\nRedirect to: %s\n", ctxt->location);
1545 while ( xmlNanoHTTPRecv(ctxt) > 0 )
1551 redirURL = xmlMemStrdup(ctxt->location);
1552 xmlNanoHTTPFreeCtxt(ctxt);
1555 xmlNanoHTTPFreeCtxt(ctxt);
1565 if (ctxt->contentType != NULL)
1566 *contentType = xmlMemStrdup(ctxt->contentType);
1581 if (ctxt->contentType != NULL)
1584 ctxt->returnValue, ctxt->contentType);
1588 ctxt->returnValue);
1591 return((void *) ctxt);
1633 void *ctxt = NULL;
1640 ctxt = xmlNanoHTTPOpen(URL, contentType);
1641 if (ctxt == NULL) return(-1);
1648 xmlNanoHTTPClose(ctxt);
1657 xmlNanoHTTPFetchContent( ctxt, &buf, &len );
1664 xmlNanoHTTPClose(ctxt);
1672 * @ctxt: the HTTP context
1681 xmlNanoHTTPSave(void *ctxt, const char *filename) {
1687 if ((ctxt == NULL) || (filename == NULL)) return(-1);
1694 xmlNanoHTTPClose(ctxt);
1699 xmlNanoHTTPFetchContent( ctxt, &buf, &len );
1706 xmlNanoHTTPClose(ctxt);
1722 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr) ctx;
1724 if (ctxt == NULL) return(-1);
1726 return(ctxt->returnValue);
1740 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr) ctx;
1742 if (ctxt == NULL) return(NULL);
1744 return(ctxt->authHeader);
1759 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr)ctx;
1761 return ( ( ctxt == NULL ) ? -1 : ctxt->ContentLength );
1774 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr)ctx;
1776 return ( ( ctxt == NULL ) ? NULL : ctxt->location );
1789 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr)ctx;
1791 return ( ( ctxt == NULL ) ? NULL : ctxt->encoding );
1804 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr)ctx;
1806 return ( ( ctxt == NULL ) ? NULL : ctxt->mimeType );
1823 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr)ctx;
1841 if ( ( ctxt == NULL ) || ( ctxt->content == NULL ) ) {
1847 rcvd_lgth = ctxt->inptr - ctxt->content;
1849 while ( (cur_lgth = xmlNanoHTTPRecv( ctxt )) > 0 ) {
1852 if ( (ctxt->ContentLength > 0) && (rcvd_lgth >= ctxt->ContentLength) )
1856 *ptr = ctxt->content;
1859 if ( ( ctxt->ContentLength > 0 ) && ( rcvd_lgth < ctxt->ContentLength ) )