Home | History | Annotate | Download | only in libxml2

Lines Matching refs:ctxt

269  * @ctxt:  an HTTP context
277 xmlNanoHTTPScanURL(xmlNanoHTTPCtxtPtr ctxt, const char *URL) {
284 if (ctxt->protocol != NULL) {
285 xmlFree(ctxt->protocol);
286 ctxt->protocol = NULL;
288 if (ctxt->hostname != NULL) {
289 xmlFree(ctxt->hostname);
290 ctxt->hostname = NULL;
292 if (ctxt->path != NULL) {
293 xmlFree(ctxt->path);
294 ctxt->path = NULL;
296 if (ctxt->query != NULL) {
297 xmlFree(ctxt->query);
298 ctxt->query = NULL;
311 ctxt->protocol = xmlMemStrdup(uri->scheme);
316 ctxt->hostname = (char *) xmlCharStrndup(uri->server + 1, len -2);
318 ctxt->hostname = xmlMemStrdup(uri->server);
320 ctxt->hostname = xmlMemStrdup(uri->server);
322 ctxt->path = xmlMemStrdup(uri->path);
324 ctxt->path = xmlMemStrdup("/");
326 ctxt->query = xmlMemStrdup(uri->query);
328 ctxt->port = uri->port;
411 * @ctxt: an HTTP context
417 xmlNanoHTTPFreeCtxt(xmlNanoHTTPCtxtPtr ctxt) {
418 if (ctxt == NULL) return;
419 if (ctxt->hostname != NULL) xmlFree(ctxt->hostname);
420 if (ctxt->protocol != NULL) xmlFree(ctxt->protocol);
421 if (ctxt->path != NULL) xmlFree(ctxt->path);
422 if (ctxt->query != NULL) xmlFree(ctxt->query);
423 if (ctxt->out != NULL) xmlFree(ctxt->out);
424 if (ctxt->in != NULL) xmlFree(ctxt->in);
425 if (ctxt->contentType != NULL) xmlFree(ctxt->contentType);
426 if (ctxt->encoding != NULL) xmlFree(ctxt->encoding);
427 if (ctxt->mimeType != NULL) xmlFree(ctxt->mimeType);
428 if (ctxt->location != NULL) xmlFree(ctxt->location);
429 if (ctxt->authHeader != NULL) xmlFree(ctxt->authHeader);
431 if (ctxt->strm != NULL) {
432 inflateEnd(ctxt->strm);
433 xmlFree(ctxt->strm);
437 ctxt->state = XML_NANO_HTTP_NONE;
438 if (ctxt->fd != INVALID_SOCKET) closesocket(ctxt->fd);
439 ctxt->fd = INVALID_SOCKET;
440 xmlFree(ctxt);
445 * @ctxt: an HTTP context
452 xmlNanoHTTPSend(xmlNanoHTTPCtxtPtr ctxt, const char *xmt_ptr, int outlen)
462 if ((ctxt->state & XML_NANO_HTTP_WRITE) && (xmt_ptr != NULL)) {
464 int nsent = send(ctxt->fd, SEND_ARG2_CAST (xmt_ptr + total_sent),
487 if (ctxt->fd > FD_SETSIZE)
498 FD_SET(ctxt->fd, &wfd);
502 (void) select(ctxt->fd + 1, NULL, &wfd, NULL, &tv);
504 p.fd = ctxt->fd;
517 * @ctxt: an HTTP context
526 xmlNanoHTTPRecv(xmlNanoHTTPCtxtPtr ctxt)
536 while (ctxt->state & XML_NANO_HTTP_READ) {
537 if (ctxt->in == NULL) {
538 ctxt->in = (char *) xmlMallocAtomic(65000 * sizeof(char));
539 if (ctxt->in == NULL) {
541 ctxt->last = -1;
544 ctxt->inlen = 65000;
545 ctxt->inptr = ctxt->content = ctxt->inrptr = ctxt->in;
547 if (ctxt->inrptr > ctxt->in + XML_NANO_HTTP_CHUNK) {
548 int delta = ctxt->inrptr - ctxt->in;
549 int len = ctxt->inptr - ctxt->inrptr;
551 memmove(ctxt->in, ctxt->inrptr, len);
552 ctxt->inrptr -= delta;
553 ctxt->content -= delta;
554 ctxt->inptr -= delta;
556 if ((ctxt->in + ctxt->inlen) < (ctxt->inptr + XML_NANO_HTTP_CHUNK)) {
557 int d_inptr = ctxt->inptr - ctxt->in;
558 int d_content = ctxt->content - ctxt->in;
559 int d_inrptr = ctxt->inrptr - ctxt->in;
560 char *tmp_ptr = ctxt->in;
562 ctxt->inlen *= 2;
563 ctxt->in = (char *) xmlRealloc(tmp_ptr, ctxt->inlen);
564 if (ctxt->in == NULL) {
567 ctxt->last = -1;
570 ctxt->inptr = ctxt->in + d_inptr;
571 ctxt->content = ctxt->in + d_content;
572 ctxt->inrptr = ctxt->in + d_inrptr;
574 ctxt->last = recv(ctxt->fd, ctxt->inptr, XML_NANO_HTTP_CHUNK, 0);
575 if (ctxt->last > 0) {
576 ctxt->inptr += ctxt->last;
577 return (ctxt->last);
579 if (ctxt->last == 0) {
582 if (ctxt->last == -1) {
601 p.fd = ctxt->fd;
611 if (ctxt->fd > FD_SETSIZE)
624 FD_SET(ctxt->fd, &rfd);
630 if ((select(ctxt->fd + 1, &rfd, NULL, NULL, &tv) < 1)
643 * @ctxt: an HTTP context
653 xmlNanoHTTPReadLine(xmlNanoHTTPCtxtPtr ctxt) {
659 if (ctxt->inrptr == ctxt->inptr) {
660 if ( (rc = xmlNanoHTTPRecv(ctxt)) == 0) {
671 *bp = *ctxt->inrptr++;
686 * @ctxt: an HTTP context
699 xmlNanoHTTPScanAnswer(xmlNanoHTTPCtxtPtr ctxt, const char *line) {
734 ctxt->returnValue = ret;
735 ctxt->version = version;
740 if (ctxt->contentType != NULL)
741 xmlFree(ctxt->contentType);
742 ctxt->contentType = xmlMemStrdup(cur);
748 if (ctxt->mimeType != NULL)
749 xmlFree(ctxt->mimeType);
750 ctxt->mimeType = (char *) xmlStrndup(mime, last - mime);
751 charset = xmlStrstr(BAD_CAST ctxt->contentType, BAD_CAST "charset=");
758 if (ctxt->encoding != NULL)
759 xmlFree(ctxt->encoding);
760 ctxt->encoding = (char *) xmlStrndup(charset, last - charset);
765 if (ctxt->contentType != NULL) return;
767 ctxt->contentType = xmlMemStrdup(cur);
773 if (ctxt->mimeType != NULL)
774 xmlFree(ctxt->mimeType);
775 ctxt->mimeType = (char *) xmlStrndup(mime, last - mime);
776 charset = xmlStrstr(BAD_CAST ctxt->contentType, BAD_CAST "charset=");
783 if (ctxt->encoding != NULL)
784 xmlFree(ctxt->encoding);
785 ctxt->encoding = (char *) xmlStrndup(charset, last - charset);
790 if (ctxt->location != NULL)
791 xmlFree(ctxt->location);
795 xmlStrcat(tmp_http, (const xmlChar *) ctxt->hostname);
796 ctxt->location =
799 ctxt->location = xmlMemStrdup(cur);
804 if (ctxt->authHeader != NULL)
805 xmlFree(ctxt->authHeader);
806 ctxt->authHeader = xmlMemStrdup(cur);
810 if (ctxt->authHeader != NULL)
811 xmlFree(ctxt->authHeader);
812 ctxt->authHeader = xmlMemStrdup(cur);
818 ctxt->usesGzip = 1;
820 ctxt->strm = xmlMalloc(sizeof(z_stream));
822 if (ctxt->strm != NULL) {
823 ctxt->strm->zalloc = Z_NULL;
824 ctxt->strm->zfree = Z_NULL;
825 ctxt->strm->opaque = Z_NULL;
826 ctxt->strm->avail_in = 0;
827 ctxt->strm->next_in = Z_NULL;
829 inflateInit2( ctxt->strm, 31 );
835 ctxt->ContentLength = strtol( cur, NULL, 10 );
1267 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr) ctx;
1279 if (ctxt->usesGzip == 1) {
1280 if (ctxt->strm == NULL) return(0);
1282 ctxt->strm->next_out = dest;
1283 ctxt->strm->avail_out = len;
1284 ctxt->strm->avail_in = ctxt->inptr - ctxt->inrptr;
1286 while (ctxt->strm->avail_out > 0 &&
1287 (ctxtctxt) > 0)) {
1288 orig_avail_in = ctxt->strm->avail_in =
1289 ctxt->inptr - ctxt->inrptr - bytes_read;
1290 ctxt->strm->next_in = BAD_CAST (ctxt->inrptr + bytes_read);
1292 z_ret = inflate(ctxt->strm, Z_NO_FLUSH);
1293 bytes_read += orig_avail_in - ctxt->strm->avail_in;
1298 ctxt->inrptr += bytes_read;
1299 return(len - ctxt->strm->avail_out);
1303 while (ctxt->inptr - ctxt->inrptr < len) {
1304 if (xmlNanoHTTPRecv(ctxt) <= 0) break;
1306 if (ctxt->inptr - ctxt->inrptr < len)
1307 len = ctxt->inptr - ctxt->inrptr;
1308 memcpy(dest, ctxt->inrptr, len);
1309 ctxt->inrptr += len;
1322 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr) ctx;
1326 xmlNanoHTTPFreeCtxt(ctxt);
1351 xmlNanoHTTPCtxtPtr ctxt;
1367 ctxt = xmlNanoHTTPNewCtxt(URL);
1368 if (ctxt == NULL)
1371 ctxt = xmlNanoHTTPNewCtxt(redirURL);
1372 if (ctxt == NULL)
1374 ctxt->location = xmlMemStrdup(redirURL);
1377 if ((ctxt->protocol == NULL) || (strcmp(ctxt->protocol, "http"))) {
1379 xmlNanoHTTPFreeCtxt(ctxt);
1383 if (ctxt->hostname == NULL) {
1386 xmlNanoHTTPFreeCtxt(ctxt);
1391 blen = strlen(ctxt->hostname) * 2 + 16;
1395 blen = strlen(ctxt->hostname);
1396 ret = xmlNanoHTTPConnectHost(ctxt->hostname, ctxt->port);
1399 xmlNanoHTTPFreeCtxt(ctxt);
1403 ctxt->fd = ret;
1415 if (ctxt->query != NULL)
1417 blen += strlen(ctxt->query) + 1;
1418 blen += strlen(method) + strlen(ctxt->path) + 24;
1423 if (ctxt->port != 80) {
1432 xmlNanoHTTPFreeCtxt( ctxt );
1440 if (ctxt->port != 80) {
1442 method, ctxt->hostname,
1443 ctxt->port, ctxt->path );
1447 ctxt->hostname, ctxt->path);
1450 p += snprintf( p, blen - (p - bp), "%s %s", method, ctxt->path);
1452 if (ctxt->query != NULL)
1453 p += snprintf( p, blen - (p - bp), "?%s", ctxt->query);
1455 if (ctxt->port == 80) {
1457 ctxt->hostname);
1460 ctxt->hostname, ctxt->port);
1485 ctxt->outptr = ctxt->out = bp;
1486 ctxt->state = XML_NANO_HTTP_WRITE;
1487 blen = strlen( ctxt->out );
1489 xmt_bytes = xmlNanoHTTPSend(ctxt, ctxt->out, blen );
1495 ctxt->hostname );
1497 xmlNanoHTTPSend(ctxt, ctxt->out, blen );
1502 xmt_bytes = xmlNanoHTTPSend( ctxt, input, ilen );
1509 ctxt->hostname );
1511 xmlNanoHTTPSend( ctxt, input, ilen );
1515 ctxt->state = XML_NANO_HTTP_READ;
1517 while ((p = xmlNanoHTTPReadLine(ctxt)) != NULL) {
1519 ctxt->content = ctxt->inrptr;
1523 xmlNanoHTTPScanAnswer(ctxt, p);
1531 if ((ctxt->location != NULL) && (ctxt->returnValue >= 300) &&
1532 (ctxt->returnValue < 400)) {
1535 "\nRedirect to: %s\n", ctxt->location);
1537 while ( xmlNanoHTTPRecv(ctxt) > 0 ) ;
1542 redirURL = xmlMemStrdup(ctxt->location);
1543 xmlNanoHTTPFreeCtxt(ctxt);
1546 xmlNanoHTTPFreeCtxt(ctxt);
1556 if (ctxt->contentType != NULL)
1557 *contentType = xmlMemStrdup(ctxt->contentType);
1572 if (ctxt->contentType != NULL)
1575 ctxt->returnValue, ctxt->contentType);
1579 ctxt->returnValue);
1582 return((void *) ctxt);
1624 void *ctxt = NULL;
1631 ctxt = xmlNanoHTTPOpen(URL, contentType);
1632 if (ctxt == NULL) return(-1);
1639 xmlNanoHTTPClose(ctxt);
1648 xmlNanoHTTPFetchContent( ctxt, &buf, &len );
1655 xmlNanoHTTPClose(ctxt);
1663 * @ctxt: the HTTP context
1672 xmlNanoHTTPSave(void *ctxt, const char *filename) {
1678 if ((ctxt == NULL) || (filename == NULL)) return(-1);
1685 xmlNanoHTTPClose(ctxt);
1690 xmlNanoHTTPFetchContent( ctxt, &buf, &len );
1697 xmlNanoHTTPClose(ctxt);
1713 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr) ctx;
1715 if (ctxt == NULL) return(-1);
1717 return(ctxt->returnValue);
1731 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr) ctx;
1733 if (ctxt == NULL) return(NULL);
1735 return(ctxt->authHeader);
1750 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr)ctx;
1752 return ( ( ctxt == NULL ) ? -1 : ctxt->ContentLength );
1765 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr)ctx;
1767 return ( ( ctxt == NULL ) ? NULL : ctxt->location );
1780 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr)ctx;
1782 return ( ( ctxt == NULL ) ? NULL : ctxt->encoding );
1795 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr)ctx;
1797 return ( ( ctxt == NULL ) ? NULL : ctxt->mimeType );
1814 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr)ctx;
1832 if ( ( ctxt == NULL ) || ( ctxt->content == NULL ) ) {
1838 rcvd_lgth = ctxt->inptr - ctxt->content;
1840 while ( (cur_lgth = xmlNanoHTTPRecv( ctxt )) > 0 ) {
1843 if ( (ctxt->ContentLength > 0) && (rcvd_lgth >= ctxt->ContentLength) )
1847 *ptr = ctxt->content;
1850 if ( ( ctxt->ContentLength > 0 ) && ( rcvd_lgth < ctxt->ContentLength ) )