Lines Matching refs:ctxt

269  * @ctxt:  an HTTP context
277 xmlNanoHTTPScanURL(xmlNanoHTTPCtxtPtr ctxt, const char *URL) {
282 if (ctxt->protocol != NULL) {
283 xmlFree(ctxt->protocol);
284 ctxt->protocol = NULL;
286 if (ctxt->hostname != NULL) {
287 xmlFree(ctxt->hostname);
288 ctxt->hostname = NULL;
290 if (ctxt->path != NULL) {
291 xmlFree(ctxt->path);
292 ctxt->path = NULL;
294 if (ctxt->query != NULL) {
295 xmlFree(ctxt->query);
296 ctxt->query = NULL;
309 ctxt->protocol = xmlMemStrdup(uri->scheme);
310 ctxt->hostname = xmlMemStrdup(uri->server);
312 ctxt->path = xmlMemStrdup(uri->path);
314 ctxt->path = xmlMemStrdup("/");
316 ctxt->query = xmlMemStrdup(uri->query);
318 ctxt->port = uri->port;
401 * @ctxt: an HTTP context
407 xmlNanoHTTPFreeCtxt(xmlNanoHTTPCtxtPtr ctxt) {
408 if (ctxt == NULL) return;
409 if (ctxt->hostname != NULL) xmlFree(ctxt->hostname);
410 if (ctxt->protocol != NULL) xmlFree(ctxt->protocol);
411 if (ctxt->path != NULL) xmlFree(ctxt->path);
412 if (ctxt->query != NULL) xmlFree(ctxt->query);
413 if (ctxt->out != NULL) xmlFree(ctxt->out);
414 if (ctxt->in != NULL) xmlFree(ctxt->in);
415 if (ctxt->contentType != NULL) xmlFree(ctxt->contentType);
416 if (ctxt->encoding != NULL) xmlFree(ctxt->encoding);
417 if (ctxt->mimeType != NULL) xmlFree(ctxt->mimeType);
418 if (ctxt->location != NULL) xmlFree(ctxt->location);
419 if (ctxt->authHeader != NULL) xmlFree(ctxt->authHeader);
421 if (ctxt->strm != NULL) {
422 inflateEnd(ctxt->strm);
423 xmlFree(ctxt->strm);
427 ctxt->state = XML_NANO_HTTP_NONE;
428 if (ctxt->fd >= 0) closesocket(ctxt->fd);
429 ctxt->fd = -1;
430 xmlFree(ctxt);
435 * @ctxt: an HTTP context
442 xmlNanoHTTPSend(xmlNanoHTTPCtxtPtr ctxt, const char * xmt_ptr, int outlen) {
446 if ( (ctxt->state & XML_NANO_HTTP_WRITE) && (xmt_ptr != NULL ) ) {
448 int nsent = send(ctxt->fd, xmt_ptr + total_sent,
480 FD_SET( ctxt->fd, &wfd );
484 (void)select( ctxt->fd + 1, NULL, &wfd, NULL, &tv );
494 * @ctxt: an HTTP context
503 xmlNanoHTTPRecv(xmlNanoHTTPCtxtPtr ctxt) {
508 while (ctxt->state & XML_NANO_HTTP_READ) {
509 if (ctxt->in == NULL) {
510 ctxt->in = (char *) xmlMallocAtomic(65000 * sizeof(char));
511 if (ctxt->in == NULL) {
513 ctxt->last = -1;
516 ctxt->inlen = 65000;
517 ctxt->inptr = ctxt->content = ctxt->inrptr = ctxt->in;
519 if (ctxt->inrptr > ctxt->in + XML_NANO_HTTP_CHUNK) {
520 int delta = ctxt->inrptr - ctxt->in;
521 int len = ctxt->inptr - ctxt->inrptr;
523 memmove(ctxt->in, ctxt->inrptr, len);
524 ctxt->inrptr -= delta;
525 ctxt->content -= delta;
526 ctxt->inptr -= delta;
528 if ((ctxt->in + ctxt->inlen) < (ctxt->inptr + XML_NANO_HTTP_CHUNK)) {
529 int d_inptr = ctxt->inptr - ctxt->in;
530 int d_content = ctxt->content - ctxt->in;
531 int d_inrptr = ctxt->inrptr - ctxt->in;
532 char * tmp_ptr = ctxt->in;
534 ctxt->inlen *= 2;
535 ctxt->in = (char *) xmlRealloc(tmp_ptr, ctxt->inlen);
536 if (ctxt->in == NULL) {
539 ctxt->last = -1;
542 ctxt->inptr = ctxt->in + d_inptr;
543 ctxt->content = ctxt->in + d_content;
544 ctxt->inrptr = ctxt->in + d_inrptr;
546 ctxt->last = recv(ctxt->fd, ctxt->inptr, XML_NANO_HTTP_CHUNK, 0);
547 if (ctxt->last > 0) {
548 ctxt->inptr += ctxt->last;
549 return(ctxt->last);
551 if (ctxt->last == 0) {
554 if (ctxt->last == -1) {
580 FD_SET(ctxt->fd, &rfd);
585 if ( (select(ctxt->fd+1, &rfd, NULL, NULL, &tv)<1)
597 * @ctxt: an HTTP context
607 xmlNanoHTTPReadLine(xmlNanoHTTPCtxtPtr ctxt) {
613 if (ctxt->inrptr == ctxt->inptr) {
614 if ( (rc = xmlNanoHTTPRecv(ctxt)) == 0) {
625 *bp = *ctxt->inrptr++;
640 * @ctxt: an HTTP context
653 xmlNanoHTTPScanAnswer(xmlNanoHTTPCtxtPtr ctxt, const char *line) {
688 ctxt->returnValue = ret;
693 if (ctxt->contentType != NULL)
694 xmlFree(ctxt->contentType);
695 ctxt->contentType = xmlMemStrdup(cur);
701 if (ctxt->mimeType != NULL)
702 xmlFree(ctxt->mimeType);
703 ctxt->mimeType = (char *) xmlStrndup(mime, last - mime);
704 charset = xmlStrstr(BAD_CAST ctxt->contentType, BAD_CAST "charset=");
711 if (ctxt->encoding != NULL)
712 xmlFree(ctxt->encoding);
713 ctxt->encoding = (char *) xmlStrndup(charset, last - charset);
718 if (ctxt->contentType != NULL) return;
720 ctxt->contentType = xmlMemStrdup(cur);
726 if (ctxt->mimeType != NULL)
727 xmlFree(ctxt->mimeType);
728 ctxt->mimeType = (char *) xmlStrndup(mime, last - mime);
729 charset = xmlStrstr(BAD_CAST ctxt->contentType, BAD_CAST "charset=");
736 if (ctxt->encoding != NULL)
737 xmlFree(ctxt->encoding);
738 ctxt->encoding = (char *) xmlStrndup(charset, last - charset);
743 if (ctxt->location != NULL)
744 xmlFree(ctxt->location);
748 xmlStrcat(tmp_http, (const xmlChar *) ctxt->hostname);
749 ctxt->location =
752 ctxt->location = xmlMemStrdup(cur);
757 if (ctxt->authHeader != NULL)
758 xmlFree(ctxt->authHeader);
759 ctxt->authHeader = xmlMemStrdup(cur);
763 if (ctxt->authHeader != NULL)
764 xmlFree(ctxt->authHeader);
765 ctxt->authHeader = xmlMemStrdup(cur);
771 ctxt->usesGzip = 1;
773 ctxt->strm = xmlMalloc(sizeof(z_stream));
775 if (ctxt->strm != NULL) {
776 ctxt->strm->zalloc = Z_NULL;
777 ctxt->strm->zfree = Z_NULL;
778 ctxt->strm->opaque = Z_NULL;
779 ctxt->strm->avail_in = 0;
780 ctxt->strm->next_in = Z_NULL;
782 inflateInit2( ctxt->strm, 31 );
788 ctxt->ContentLength = strtol( cur, NULL, 10 );
1189 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr) ctx;
1201 if (ctxt->usesGzip == 1) {
1202 if (ctxt->strm == NULL) return(0);
1204 ctxt->strm->next_out = dest;
1205 ctxt->strm->avail_out = len;
1206 ctxt->strm->avail_in = ctxt->inptr - ctxt->inrptr;
1208 while (ctxt->strm->avail_out > 0 &&
1209 (ctxt->strm->avail_in > 0 || xmlNanoHTTPRecv(ctxt) > 0)) {
1210 orig_avail_in = ctxt->strm->avail_in =
1211 ctxt->inptr - ctxt->inrptr - bytes_read;
1212 ctxt->strm->next_in = BAD_CAST (ctxt->inrptr + bytes_read);
1214 z_ret = inflate(ctxt->strm, Z_NO_FLUSH);
1215 bytes_read += orig_avail_in - ctxt->strm->avail_in;
1220 ctxt->inrptr += bytes_read;
1221 return(len - ctxt->strm->avail_out);
1225 while (ctxt->inptr - ctxt->inrptr < len) {
1226 if (xmlNanoHTTPRecv(ctxt) <= 0) break;
1228 if (ctxt->inptr - ctxt->inrptr < len)
1229 len = ctxt->inptr - ctxt->inrptr;
1230 memcpy(dest, ctxt->inrptr, len);
1231 ctxt->inrptr += len;
1244 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr) ctx;
1248 xmlNanoHTTPFreeCtxt(ctxt);
1273 xmlNanoHTTPCtxtPtr ctxt;
1289 ctxt = xmlNanoHTTPNewCtxt(URL);
1291 ctxt = xmlNanoHTTPNewCtxt(redirURL);
1292 ctxt->location = xmlMemStrdup(redirURL);
1295 if ( ctxt == NULL ) {
1299 if ((ctxt->protocol == NULL) || (strcmp(ctxt->protocol, "http"))) {
1301 xmlNanoHTTPFreeCtxt(ctxt);
1305 if (ctxt->hostname == NULL) {
1308 xmlNanoHTTPFreeCtxt(ctxt);
1313 blen = strlen(ctxt->hostname) * 2 + 16;
1317 blen = strlen(ctxt->hostname);
1318 ret = xmlNanoHTTPConnectHost(ctxt->hostname, ctxt->port);
1321 xmlNanoHTTPFreeCtxt(ctxt);
1325 ctxt->fd = ret;
1337 if (ctxt->query != NULL)
1339 blen += strlen(ctxt->query) + 1;
1340 blen += strlen(method) + strlen(ctxt->path) + 24;
1345 if (ctxt->port != 80) {
1354 xmlNanoHTTPFreeCtxt( ctxt );
1362 if (ctxt->port != 80) {
1364 method, ctxt->hostname,
1365 ctxt->port, ctxt->path );
1369 ctxt->hostname, ctxt->path);
1372 p += snprintf( p, blen - (p - bp), "%s %s", method, ctxt->path);
1374 if (ctxt->query != NULL)
1375 p += snprintf( p, blen - (p - bp), "?%s", ctxt->query);
1377 if (ctxt->port == 80) {
1379 ctxt->hostname);
1382 ctxt->hostname, ctxt->port);
1407 ctxt->outptr = ctxt->out = bp;
1408 ctxt->state = XML_NANO_HTTP_WRITE;
1409 blen = strlen( ctxt->out );
1411 xmt_bytes = xmlNanoHTTPSend(ctxt, ctxt->out, blen );
1417 ctxt->hostname );
1419 xmlNanoHTTPSend(ctxt, ctxt->out, blen );
1424 xmt_bytes = xmlNanoHTTPSend( ctxt, input, ilen );
1431 ctxt->hostname );
1433 xmlNanoHTTPSend( ctxt, input, ilen );
1437 ctxt->state = XML_NANO_HTTP_READ;
1440 while ((p = xmlNanoHTTPReadLine(ctxt)) != NULL) {
1443 ctxt->content = ctxt->inrptr;
1447 xmlNanoHTTPScanAnswer(ctxt, p);
1455 if ((ctxt->location != NULL) && (ctxt->returnValue >= 300) &&
1456 (ctxt->returnValue < 400)) {
1459 "\nRedirect to: %s\n", ctxt->location);
1461 while ( xmlNanoHTTPRecv(ctxt) > 0 ) ;
1466 redirURL = xmlMemStrdup(ctxt->location);
1467 xmlNanoHTTPFreeCtxt(ctxt);
1470 xmlNanoHTTPFreeCtxt(ctxt);
1480 if (ctxt->contentType != NULL)
1481 *contentType = xmlMemStrdup(ctxt->contentType);
1496 if (ctxt->contentType != NULL)
1499 ctxt->returnValue, ctxt->contentType);
1503 ctxt->returnValue);
1506 return((void *) ctxt);
1548 void *ctxt = NULL;
1554 ctxt = xmlNanoHTTPOpen(URL, contentType);
1555 if (ctxt == NULL) return(-1);
1562 xmlNanoHTTPClose(ctxt);
1571 xmlNanoHTTPFetchContent( ctxt, &buf, &len );
1576 xmlNanoHTTPClose(ctxt);
1584 * @ctxt: the HTTP context
1593 xmlNanoHTTPSave(void *ctxt, const char *filename) {
1598 if ((ctxt == NULL) || (filename == NULL)) return(-1);
1605 xmlNanoHTTPClose(ctxt);
1610 xmlNanoHTTPFetchContent( ctxt, &buf, &len );
1615 xmlNanoHTTPClose(ctxt);
1631 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr) ctx;
1633 if (ctxt == NULL) return(-1);
1635 return(ctxt->returnValue);
1649 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr) ctx;
1651 if (ctxt == NULL) return(NULL);
1653 return(ctxt->authHeader);
1668 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr)ctx;
1670 return ( ( ctxt == NULL ) ? -1 : ctxt->ContentLength );
1683 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr)ctx;
1685 return ( ( ctxt == NULL ) ? NULL : ctxt->location );
1698 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr)ctx;
1700 return ( ( ctxt == NULL ) ? NULL : ctxt->encoding );
1713 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr)ctx;
1715 return ( ( ctxt == NULL ) ? NULL : ctxt->mimeType );
1732 xmlNanoHTTPCtxtPtr ctxt = (xmlNanoHTTPCtxtPtr)ctx;
1750 if ( ( ctxt == NULL ) || ( ctxt->content == NULL ) ) {
1756 rcvd_lgth = ctxt->inptr - ctxt->content;
1758 while ( (cur_lgth = xmlNanoHTTPRecv( ctxt )) > 0 ) {
1761 if ( (ctxt->ContentLength > 0) && (rcvd_lgth >= ctxt->ContentLength) )
1765 *ptr = ctxt->content;
1768 if ( ( ctxt->ContentLength > 0 ) && ( rcvd_lgth < ctxt->ContentLength ) )