Home | History | Annotate | Download | only in libxml2

Lines Matching defs:ctxt

272  * @ctxt:  an HTTP context
280 xmlNanoHTTPScanURL(xmlNanoHTTPCtxtPtr ctxt, const char *URL) {
285 if (ctxt->protocol != NULL) {
286 xmlFree(ctxt->protocol);
287 ctxt->protocol = NULL;
289 if (ctxt->hostname != NULL) {
290 xmlFree(ctxt->hostname);
291 ctxt->hostname = NULL;
293 if (ctxt->path != NULL) {
294 xmlFree(ctxt->path);
295 ctxt->path = NULL;
297 if (ctxt->query != NULL) {
298 xmlFree(ctxt->query);
299 ctxt->query = NULL;
312 ctxt->protocol = xmlMemStrdup(uri->scheme);
313 ctxt->hostname = xmlMemStrdup(uri->server);
315 ctxt->path = xmlMemStrdup(uri->path);
317 ctxt->path = xmlMemStrdup("/");
319 ctxt->query = xmlMemStrdup(uri->query);
321 ctxt->port = uri->port;
404 * @ctxt: an HTTP context
410 xmlNanoHTTPFreeCtxt(xmlNanoHTTPCtxtPtr ctxt) {
411 if (ctxt == NULL) return;
412 if (ctxt->hostname != NULL) xmlFree(ctxt->hostname);
413 if (ctxt->protocol != NULL) xmlFree(ctxt->protocol);
414 if (ctxt->path != NULL) xmlFree(ctxt->path);
415 if (ctxt->query != NULL) xmlFree(ctxt->query);
416 if (ctxt->out != NULL) xmlFree(ctxt->out);
417 if (ctxt->in != NULL) xmlFree(ctxt->in);
418 if (ctxt->contentType != NULL) xmlFree(ctxt->contentType);
419 if (ctxt->encoding != NULL) xmlFree(ctxt->encoding);
420 if (ctxt->mimeType != NULL) xmlFree(ctxt->mimeType);
421 if (ctxt->location != NULL) xmlFree(ctxt->location);
422 if (ctxt->authHeader != NULL) xmlFree(ctxt->authHeader);
424 if (ctxt->strm != NULL) {
425 inflateEnd(ctxt->strm);
426 xmlFree(ctxt->strm);
430 ctxt->state = XML_NANO_HTTP_NONE;
431 if (ctxt->fd != INVALID_SOCKET) closesocket(ctxt->fd);
432 ctxt->fd = INVALID_SOCKET;
433 xmlFree(ctxt);
438 * @ctxt: an HTTP context
445 xmlNanoHTTPSend(xmlNanoHTTPCtxtPtr ctxt, const char *xmt_ptr, int outlen)
455 if ((ctxt->state & XML_NANO_HTTP_WRITE) && (xmt_ptr != NULL)) {
457 int nsent = send(ctxt->fd, xmt_ptr + total_sent,
480 if (ctxt->fd > FD_SETSIZE)
491 FD_SET(ctxt->fd, &wfd);
495 (void) select(ctxt->fd + 1, NULL, &wfd, NULL, &tv);
497 p.fd = ctxt->fd;
510 * @ctxt: an HTTP context
519 xmlNanoHTTPRecv(xmlNanoHTTPCtxtPtr ctxt)
529 while (ctxt->state & XML_NANO_HTTP_READ) {
530 if (ctxt->in == NULL) {
531 ctxt->in = (char *) xmlMallocAtomic(65000 * sizeof(char));
532 if (ctxt->in == NULL) {
534 ctxt->last = -1;
537 ctxt->inlen = 65000;
538 ctxt->inptr = ctxt->content = ctxt->inrptr = ctxt->in;
540 if (ctxt->inrptr > ctxt->in + XML_NANO_HTTP_CHUNK) {
541 int delta = ctxt->inrptr - ctxt->in;
542 int len = ctxt->inptr - ctxt->inrptr;
544 memmove(ctxt->in, ctxt->inrptr, len);
545 ctxt->inrptr -= delta;
546 ctxt->content -= delta;
547 ctxt->inptr -= delta;
549 if ((ctxt->in + ctxt->inlen) < (ctxt->inptr + XML_NANO_HTTP_CHUNK)) {
550 int d_inptr = ctxt->inptr - ctxt->in;
551 int d_content = ctxt->content - ctxt->in;
552 int d_inrptr = ctxt->inrptr - ctxt->in;
553 char *tmp_ptr = ctxt->in;
555 ctxt->inlen *= 2;
556 ctxt->in = (char *) xmlRealloc(tmp_ptr, ctxt->inlen);
557 if (ctxt->in == NULL) {
560 ctxt->last = -1;
563 ctxt->inptr = ctxt->in + d_inptr;
564 ctxt->content = ctxt->in + d_content;
565 ctxt->inrptr = ctxt->in + d_inrptr;
567 ctxt->last = recv(ctxt->fd, ctxt->inptr, XML_NANO_HTTP_CHUNK, 0);
568 if (ctxt->last > 0) {
569 ctxt->inptr += ctxt->last;
570 return (ctxt->last);
572 if (ctxt->last == 0) {
575 if (ctxt->last == -1) {
594 p.fd = ctxt->fd;
604 if (ctxt->fd > FD_SETSIZE)
617 FD_SET(ctxt->fd, &rfd);
623 if ((select(ctxt->fd + 1, &rfd, NULL, NULL, &tv) < 1)
636 * @ctxt: an HTTP context
646 xmlNanoHTTPReadLine(xmlNanoHTTPCtxtPtr ctxt) {
652 if (ctxt->inrptr == ctxt->inptr) {
653 if ( (rc = xmlNanoHTTPRecv(ctxt)) == 0) {
664 *bp = *ctxt->inrptr++;
679 * @ctxt: an HTTP context
692 xmlNanoHTTPScanAnswer(xmlNanoHTTPCtxtPtr ctxt, const char *line) {
727 ctxt->returnValue = ret;
728 ctxt->version = version;
733 if (ctxt->contentType != NULL)
734 xmlFree(ctxt->contentType);
735 ctxt->contentType = xmlMemStrdup(cur);
741 if (ctxt->mimeType != NULL)
742 xmlFree(ctxt->mimeType);
743 ctxt->mimeType = (char *) xmlStrndup(mime, last - mime);
744 charset = xmlStrstr(BAD_CAST ctxt->contentType, BAD_CAST "charset=");
751 if (ctxt->encoding != NULL)
752 xmlFree(ctxt->encoding);
753 ctxt->encoding = (char *) xmlStrndup(charset, last - charset);
758 if (ctxt->contentType != NULL) return;
760 ctxt->contentType = xmlMemStrdup(cur);
766 if (ctxt->mimeType != NULL)
767 xmlFree(ctxt->mimeType);
768 ctxt->mimeType = (char *) xmlStrndup(mime, last - mime);
769 charset = xmlStrstr(BAD_CAST ctxt->contentType, BAD_CAST "charset=");
776 if (ctxt->encoding != NULL)
777 xmlFree(ctxt->encoding);
778 ctxt->encoding = (char *) xmlStrndup(charset, last - charset);
783 if (ctxt->location != NULL)
784 xmlFree(ctxt->location);
788 xmlStrcat(tmp_http, (const xmlChar *) ctxt->hostname);
789 ctxt->location =
792 ctxt->location = xmlMemStrdup(cur);
797 if (ctxt->authHeader != NULL)
798 xmlFree(ctxt->authHeader);
799 ctxt->authHeader = xmlMemStrdup(cur);
803 if (ctxt->authHeader != NULL)
804 xmlFree(ctxt->authHeader);
805 ctxt->authHeader = xmlMemStrdup(cur);
811 ctxt->usesGzip = 1;
813 ctxt->strm = xmlMalloc(sizeof(z_stream));
815 if (ctxt->strm != NULL) {
816 ctxt->strm->zalloc = Z_NULL;
817 ctxt->strm->zfree = Z_NULL;
818 ctxt->strm->opaque = Z_NULL;
819 ctxt->strm->avail_in = 0;
820 ctxt->strm->next_in = Z_NULL;
822 inflateInit2( ctxt->strm, 31 );
828 ctxt->ContentLength = strtol( cur, NULL, 10 );
1257 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr) ctx;
1269 if (ctxt->usesGzip == 1) {
1270 if (ctxt->strm == NULL) return(0);
1272 ctxt->strm->next_out = dest;
1273 ctxt->strm->avail_out = len;
1274 ctxt->strm->avail_in = ctxt->inptr - ctxt->inrptr;
1276 while (ctxt->strm->avail_out > 0 &&
1277 (ctxt->strm->avail_in > 0 || xmlNanoHTTPRecv(ctxt) > 0)) {
1278 orig_avail_in = ctxt->strm->avail_in =
1279 ctxt->inptr - ctxt->inrptr - bytes_read;
1280 ctxt->strm->next_in = BAD_CAST (ctxt->inrptr + bytes_read);
1282 z_ret = inflate(ctxt->strm, Z_NO_FLUSH);
1283 bytes_read += orig_avail_in - ctxt->strm->avail_in;
1288 ctxt
1289 return(len - ctxt->strm->avail_out);
1293 while (ctxt->inptr - ctxt->inrptr < len) {
1294 if (xmlNanoHTTPRecv(ctxt) <= 0) break;
1296 if (ctxt->inptr - ctxt->inrptr < len)
1297 len = ctxt->inptr - ctxt->inrptr;
1298 memcpy(dest, ctxt->inrptr, len);
1299 ctxt->inrptr += len;
1312 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr) ctx;
1316 xmlNanoHTTPFreeCtxt(ctxt);
1341 xmlNanoHTTPCtxtPtr ctxt;
1357 ctxt = xmlNanoHTTPNewCtxt(URL);
1359 ctxt = xmlNanoHTTPNewCtxt(redirURL);
1360 ctxt->location = xmlMemStrdup(redirURL);
1363 if ( ctxt == NULL ) {
1367 if ((ctxt->protocol == NULL) || (strcmp(ctxt->protocol, "http"))) {
1369 xmlNanoHTTPFreeCtxt(ctxt);
1373 if (ctxt->hostname == NULL) {
1376 xmlNanoHTTPFreeCtxt(ctxt);
1381 blen = strlen(ctxt->hostname) * 2 + 16;
1385 blen = strlen(ctxt->hostname);
1386 ret = xmlNanoHTTPConnectHost(ctxt->hostname, ctxt->port);
1389 xmlNanoHTTPFreeCtxt(ctxt);
1393 ctxt->fd = ret;
1405 if (ctxt->query != NULL)
1407 blen += strlen(ctxt->query) + 1;
1408 blen += strlen(method) + strlen(ctxt->path) + 24;
1413 if (ctxt->port != 80) {
1422 xmlNanoHTTPFreeCtxt( ctxt );
1430 if (ctxt->port != 80) {
1432 method, ctxt->hostname,
1433 ctxt->port, ctxt->path );
1437 ctxt->hostname, ctxt->path);
1440 p += snprintf( p, blen - (p - bp), "%s %s", method, ctxt->path);
1442 if (ctxt->query != NULL)
1443 p += snprintf( p, blen - (p - bp), "?%s", ctxt->query);
1445 if (ctxt->port == 80) {
1447 ctxt->hostname);
1450 ctxt->hostname, ctxt->port);
1475 ctxt->outptr = ctxt->out = bp;
1476 ctxt->state = XML_NANO_HTTP_WRITE;
1477 blen = strlen( ctxt->out );
1479 xmt_bytes = xmlNanoHTTPSend(ctxt, ctxt->out, blen );
1485 ctxt->hostname );
1487 xmlNanoHTTPSend(ctxt, ctxt->out, blen );
1492 xmt_bytes = xmlNanoHTTPSend( ctxt, input, ilen );
1499 ctxt->hostname );
1501 xmlNanoHTTPSend( ctxt, input, ilen );
1505 ctxt->state = XML_NANO_HTTP_READ;
1507 while ((p = xmlNanoHTTPReadLine(ctxt)) != NULL) {
1509 ctxt->content = ctxt->inrptr;
1513 xmlNanoHTTPScanAnswer(ctxt, p);
1521 if ((ctxt->location != NULL) && (ctxt->returnValue >= 300) &&
1522 (ctxt->returnValue < 400)) {
1525 "\nRedirect to: %s\n", ctxt->location);
1527 while ( xmlNanoHTTPRecv(ctxt) > 0 ) ;
1532 redirURL = xmlMemStrdup(ctxt->location);
1533 xmlNanoHTTPFreeCtxt(ctxt);
1536 xmlNanoHTTPFreeCtxt(ctxt);
1546 if (ctxt->contentType != NULL)
1547 *contentType = xmlMemStrdup(ctxt->contentType);
1562 if (ctxt->contentType != NULL)
1565 ctxt->returnValue, ctxt->contentType);
1569 ctxt->returnValue);
1572 return((void *) ctxt);
1614 void *ctxt = NULL;
1621 ctxt = xmlNanoHTTPOpen(URL, contentType);
1622 if (ctxt == NULL) return(-1);
1629 xmlNanoHTTPClose(ctxt);
1638 xmlNanoHTTPFetchContent( ctxt, &buf, &len );
1645 xmlNanoHTTPClose(ctxt);
1653 * @ctxt: the HTTP context
1662 xmlNanoHTTPSave(void *ctxt, const char *filename) {
1668 if ((ctxt == NULL) || (filename == NULL)) return(-1);
1675 xmlNanoHTTPClose(ctxt);
1680 xmlNanoHTTPFetchContent( ctxt, &buf, &len );
1687 xmlNanoHTTPClose(ctxt);
1703 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr) ctx;
1705 if (ctxt == NULL) return(-1);
1707 return(ctxt->returnValue);
1721 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr) ctx;
1723 if (ctxt == NULL) return(NULL);
1725 return(ctxt->authHeader);
1740 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr)ctx;
1742 return ( ( ctxt == NULL ) ? -1 : ctxt->ContentLength );
1755 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr)ctx;
1757 return ( ( ctxt == NULL ) ? NULL : ctxt->location );
1770 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr)ctx;
1772 return ( ( ctxt == NULL ) ? NULL : ctxt->encoding );
1785 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr)ctx;
1787 return ( ( ctxt == NULL ) ? NULL : ctxt->mimeType );
1804 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr)ctx;
1822 if ( ( ctxt == NULL ) || ( ctxt->content == NULL ) ) {
1828 rcvd_lgth = ctxt->inptr - ctxt->content;
1830 while ( (cur_lgth = xmlNanoHTTPRecv( ctxt )) > 0 ) {
1833 if ( (ctxt->ContentLength > 0) && (rcvd_lgth >= ctxt->ContentLength) )
1837 *ptr = ctxt->content;
1840 if ( ( ctxt->ContentLength > 0 ) && ( rcvd_lgth < ctxt->ContentLength ) )