Lines 747-810
util_curl_new(void)
Link Here
|
747 |
return self; |
747 |
return self; |
748 |
} |
748 |
} |
749 |
|
749 |
|
750 |
|
750 |
/* Set default values to curl handle options, so curl cooperates with |
751 |
/* constructor - this is a module-level function returning a new instance */ |
751 |
python curl object. */ |
752 |
static CurlObject * |
752 |
static int |
753 |
do_curl_new(PyObject *dummy) |
753 |
util_curl_init_handle(CurlObject *self) |
754 |
{ |
754 |
{ |
755 |
CurlObject *self = NULL; |
|
|
756 |
int res; |
755 |
int res; |
757 |
char *s = NULL; |
756 |
char *s = NULL; |
758 |
|
757 |
|
759 |
UNUSED(dummy); |
|
|
760 |
|
761 |
/* Allocate python curl object */ |
762 |
self = util_curl_new(); |
763 |
if (self == NULL) |
764 |
return NULL; |
765 |
|
766 |
/* Initialize curl handle */ |
767 |
self->handle = curl_easy_init(); |
768 |
if (self->handle == NULL) |
769 |
goto error; |
770 |
|
771 |
/* Set curl error buffer and zero it */ |
758 |
/* Set curl error buffer and zero it */ |
772 |
res = curl_easy_setopt(self->handle, CURLOPT_ERRORBUFFER, self->error); |
759 |
res = curl_easy_setopt(self->handle, CURLOPT_ERRORBUFFER, self->error); |
773 |
if (res != CURLE_OK) |
760 |
if (res != CURLE_OK) |
774 |
goto error; |
761 |
return -1; |
775 |
memset(self->error, 0, sizeof(self->error)); |
762 |
memset(self->error, 0, sizeof(self->error)); |
776 |
|
763 |
|
777 |
/* Set backreference */ |
764 |
/* Set backreference */ |
778 |
res = curl_easy_setopt(self->handle, CURLOPT_PRIVATE, (char *) self); |
765 |
res = curl_easy_setopt(self->handle, CURLOPT_PRIVATE, (char*) self); |
779 |
if (res != CURLE_OK) |
766 |
if (res != CURLE_OK) |
780 |
goto error; |
767 |
return -1; |
781 |
|
768 |
|
782 |
/* Enable NOPROGRESS by default, i.e. no progress output */ |
769 |
/* Enable NOPROGRESS by default, i.e. no progress output */ |
783 |
res = curl_easy_setopt(self->handle, CURLOPT_NOPROGRESS, (long)1); |
770 |
res = curl_easy_setopt(self->handle, CURLOPT_NOPROGRESS, (long)1); |
784 |
if (res != CURLE_OK) |
771 |
if (res != CURLE_OK) |
785 |
goto error; |
772 |
return -1; |
786 |
|
773 |
|
787 |
/* Disable VERBOSE by default, i.e. no verbose output */ |
774 |
/* Disable VERBOSE by default, i.e. no verbose output */ |
788 |
res = curl_easy_setopt(self->handle, CURLOPT_VERBOSE, (long)0); |
775 |
res = curl_easy_setopt(self->handle, CURLOPT_VERBOSE, (long)0); |
789 |
if (res != CURLE_OK) |
776 |
if (res != CURLE_OK) |
790 |
goto error; |
777 |
return -1; |
791 |
|
778 |
|
792 |
/* Set FTP_ACCOUNT to NULL by default */ |
779 |
/* Set FTP_ACCOUNT to NULL by default */ |
793 |
res = curl_easy_setopt(self->handle, CURLOPT_FTP_ACCOUNT, NULL); |
780 |
res = curl_easy_setopt(self->handle, CURLOPT_FTP_ACCOUNT, NULL); |
794 |
if (res != CURLE_OK) |
781 |
if (res != CURLE_OK) |
795 |
goto error; |
782 |
return -1; |
796 |
|
783 |
|
797 |
/* Set default USERAGENT */ |
784 |
/* Set default USERAGENT */ |
798 |
s = (char *) malloc(7 + strlen(LIBCURL_VERSION) + 1); |
785 |
s = (char *) malloc(7 + strlen(LIBCURL_VERSION) + 1); |
799 |
if (s == NULL) |
786 |
if (s == NULL) |
800 |
goto error; |
787 |
return -1; |
801 |
strcpy(s, "PycURL/"); strcpy(s+7, LIBCURL_VERSION); |
788 |
strcpy(s, "PycURL/"); strcpy(s+7, LIBCURL_VERSION); |
802 |
res = curl_easy_setopt(self->handle, CURLOPT_USERAGENT, (char *) s); |
789 |
res = curl_easy_setopt(self->handle, CURLOPT_USERAGENT, (char *) s); |
803 |
if (res != CURLE_OK) { |
790 |
if (res != CURLE_OK) { |
804 |
free(s); |
791 |
free(s); |
805 |
goto error; |
792 |
return -1; |
806 |
} |
793 |
} |
807 |
self->options[ OPT_INDEX(CURLOPT_USERAGENT) ] = s; s = NULL; |
794 |
self->options[ OPT_INDEX(CURLOPT_USERAGENT) ] = s; |
|
|
795 |
|
796 |
return 0; |
797 |
} |
798 |
|
799 |
|
800 |
/* constructor - this is a module-level function returning a new instance */ |
801 |
static CurlObject * |
802 |
do_curl_new(PyObject *dummy) |
803 |
{ |
804 |
CurlObject *self = NULL; |
805 |
|
806 |
UNUSED(dummy); |
807 |
|
808 |
/* Allocate python curl object */ |
809 |
self = util_curl_new(); |
810 |
if (self == NULL) |
811 |
return NULL; |
812 |
|
813 |
/* Initialize curl handle */ |
814 |
self->handle = curl_easy_init(); |
815 |
if (self->handle == NULL) |
816 |
goto error; |
817 |
|
818 |
/* Configure handle to work with python curl object, |
819 |
and set better initial state for pycurl. */ |
820 |
if (util_curl_init_handle(self)) |
821 |
goto error; |
808 |
|
822 |
|
809 |
/* Success - return new object */ |
823 |
/* Success - return new object */ |
810 |
return self; |
824 |
return self; |
Lines 1452-1457
do_curl_reset(CurlObject *self)
Link Here
|
1452 |
} |
1466 |
} |
1453 |
} |
1467 |
} |
1454 |
|
1468 |
|
|
|
1469 |
/* Reconfigure handle to work with python curl, as the settings |
1470 |
* are lost after curl_easy_reset(). |
1471 |
* |
1472 |
* We cannot do anything useful if this fails, so don't check the |
1473 |
* return value. */ |
1474 |
util_curl_init_handle(self); |
1475 |
|
1455 |
return Py_None; |
1476 |
return Py_None; |
1456 |
} |
1477 |
} |
1457 |
|
1478 |
|