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, 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 );
1266 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr) ctx;
1278 if (ctxt->usesGzip == 1) {
1279 if (ctxt->strm == NULL) return(0);
1281 ctxt->strm->next_out = dest;
1282 ctxt->strm->avail_out = len;
1283 ctxt->strm->avail_in = ctxt->inptr - ctxt->inrptr;
1285 while (ctxt->strm->avail_out > 0 &&
1286 (ctxt->strm->avail_in > 0 || xmlNanoHTTPRecv(ctxt) > 0)) {
1287 orig_avail_in = ctxt->strm->avail_in =
1288 ctxt->inptr - ctxt->inrptr - bytes_read;
1289 ctxt->strm->next_in = BAD_CAST (ctxt->inrptr + bytes_read);
1291 z_ret = inflate(ctxt->strm, Z_NO_FLUSH);
1292 bytes_read += orig_avail_in - ctxt->strm->avail_in;
1297 ctxt->inrptr += bytes_read;
1298 return(len - ctxt->strm->avail_out);
1302 while (ctxt->inptr - ctxt->inrptr < len) {
1303 if (xmlNanoHTTPRecv(ctxt) <= 0) break;
1305 if (ctxt->inptr - ctxt->inrptr < len)
1306 len = ctxt->inptr - ctxt->inrptr;
1307 memcpy(dest, ctxt->inrptr, len);
1308 ctxt->inrptr += len;
1321 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr) ctx;
1325 xmlNanoHTTPFreeCtxt(ctxt);
1350 xmlNanoHTTPCtxtPtr ctxt;
1366 ctxt = xmlNanoHTTPNewCtxt(URL);
1368 ctxt = xmlNanoHTTPNewCtxt(redirURL);
1369 ctxt->location = xmlMemStrdup(redirURL);
1372 if ( ctxt == NULL ) {
1376 if ((ctxt->protocol == NULL) || (strcmp(ctxt->protocol, "http"))) {
1378 xmlNanoHTTPFreeCtxt(ctxt);
1382 if (ctxt->hostname == NULL) {
1385 xmlNanoHTTPFreeCtxt(ctxt);
1390 blen = strlen(ctxt->hostname) * 2 + 16;
1394 blen = strlen(ctxt->hostname);
1395 ret = xmlNanoHTTPConnectHost(ctxt->hostname, ctxt->port);
1398 xmlNanoHTTPFreeCtxt(ctxt);
1402 ctxt->fd = ret;
1414 if (ctxt->query != NULL)
1416 blen += strlen(ctxt->query) + 1;
1417 blen += strlen(method) + strlen(ctxt->path) + 24;
1422 if (ctxt->port != 80) {
1431 xmlNanoHTTPFreeCtxt( ctxt );
1439 if (ctxt->port != 80) {
1441 method, ctxt->hostname,
1442 ctxt->port, ctxt->path );
1446 ctxt->hostname, ctxt->path);
1449 p += snprintf( p, blen - (p - bp), "%s %s", method, ctxt->path);
1451 if (ctxt->query != NULL)
1452 p += snprintf( p, blen - (p - bp), "?%s", ctxt->query);
1454 if (ctxt->port == 80) {
1456 ctxt->hostname);
1459 ctxt->hostname, ctxt->port);
1484 ctxt->outptr = ctxt->out = bp;
1485 ctxt->state = XML_NANO_HTTP_WRITE;
1486 blen = strlen( ctxt->out );
1488 xmt_bytes = xmlNanoHTTPSend(ctxt, ctxt->out, blen );
1494 ctxt->hostname );
1496 xmlNanoHTTPSend(ctxt, ctxt->out, blen );
1501 xmt_bytes = xmlNanoHTTPSend( ctxt, input, ilen );
1508 ctxt->hostname );
1510 xmlNanoHTTPSend( ctxt, input, ilen );
1514 ctxt->state = XML_NANO_HTTP_READ;
1516 while ((p = xmlNanoHTTPReadLine(ctxt)) != NULL) {
1518 ctxt->content = ctxt->inrptr;
1522 xmlNanoHTTPScanAnswer(ctxt, p);
1530 if ((ctxt->location != NULL) && (ctxt->returnValue >= 300) &&
1531 (ctxt->returnValue < 400)) {
1534 "\nRedirect to: %s\n", ctxt->location);
1536 while ( xmlNanoHTTPRecv(ctxt) > 0 ) ;
1541 redirURL = xmlMemStrdup(ctxt->location);
1542 xmlNanoHTTPFreeCtxt(ctxt);
1545 xmlNanoHTTPFreeCtxt(ctxt);
1555 if (ctxt->contentType != NULL)
1556 *contentType = xmlMemStrdup(ctxt->contentType);
1571 if (ctxt->contentType != NULL)
1574 ctxt->returnValue, ctxt->contentType);
1578 ctxt->returnValue);
1581 return((void *) ctxt);
1623 void *ctxt = NULL;
1630 ctxt = xmlNanoHTTPOpen(URL, contentType);
1631 if (ctxt == NULL) return(-1);
1638 xmlNanoHTTPClose(ctxt);
1647 xmlNanoHTTPFetchContent( ctxt, &buf, &len );
1654 xmlNanoHTTPClose(ctxt);
1662 * @ctxt: the HTTP context
1671 xmlNanoHTTPSave(void *ctxt, const char *filename) {
1677 if ((ctxt == NULL) || (filename == NULL)) return(-1);
1684 xmlNanoHTTPClose(ctxt);
1689 xmlNanoHTTPFetchContent( ctxt, &buf, &len );
1696 xmlNanoHTTPClose(ctxt);
1712 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr) ctx;
1714 if (ctxt == NULL) return(-1);
1716 return(ctxt->returnValue);
1730 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr) ctx;
1732 if (ctxt == NULL) return(NULL);
1734 return(ctxt->authHeader);
1749 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr)ctx;
1751 return ( ( ctxt == NULL ) ? -1 : ctxt->ContentLength );
1764 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr)ctx;
1766 return ( ( ctxt == NULL ) ? NULL : ctxt->location );
1779 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr)ctx;
1781 return ( ( ctxt == NULL ) ? NULL : ctxt->encoding );
1794 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr)ctx;
1796 return ( ( ctxt == NULL ) ? NULL : ctxt->mimeType );
1813 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr)ctx;
1831 if ( ( ctxt == NULL ) || ( ctxt->content == NULL ) ) {
1837 rcvd_lgth = ctxt->inptr - ctxt->content;
1839 while ( (cur_lgth = xmlNanoHTTPRecv( ctxt )) > 0 ) {
1842 if ( (ctxt->ContentLength > 0) && (rcvd_lgth >= ctxt->ContentLength) )
1846 *ptr = ctxt->content;
1849 if ( ( ctxt->ContentLength > 0 ) && ( rcvd_lgth < ctxt->ContentLength ) )