interface.c 115 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 7 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2018 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Author: Sterling Hughes <sterling@php.net> |
  16. +----------------------------------------------------------------------+
  17. */
  18. #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
  19. #ifdef HAVE_CONFIG_H
  20. #include "config.h"
  21. #endif
  22. #include "php.h"
  23. #if HAVE_CURL
  24. #include <stdio.h>
  25. #include <string.h>
  26. #ifdef PHP_WIN32
  27. #include <winsock2.h>
  28. #include <sys/types.h>
  29. #endif
  30. #include <curl/curl.h>
  31. #include <curl/easy.h>
  32. /* As of curl 7.11.1 this is no longer defined inside curl.h */
  33. #ifndef HttpPost
  34. #define HttpPost curl_httppost
  35. #endif
  36. /* {{{ cruft for thread safe SSL crypto locks */
  37. #if defined(ZTS) && defined(HAVE_CURL_SSL)
  38. # ifdef PHP_WIN32
  39. # define PHP_CURL_NEED_OPENSSL_TSL
  40. # include <openssl/crypto.h>
  41. # else /* !PHP_WIN32 */
  42. # if defined(HAVE_CURL_OPENSSL)
  43. # if defined(HAVE_OPENSSL_CRYPTO_H)
  44. # define PHP_CURL_NEED_OPENSSL_TSL
  45. # include <openssl/crypto.h>
  46. # else
  47. # warning \
  48. "libcurl was compiled with OpenSSL support, but configure could not find " \
  49. "openssl/crypto.h; thus no SSL crypto locking callbacks will be set, which may " \
  50. "cause random crashes on SSL requests"
  51. # endif
  52. # elif defined(HAVE_CURL_GNUTLS)
  53. # if defined(HAVE_GCRYPT_H)
  54. # define PHP_CURL_NEED_GNUTLS_TSL
  55. # include <gcrypt.h>
  56. # else
  57. # warning \
  58. "libcurl was compiled with GnuTLS support, but configure could not find " \
  59. "gcrypt.h; thus no SSL crypto locking callbacks will be set, which may " \
  60. "cause random crashes on SSL requests"
  61. # endif
  62. # else
  63. # warning \
  64. "libcurl was compiled with SSL support, but configure could not determine which" \
  65. "library was used; thus no SSL crypto locking callbacks will be set, which may " \
  66. "cause random crashes on SSL requests"
  67. # endif /* HAVE_CURL_OPENSSL || HAVE_CURL_GNUTLS */
  68. # endif /* PHP_WIN32 */
  69. #endif /* ZTS && HAVE_CURL_SSL */
  70. /* }}} */
  71. #define SMART_STR_PREALLOC 4096
  72. #include "zend_smart_str.h"
  73. #include "ext/standard/info.h"
  74. #include "ext/standard/file.h"
  75. #include "ext/standard/url.h"
  76. #include "php_curl.h"
  77. int le_curl;
  78. int le_curl_multi_handle;
  79. int le_curl_share_handle;
  80. #ifdef PHP_CURL_NEED_OPENSSL_TSL /* {{{ */
  81. static MUTEX_T *php_curl_openssl_tsl = NULL;
  82. static void php_curl_ssl_lock(int mode, int n, const char * file, int line)
  83. {
  84. if (mode & CRYPTO_LOCK) {
  85. tsrm_mutex_lock(php_curl_openssl_tsl[n]);
  86. } else {
  87. tsrm_mutex_unlock(php_curl_openssl_tsl[n]);
  88. }
  89. }
  90. static unsigned long php_curl_ssl_id(void)
  91. {
  92. return (unsigned long) tsrm_thread_id();
  93. }
  94. #endif
  95. /* }}} */
  96. #ifdef PHP_CURL_NEED_GNUTLS_TSL /* {{{ */
  97. static int php_curl_ssl_mutex_create(void **m)
  98. {
  99. if (*((MUTEX_T *) m) = tsrm_mutex_alloc()) {
  100. return SUCCESS;
  101. } else {
  102. return FAILURE;
  103. }
  104. }
  105. static int php_curl_ssl_mutex_destroy(void **m)
  106. {
  107. tsrm_mutex_free(*((MUTEX_T *) m));
  108. return SUCCESS;
  109. }
  110. static int php_curl_ssl_mutex_lock(void **m)
  111. {
  112. return tsrm_mutex_lock(*((MUTEX_T *) m));
  113. }
  114. static int php_curl_ssl_mutex_unlock(void **m)
  115. {
  116. return tsrm_mutex_unlock(*((MUTEX_T *) m));
  117. }
  118. static struct gcry_thread_cbs php_curl_gnutls_tsl = {
  119. GCRY_THREAD_OPTION_USER,
  120. NULL,
  121. php_curl_ssl_mutex_create,
  122. php_curl_ssl_mutex_destroy,
  123. php_curl_ssl_mutex_lock,
  124. php_curl_ssl_mutex_unlock
  125. };
  126. #endif
  127. /* }}} */
  128. static void _php_curl_close_ex(php_curl *ch);
  129. static void _php_curl_close(zend_resource *rsrc);
  130. #define CAAL(s, v) add_assoc_long_ex(return_value, s, sizeof(s) - 1, (zend_long) v);
  131. #define CAAD(s, v) add_assoc_double_ex(return_value, s, sizeof(s) - 1, (double) v);
  132. #define CAAS(s, v) add_assoc_string_ex(return_value, s, sizeof(s) - 1, (char *) (v ? v : ""));
  133. #define CAASTR(s, v) add_assoc_str_ex(return_value, s, sizeof(s) - 1, \
  134. v ? zend_string_copy(v) : ZSTR_EMPTY_ALLOC());
  135. #define CAAZ(s, v) add_assoc_zval_ex(return_value, s, sizeof(s) -1 , (zval *) v);
  136. #if defined(PHP_WIN32) || defined(__GNUC__)
  137. # define php_curl_ret(__ret) RETVAL_FALSE; return __ret;
  138. #else
  139. # define php_curl_ret(__ret) RETVAL_FALSE; return;
  140. #endif
  141. static int php_curl_option_str(php_curl *ch, zend_long option, const char *str, const size_t len, zend_bool make_copy)
  142. {
  143. CURLcode error = CURLE_OK;
  144. if (strlen(str) != len) {
  145. php_error_docref(NULL, E_WARNING, "Curl option contains invalid characters (\\0)");
  146. return FAILURE;
  147. }
  148. #if LIBCURL_VERSION_NUM >= 0x071100
  149. if (make_copy) {
  150. #endif
  151. char *copystr;
  152. /* Strings passed to libcurl as 'char *' arguments, are copied by the library since 7.17.0 */
  153. copystr = estrndup(str, len);
  154. error = curl_easy_setopt(ch->cp, option, copystr);
  155. zend_llist_add_element(&ch->to_free->str, &copystr);
  156. #if LIBCURL_VERSION_NUM >= 0x071100
  157. } else {
  158. error = curl_easy_setopt(ch->cp, option, str);
  159. }
  160. #endif
  161. SAVE_CURL_ERROR(ch, error)
  162. return error == CURLE_OK ? SUCCESS : FAILURE;
  163. }
  164. static int php_curl_option_url(php_curl *ch, const char *url, const size_t len) /* {{{ */
  165. {
  166. /* Disable file:// if open_basedir are used */
  167. if (PG(open_basedir) && *PG(open_basedir)) {
  168. #if LIBCURL_VERSION_NUM >= 0x071304
  169. curl_easy_setopt(ch->cp, CURLOPT_PROTOCOLS, CURLPROTO_ALL & ~CURLPROTO_FILE);
  170. #else
  171. php_url *uri;
  172. if (!(uri = php_url_parse_ex(url, len))) {
  173. php_error_docref(NULL, E_WARNING, "Invalid URL '%s'", url);
  174. return FAILURE;
  175. }
  176. if (uri->scheme && zend_string_equals_literal_ci(uri->scheme, "file")) {
  177. php_error_docref(NULL, E_WARNING, "Protocol 'file' disabled in cURL");
  178. php_url_free(uri);
  179. return FAILURE;
  180. }
  181. php_url_free(uri);
  182. #endif
  183. }
  184. #if LIBCURL_VERSION_NUM > 0x073800 && defined(PHP_WIN32)
  185. if (len > sizeof("file://") - 1 && '/' != url[sizeof("file://") - 1] && !strncmp("file://", url, sizeof("file://") - 1) && len < MAXPATHLEN - 2) {
  186. char _tmp[MAXPATHLEN] = {0};
  187. memmove(_tmp, "file:///", sizeof("file:///") - 1);
  188. memmove(_tmp + sizeof("file:///") - 1, url + sizeof("file://") - 1, len - sizeof("file://") + 1);
  189. return php_curl_option_str(ch, CURLOPT_URL, _tmp, len + 1, 0);
  190. }
  191. #endif
  192. return php_curl_option_str(ch, CURLOPT_URL, url, len, 0);
  193. }
  194. /* }}} */
  195. void _php_curl_verify_handlers(php_curl *ch, int reporterror) /* {{{ */
  196. {
  197. php_stream *stream;
  198. ZEND_ASSERT(ch && ch->handlers);
  199. if (!Z_ISUNDEF(ch->handlers->std_err)) {
  200. stream = (php_stream *)zend_fetch_resource2_ex(&ch->handlers->std_err, NULL, php_file_le_stream(), php_file_le_pstream());
  201. if (stream == NULL) {
  202. if (reporterror) {
  203. php_error_docref(NULL, E_WARNING, "CURLOPT_STDERR resource has gone away, resetting to stderr");
  204. }
  205. zval_ptr_dtor(&ch->handlers->std_err);
  206. ZVAL_UNDEF(&ch->handlers->std_err);
  207. curl_easy_setopt(ch->cp, CURLOPT_STDERR, stderr);
  208. }
  209. }
  210. if (ch->handlers->read && !Z_ISUNDEF(ch->handlers->read->stream)) {
  211. stream = (php_stream *)zend_fetch_resource2_ex(&ch->handlers->read->stream, NULL, php_file_le_stream(), php_file_le_pstream());
  212. if (stream == NULL) {
  213. if (reporterror) {
  214. php_error_docref(NULL, E_WARNING, "CURLOPT_INFILE resource has gone away, resetting to default");
  215. }
  216. zval_ptr_dtor(&ch->handlers->read->stream);
  217. ZVAL_UNDEF(&ch->handlers->read->stream);
  218. ch->handlers->read->res = NULL;
  219. ch->handlers->read->fp = 0;
  220. curl_easy_setopt(ch->cp, CURLOPT_INFILE, (void *) ch);
  221. }
  222. }
  223. if (ch->handlers->write_header && !Z_ISUNDEF(ch->handlers->write_header->stream)) {
  224. stream = (php_stream *)zend_fetch_resource2_ex(&ch->handlers->write_header->stream, NULL, php_file_le_stream(), php_file_le_pstream());
  225. if (stream == NULL) {
  226. if (reporterror) {
  227. php_error_docref(NULL, E_WARNING, "CURLOPT_WRITEHEADER resource has gone away, resetting to default");
  228. }
  229. zval_ptr_dtor(&ch->handlers->write_header->stream);
  230. ZVAL_UNDEF(&ch->handlers->write_header->stream);
  231. ch->handlers->write_header->fp = 0;
  232. ch->handlers->write_header->method = PHP_CURL_IGNORE;
  233. curl_easy_setopt(ch->cp, CURLOPT_WRITEHEADER, (void *) ch);
  234. }
  235. }
  236. if (ch->handlers->write && !Z_ISUNDEF(ch->handlers->write->stream)) {
  237. stream = (php_stream *)zend_fetch_resource2_ex(&ch->handlers->write->stream, NULL, php_file_le_stream(), php_file_le_pstream());
  238. if (stream == NULL) {
  239. if (reporterror) {
  240. php_error_docref(NULL, E_WARNING, "CURLOPT_FILE resource has gone away, resetting to default");
  241. }
  242. zval_ptr_dtor(&ch->handlers->write->stream);
  243. ZVAL_UNDEF(&ch->handlers->write->stream);
  244. ch->handlers->write->fp = 0;
  245. ch->handlers->write->method = PHP_CURL_STDOUT;
  246. curl_easy_setopt(ch->cp, CURLOPT_FILE, (void *) ch);
  247. }
  248. }
  249. return;
  250. }
  251. /* }}} */
  252. /* {{{ arginfo */
  253. ZEND_BEGIN_ARG_INFO_EX(arginfo_curl_version, 0, 0, 0)
  254. ZEND_ARG_INFO(0, version)
  255. ZEND_END_ARG_INFO()
  256. ZEND_BEGIN_ARG_INFO_EX(arginfo_curl_init, 0, 0, 0)
  257. ZEND_ARG_INFO(0, url)
  258. ZEND_END_ARG_INFO()
  259. ZEND_BEGIN_ARG_INFO(arginfo_curl_copy_handle, 0)
  260. ZEND_ARG_INFO(0, ch)
  261. ZEND_END_ARG_INFO()
  262. ZEND_BEGIN_ARG_INFO(arginfo_curl_setopt, 0)
  263. ZEND_ARG_INFO(0, ch)
  264. ZEND_ARG_INFO(0, option)
  265. ZEND_ARG_INFO(0, value)
  266. ZEND_END_ARG_INFO()
  267. ZEND_BEGIN_ARG_INFO(arginfo_curl_setopt_array, 0)
  268. ZEND_ARG_INFO(0, ch)
  269. ZEND_ARG_ARRAY_INFO(0, options, 0)
  270. ZEND_END_ARG_INFO()
  271. ZEND_BEGIN_ARG_INFO(arginfo_curl_exec, 0)
  272. ZEND_ARG_INFO(0, ch)
  273. ZEND_END_ARG_INFO()
  274. ZEND_BEGIN_ARG_INFO_EX(arginfo_curl_getinfo, 0, 0, 1)
  275. ZEND_ARG_INFO(0, ch)
  276. ZEND_ARG_INFO(0, option)
  277. ZEND_END_ARG_INFO()
  278. ZEND_BEGIN_ARG_INFO(arginfo_curl_error, 0)
  279. ZEND_ARG_INFO(0, ch)
  280. ZEND_END_ARG_INFO()
  281. ZEND_BEGIN_ARG_INFO(arginfo_curl_errno, 0)
  282. ZEND_ARG_INFO(0, ch)
  283. ZEND_END_ARG_INFO()
  284. ZEND_BEGIN_ARG_INFO(arginfo_curl_close, 0)
  285. ZEND_ARG_INFO(0, ch)
  286. ZEND_END_ARG_INFO()
  287. ZEND_BEGIN_ARG_INFO(arginfo_curl_reset, 0)
  288. ZEND_ARG_INFO(0, ch)
  289. ZEND_END_ARG_INFO()
  290. ZEND_BEGIN_ARG_INFO(arginfo_curl_escape, 0)
  291. ZEND_ARG_INFO(0, ch)
  292. ZEND_ARG_INFO(0, str)
  293. ZEND_END_ARG_INFO()
  294. ZEND_BEGIN_ARG_INFO(arginfo_curl_unescape, 0)
  295. ZEND_ARG_INFO(0, ch)
  296. ZEND_ARG_INFO(0, str)
  297. ZEND_END_ARG_INFO()
  298. ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_setopt, 0)
  299. ZEND_ARG_INFO(0, sh)
  300. ZEND_ARG_INFO(0, option)
  301. ZEND_ARG_INFO(0, value)
  302. ZEND_END_ARG_INFO()
  303. ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_init, 0)
  304. ZEND_END_ARG_INFO()
  305. ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_add_handle, 0)
  306. ZEND_ARG_INFO(0, mh)
  307. ZEND_ARG_INFO(0, ch)
  308. ZEND_END_ARG_INFO()
  309. ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_remove_handle, 0)
  310. ZEND_ARG_INFO(0, mh)
  311. ZEND_ARG_INFO(0, ch)
  312. ZEND_END_ARG_INFO()
  313. ZEND_BEGIN_ARG_INFO_EX(arginfo_curl_multi_select, 0, 0, 1)
  314. ZEND_ARG_INFO(0, mh)
  315. ZEND_ARG_INFO(0, timeout)
  316. ZEND_END_ARG_INFO()
  317. ZEND_BEGIN_ARG_INFO_EX(arginfo_curl_multi_exec, 0, 0, 1)
  318. ZEND_ARG_INFO(0, mh)
  319. ZEND_ARG_INFO(1, still_running)
  320. ZEND_END_ARG_INFO()
  321. ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_getcontent, 0)
  322. ZEND_ARG_INFO(0, ch)
  323. ZEND_END_ARG_INFO()
  324. ZEND_BEGIN_ARG_INFO_EX(arginfo_curl_multi_info_read, 0, 0, 1)
  325. ZEND_ARG_INFO(0, mh)
  326. ZEND_ARG_INFO(1, msgs_in_queue)
  327. ZEND_END_ARG_INFO()
  328. ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_close, 0)
  329. ZEND_ARG_INFO(0, mh)
  330. ZEND_END_ARG_INFO()
  331. ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_errno, 0)
  332. ZEND_ARG_INFO(0, mh)
  333. ZEND_END_ARG_INFO()
  334. ZEND_BEGIN_ARG_INFO(arginfo_curl_strerror, 0)
  335. ZEND_ARG_INFO(0, errornum)
  336. ZEND_END_ARG_INFO()
  337. ZEND_BEGIN_ARG_INFO(arginfo_curl_multi_strerror, 0)
  338. ZEND_ARG_INFO(0, errornum)
  339. ZEND_END_ARG_INFO()
  340. ZEND_BEGIN_ARG_INFO(arginfo_curl_share_strerror, 0)
  341. ZEND_ARG_INFO(0, errornum)
  342. ZEND_END_ARG_INFO()
  343. ZEND_BEGIN_ARG_INFO(arginfo_curl_share_init, 0)
  344. ZEND_END_ARG_INFO()
  345. ZEND_BEGIN_ARG_INFO(arginfo_curl_share_close, 0)
  346. ZEND_ARG_INFO(0, sh)
  347. ZEND_END_ARG_INFO()
  348. ZEND_BEGIN_ARG_INFO(arginfo_curl_share_setopt, 0)
  349. ZEND_ARG_INFO(0, sh)
  350. ZEND_ARG_INFO(0, option)
  351. ZEND_ARG_INFO(0, value)
  352. ZEND_END_ARG_INFO()
  353. ZEND_BEGIN_ARG_INFO(arginfo_curl_share_errno, 0)
  354. ZEND_ARG_INFO(0, sh)
  355. ZEND_END_ARG_INFO()
  356. #if LIBCURL_VERSION_NUM >= 0x071200 /* Available since 7.18.0 */
  357. ZEND_BEGIN_ARG_INFO(arginfo_curl_pause, 0)
  358. ZEND_ARG_INFO(0, ch)
  359. ZEND_ARG_INFO(0, bitmask)
  360. ZEND_END_ARG_INFO()
  361. #endif
  362. ZEND_BEGIN_ARG_INFO_EX(arginfo_curlfile_create, 0, 0, 1)
  363. ZEND_ARG_INFO(0, filename)
  364. ZEND_ARG_INFO(0, mimetype)
  365. ZEND_ARG_INFO(0, postname)
  366. ZEND_END_ARG_INFO()
  367. /* }}} */
  368. /* {{{ curl_functions[]
  369. */
  370. static const zend_function_entry curl_functions[] = {
  371. PHP_FE(curl_init, arginfo_curl_init)
  372. PHP_FE(curl_copy_handle, arginfo_curl_copy_handle)
  373. PHP_FE(curl_version, arginfo_curl_version)
  374. PHP_FE(curl_setopt, arginfo_curl_setopt)
  375. PHP_FE(curl_setopt_array, arginfo_curl_setopt_array)
  376. PHP_FE(curl_exec, arginfo_curl_exec)
  377. PHP_FE(curl_getinfo, arginfo_curl_getinfo)
  378. PHP_FE(curl_error, arginfo_curl_error)
  379. PHP_FE(curl_errno, arginfo_curl_errno)
  380. PHP_FE(curl_close, arginfo_curl_close)
  381. PHP_FE(curl_strerror, arginfo_curl_strerror)
  382. PHP_FE(curl_multi_strerror, arginfo_curl_multi_strerror)
  383. PHP_FE(curl_share_strerror, arginfo_curl_share_strerror)
  384. PHP_FE(curl_reset, arginfo_curl_reset)
  385. PHP_FE(curl_escape, arginfo_curl_escape)
  386. PHP_FE(curl_unescape, arginfo_curl_unescape)
  387. #if LIBCURL_VERSION_NUM >= 0x071200 /* 7.18.0 */
  388. PHP_FE(curl_pause, arginfo_curl_pause)
  389. #endif
  390. PHP_FE(curl_multi_init, arginfo_curl_multi_init)
  391. PHP_FE(curl_multi_add_handle, arginfo_curl_multi_add_handle)
  392. PHP_FE(curl_multi_remove_handle, arginfo_curl_multi_remove_handle)
  393. PHP_FE(curl_multi_select, arginfo_curl_multi_select)
  394. PHP_FE(curl_multi_exec, arginfo_curl_multi_exec)
  395. PHP_FE(curl_multi_getcontent, arginfo_curl_multi_getcontent)
  396. PHP_FE(curl_multi_info_read, arginfo_curl_multi_info_read)
  397. PHP_FE(curl_multi_close, arginfo_curl_multi_close)
  398. PHP_FE(curl_multi_errno, arginfo_curl_multi_errno)
  399. PHP_FE(curl_multi_setopt, arginfo_curl_multi_setopt)
  400. PHP_FE(curl_share_init, arginfo_curl_share_init)
  401. PHP_FE(curl_share_close, arginfo_curl_share_close)
  402. PHP_FE(curl_share_setopt, arginfo_curl_share_setopt)
  403. PHP_FE(curl_share_errno, arginfo_curl_share_errno)
  404. PHP_FE(curl_file_create, arginfo_curlfile_create)
  405. PHP_FE_END
  406. };
  407. /* }}} */
  408. /* {{{ curl_module_entry
  409. */
  410. zend_module_entry curl_module_entry = {
  411. STANDARD_MODULE_HEADER,
  412. "curl",
  413. curl_functions,
  414. PHP_MINIT(curl),
  415. PHP_MSHUTDOWN(curl),
  416. NULL,
  417. NULL,
  418. PHP_MINFO(curl),
  419. PHP_CURL_VERSION,
  420. STANDARD_MODULE_PROPERTIES
  421. };
  422. /* }}} */
  423. #ifdef COMPILE_DL_CURL
  424. ZEND_GET_MODULE (curl)
  425. #endif
  426. /* {{{ PHP_INI_BEGIN */
  427. PHP_INI_BEGIN()
  428. PHP_INI_ENTRY("curl.cainfo", "", PHP_INI_SYSTEM, NULL)
  429. PHP_INI_END()
  430. /* }}} */
  431. /* {{{ PHP_MINFO_FUNCTION
  432. */
  433. PHP_MINFO_FUNCTION(curl)
  434. {
  435. curl_version_info_data *d;
  436. char **p;
  437. char str[1024];
  438. size_t n = 0;
  439. d = curl_version_info(CURLVERSION_NOW);
  440. php_info_print_table_start();
  441. php_info_print_table_row(2, "cURL support", "enabled");
  442. php_info_print_table_row(2, "cURL Information", d->version);
  443. sprintf(str, "%d", d->age);
  444. php_info_print_table_row(2, "Age", str);
  445. /* To update on each new cURL release using src/main.c in cURL sources */
  446. if (d->features) {
  447. struct feat {
  448. const char *name;
  449. int bitmask;
  450. };
  451. unsigned int i;
  452. static const struct feat feats[] = {
  453. {"AsynchDNS", CURL_VERSION_ASYNCHDNS},
  454. {"CharConv", CURL_VERSION_CONV},
  455. {"Debug", CURL_VERSION_DEBUG},
  456. {"GSS-Negotiate", CURL_VERSION_GSSNEGOTIATE},
  457. {"IDN", CURL_VERSION_IDN},
  458. {"IPv6", CURL_VERSION_IPV6},
  459. {"krb4", CURL_VERSION_KERBEROS4},
  460. {"Largefile", CURL_VERSION_LARGEFILE},
  461. {"libz", CURL_VERSION_LIBZ},
  462. {"NTLM", CURL_VERSION_NTLM},
  463. #if LIBCURL_VERSION_NUM >= 0x071600 /* 7.22.0 */
  464. {"NTLMWB", CURL_VERSION_NTLM_WB},
  465. #endif
  466. {"SPNEGO", CURL_VERSION_SPNEGO},
  467. {"SSL", CURL_VERSION_SSL},
  468. {"SSPI", CURL_VERSION_SSPI},
  469. #if LIBCURL_VERSION_NUM >= 0x071504 /* 7.21.4 */
  470. {"TLS-SRP", CURL_VERSION_TLSAUTH_SRP},
  471. #endif
  472. #if LIBCURL_VERSION_NUM >= 0x072100 /* 7.33.0 */
  473. {"HTTP2", CURL_VERSION_HTTP2},
  474. #endif
  475. #if LIBCURL_VERSION_NUM >= 0x072600 /* 7.38.0 */
  476. {"GSSAPI", CURL_VERSION_GSSAPI},
  477. #endif
  478. #if LIBCURL_VERSION_NUM >= 0x072800 /* 7.40.0 */
  479. {"KERBEROS5", CURL_VERSION_KERBEROS5},
  480. {"UNIX_SOCKETS", CURL_VERSION_UNIX_SOCKETS},
  481. #endif
  482. #if LIBCURL_VERSION_NUM >= 0x072f00 /* 7.47.0 */
  483. {"PSL", CURL_VERSION_PSL},
  484. #endif
  485. #if LIBCURL_VERSION_NUM >= 0x073400 /* 7.52.0 */
  486. {"HTTPS_PROXY", CURL_VERSION_HTTPS_PROXY},
  487. #endif
  488. #if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
  489. {"MULTI_SSL", CURL_VERSION_MULTI_SSL},
  490. #endif
  491. #if LIBCURL_VERSION_NUM >= 0x073900 /* 7.57.0 */
  492. {"BROTLI", CURL_VERSION_BROTLI},
  493. #endif
  494. {NULL, 0}
  495. };
  496. php_info_print_table_row(1, "Features");
  497. for(i=0; i<sizeof(feats)/sizeof(feats[0]); i++) {
  498. if (feats[i].name) {
  499. php_info_print_table_row(2, feats[i].name, d->features & feats[i].bitmask ? "Yes" : "No");
  500. }
  501. }
  502. }
  503. n = 0;
  504. p = (char **) d->protocols;
  505. while (*p != NULL) {
  506. n += sprintf(str + n, "%s%s", *p, *(p + 1) != NULL ? ", " : "");
  507. p++;
  508. }
  509. php_info_print_table_row(2, "Protocols", str);
  510. php_info_print_table_row(2, "Host", d->host);
  511. if (d->ssl_version) {
  512. php_info_print_table_row(2, "SSL Version", d->ssl_version);
  513. }
  514. if (d->libz_version) {
  515. php_info_print_table_row(2, "ZLib Version", d->libz_version);
  516. }
  517. #if defined(CURLVERSION_SECOND) && CURLVERSION_NOW >= CURLVERSION_SECOND
  518. if (d->ares) {
  519. php_info_print_table_row(2, "ZLib Version", d->ares);
  520. }
  521. #endif
  522. #if defined(CURLVERSION_THIRD) && CURLVERSION_NOW >= CURLVERSION_THIRD
  523. if (d->libidn) {
  524. php_info_print_table_row(2, "libIDN Version", d->libidn);
  525. }
  526. #endif
  527. #if LIBCURL_VERSION_NUM >= 0x071300
  528. if (d->iconv_ver_num) {
  529. php_info_print_table_row(2, "IconV Version", d->iconv_ver_num);
  530. }
  531. if (d->libssh_version) {
  532. php_info_print_table_row(2, "libSSH Version", d->libssh_version);
  533. }
  534. #endif
  535. php_info_print_table_end();
  536. DISPLAY_INI_ENTRIES();
  537. }
  538. /* }}} */
  539. #define REGISTER_CURL_CONSTANT(__c) REGISTER_LONG_CONSTANT(#__c, __c, CONST_CS | CONST_PERSISTENT)
  540. /* {{{ PHP_MINIT_FUNCTION
  541. */
  542. PHP_MINIT_FUNCTION(curl)
  543. {
  544. le_curl = zend_register_list_destructors_ex(_php_curl_close, NULL, "curl", module_number);
  545. le_curl_multi_handle = zend_register_list_destructors_ex(_php_curl_multi_close, NULL, "curl_multi", module_number);
  546. le_curl_share_handle = zend_register_list_destructors_ex(_php_curl_share_close, NULL, "curl_share", module_number);
  547. REGISTER_INI_ENTRIES();
  548. /* See http://curl.haxx.se/lxr/source/docs/libcurl/symbols-in-versions
  549. or curl src/docs/libcurl/symbols-in-versions for a (almost) complete list
  550. of options and which version they were introduced */
  551. /* Constants for curl_setopt() */
  552. REGISTER_CURL_CONSTANT(CURLOPT_AUTOREFERER);
  553. REGISTER_CURL_CONSTANT(CURLOPT_BINARYTRANSFER);
  554. REGISTER_CURL_CONSTANT(CURLOPT_BUFFERSIZE);
  555. REGISTER_CURL_CONSTANT(CURLOPT_CAINFO);
  556. REGISTER_CURL_CONSTANT(CURLOPT_CAPATH);
  557. REGISTER_CURL_CONSTANT(CURLOPT_CONNECTTIMEOUT);
  558. REGISTER_CURL_CONSTANT(CURLOPT_COOKIE);
  559. REGISTER_CURL_CONSTANT(CURLOPT_COOKIEFILE);
  560. REGISTER_CURL_CONSTANT(CURLOPT_COOKIEJAR);
  561. REGISTER_CURL_CONSTANT(CURLOPT_COOKIESESSION);
  562. REGISTER_CURL_CONSTANT(CURLOPT_CRLF);
  563. REGISTER_CURL_CONSTANT(CURLOPT_CUSTOMREQUEST);
  564. REGISTER_CURL_CONSTANT(CURLOPT_DNS_CACHE_TIMEOUT);
  565. REGISTER_CURL_CONSTANT(CURLOPT_DNS_USE_GLOBAL_CACHE);
  566. REGISTER_CURL_CONSTANT(CURLOPT_EGDSOCKET);
  567. REGISTER_CURL_CONSTANT(CURLOPT_ENCODING);
  568. REGISTER_CURL_CONSTANT(CURLOPT_FAILONERROR);
  569. REGISTER_CURL_CONSTANT(CURLOPT_FILE);
  570. REGISTER_CURL_CONSTANT(CURLOPT_FILETIME);
  571. REGISTER_CURL_CONSTANT(CURLOPT_FOLLOWLOCATION);
  572. REGISTER_CURL_CONSTANT(CURLOPT_FORBID_REUSE);
  573. REGISTER_CURL_CONSTANT(CURLOPT_FRESH_CONNECT);
  574. REGISTER_CURL_CONSTANT(CURLOPT_FTPAPPEND);
  575. REGISTER_CURL_CONSTANT(CURLOPT_FTPLISTONLY);
  576. REGISTER_CURL_CONSTANT(CURLOPT_FTPPORT);
  577. REGISTER_CURL_CONSTANT(CURLOPT_FTP_USE_EPRT);
  578. REGISTER_CURL_CONSTANT(CURLOPT_FTP_USE_EPSV);
  579. REGISTER_CURL_CONSTANT(CURLOPT_HEADER);
  580. REGISTER_CURL_CONSTANT(CURLOPT_HEADERFUNCTION);
  581. REGISTER_CURL_CONSTANT(CURLOPT_HTTP200ALIASES);
  582. REGISTER_CURL_CONSTANT(CURLOPT_HTTPGET);
  583. REGISTER_CURL_CONSTANT(CURLOPT_HTTPHEADER);
  584. REGISTER_CURL_CONSTANT(CURLOPT_HTTPPROXYTUNNEL);
  585. REGISTER_CURL_CONSTANT(CURLOPT_HTTP_VERSION);
  586. REGISTER_CURL_CONSTANT(CURLOPT_INFILE);
  587. REGISTER_CURL_CONSTANT(CURLOPT_INFILESIZE);
  588. REGISTER_CURL_CONSTANT(CURLOPT_INTERFACE);
  589. REGISTER_CURL_CONSTANT(CURLOPT_KRB4LEVEL);
  590. REGISTER_CURL_CONSTANT(CURLOPT_LOW_SPEED_LIMIT);
  591. REGISTER_CURL_CONSTANT(CURLOPT_LOW_SPEED_TIME);
  592. REGISTER_CURL_CONSTANT(CURLOPT_MAXCONNECTS);
  593. REGISTER_CURL_CONSTANT(CURLOPT_MAXREDIRS);
  594. REGISTER_CURL_CONSTANT(CURLOPT_NETRC);
  595. REGISTER_CURL_CONSTANT(CURLOPT_NOBODY);
  596. REGISTER_CURL_CONSTANT(CURLOPT_NOPROGRESS);
  597. REGISTER_CURL_CONSTANT(CURLOPT_NOSIGNAL);
  598. REGISTER_CURL_CONSTANT(CURLOPT_PORT);
  599. REGISTER_CURL_CONSTANT(CURLOPT_POST);
  600. REGISTER_CURL_CONSTANT(CURLOPT_POSTFIELDS);
  601. REGISTER_CURL_CONSTANT(CURLOPT_POSTQUOTE);
  602. REGISTER_CURL_CONSTANT(CURLOPT_PREQUOTE);
  603. REGISTER_CURL_CONSTANT(CURLOPT_PRIVATE);
  604. REGISTER_CURL_CONSTANT(CURLOPT_PROGRESSFUNCTION);
  605. REGISTER_CURL_CONSTANT(CURLOPT_PROXY);
  606. REGISTER_CURL_CONSTANT(CURLOPT_PROXYPORT);
  607. REGISTER_CURL_CONSTANT(CURLOPT_PROXYTYPE);
  608. REGISTER_CURL_CONSTANT(CURLOPT_PROXYUSERPWD);
  609. REGISTER_CURL_CONSTANT(CURLOPT_PUT);
  610. REGISTER_CURL_CONSTANT(CURLOPT_QUOTE);
  611. REGISTER_CURL_CONSTANT(CURLOPT_RANDOM_FILE);
  612. REGISTER_CURL_CONSTANT(CURLOPT_RANGE);
  613. REGISTER_CURL_CONSTANT(CURLOPT_READDATA);
  614. REGISTER_CURL_CONSTANT(CURLOPT_READFUNCTION);
  615. REGISTER_CURL_CONSTANT(CURLOPT_REFERER);
  616. REGISTER_CURL_CONSTANT(CURLOPT_RESUME_FROM);
  617. REGISTER_CURL_CONSTANT(CURLOPT_RETURNTRANSFER);
  618. REGISTER_CURL_CONSTANT(CURLOPT_SHARE);
  619. REGISTER_CURL_CONSTANT(CURLOPT_SSLCERT);
  620. REGISTER_CURL_CONSTANT(CURLOPT_SSLCERTPASSWD);
  621. REGISTER_CURL_CONSTANT(CURLOPT_SSLCERTTYPE);
  622. REGISTER_CURL_CONSTANT(CURLOPT_SSLENGINE);
  623. REGISTER_CURL_CONSTANT(CURLOPT_SSLENGINE_DEFAULT);
  624. REGISTER_CURL_CONSTANT(CURLOPT_SSLKEY);
  625. REGISTER_CURL_CONSTANT(CURLOPT_SSLKEYPASSWD);
  626. REGISTER_CURL_CONSTANT(CURLOPT_SSLKEYTYPE);
  627. REGISTER_CURL_CONSTANT(CURLOPT_SSLVERSION);
  628. REGISTER_CURL_CONSTANT(CURLOPT_SSL_CIPHER_LIST);
  629. REGISTER_CURL_CONSTANT(CURLOPT_SSL_VERIFYHOST);
  630. REGISTER_CURL_CONSTANT(CURLOPT_SSL_VERIFYPEER);
  631. REGISTER_CURL_CONSTANT(CURLOPT_STDERR);
  632. REGISTER_CURL_CONSTANT(CURLOPT_TELNETOPTIONS);
  633. REGISTER_CURL_CONSTANT(CURLOPT_TIMECONDITION);
  634. REGISTER_CURL_CONSTANT(CURLOPT_TIMEOUT);
  635. REGISTER_CURL_CONSTANT(CURLOPT_TIMEVALUE);
  636. REGISTER_CURL_CONSTANT(CURLOPT_TRANSFERTEXT);
  637. REGISTER_CURL_CONSTANT(CURLOPT_UNRESTRICTED_AUTH);
  638. REGISTER_CURL_CONSTANT(CURLOPT_UPLOAD);
  639. REGISTER_CURL_CONSTANT(CURLOPT_URL);
  640. REGISTER_CURL_CONSTANT(CURLOPT_USERAGENT);
  641. REGISTER_CURL_CONSTANT(CURLOPT_USERPWD);
  642. REGISTER_CURL_CONSTANT(CURLOPT_VERBOSE);
  643. REGISTER_CURL_CONSTANT(CURLOPT_WRITEFUNCTION);
  644. REGISTER_CURL_CONSTANT(CURLOPT_WRITEHEADER);
  645. /* */
  646. REGISTER_CURL_CONSTANT(CURLE_ABORTED_BY_CALLBACK);
  647. REGISTER_CURL_CONSTANT(CURLE_BAD_CALLING_ORDER);
  648. REGISTER_CURL_CONSTANT(CURLE_BAD_CONTENT_ENCODING);
  649. REGISTER_CURL_CONSTANT(CURLE_BAD_DOWNLOAD_RESUME);
  650. REGISTER_CURL_CONSTANT(CURLE_BAD_FUNCTION_ARGUMENT);
  651. REGISTER_CURL_CONSTANT(CURLE_BAD_PASSWORD_ENTERED);
  652. REGISTER_CURL_CONSTANT(CURLE_COULDNT_CONNECT);
  653. REGISTER_CURL_CONSTANT(CURLE_COULDNT_RESOLVE_HOST);
  654. REGISTER_CURL_CONSTANT(CURLE_COULDNT_RESOLVE_PROXY);
  655. REGISTER_CURL_CONSTANT(CURLE_FAILED_INIT);
  656. REGISTER_CURL_CONSTANT(CURLE_FILE_COULDNT_READ_FILE);
  657. REGISTER_CURL_CONSTANT(CURLE_FTP_ACCESS_DENIED);
  658. REGISTER_CURL_CONSTANT(CURLE_FTP_BAD_DOWNLOAD_RESUME);
  659. REGISTER_CURL_CONSTANT(CURLE_FTP_CANT_GET_HOST);
  660. REGISTER_CURL_CONSTANT(CURLE_FTP_CANT_RECONNECT);
  661. REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_GET_SIZE);
  662. REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_RETR_FILE);
  663. REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_SET_ASCII);
  664. REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_SET_BINARY);
  665. REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_STOR_FILE);
  666. REGISTER_CURL_CONSTANT(CURLE_FTP_COULDNT_USE_REST);
  667. REGISTER_CURL_CONSTANT(CURLE_FTP_PARTIAL_FILE);
  668. REGISTER_CURL_CONSTANT(CURLE_FTP_PORT_FAILED);
  669. REGISTER_CURL_CONSTANT(CURLE_FTP_QUOTE_ERROR);
  670. REGISTER_CURL_CONSTANT(CURLE_FTP_USER_PASSWORD_INCORRECT);
  671. REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_227_FORMAT);
  672. REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_PASS_REPLY);
  673. REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_PASV_REPLY);
  674. REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_SERVER_REPLY);
  675. REGISTER_CURL_CONSTANT(CURLE_FTP_WEIRD_USER_REPLY);
  676. REGISTER_CURL_CONSTANT(CURLE_FTP_WRITE_ERROR);
  677. REGISTER_CURL_CONSTANT(CURLE_FUNCTION_NOT_FOUND);
  678. REGISTER_CURL_CONSTANT(CURLE_GOT_NOTHING);
  679. REGISTER_CURL_CONSTANT(CURLE_HTTP_NOT_FOUND);
  680. REGISTER_CURL_CONSTANT(CURLE_HTTP_PORT_FAILED);
  681. REGISTER_CURL_CONSTANT(CURLE_HTTP_POST_ERROR);
  682. REGISTER_CURL_CONSTANT(CURLE_HTTP_RANGE_ERROR);
  683. REGISTER_CURL_CONSTANT(CURLE_HTTP_RETURNED_ERROR);
  684. REGISTER_CURL_CONSTANT(CURLE_LDAP_CANNOT_BIND);
  685. REGISTER_CURL_CONSTANT(CURLE_LDAP_SEARCH_FAILED);
  686. REGISTER_CURL_CONSTANT(CURLE_LIBRARY_NOT_FOUND);
  687. REGISTER_CURL_CONSTANT(CURLE_MALFORMAT_USER);
  688. REGISTER_CURL_CONSTANT(CURLE_OBSOLETE);
  689. REGISTER_CURL_CONSTANT(CURLE_OK);
  690. REGISTER_CURL_CONSTANT(CURLE_OPERATION_TIMEDOUT);
  691. REGISTER_CURL_CONSTANT(CURLE_OPERATION_TIMEOUTED);
  692. REGISTER_CURL_CONSTANT(CURLE_OUT_OF_MEMORY);
  693. REGISTER_CURL_CONSTANT(CURLE_PARTIAL_FILE);
  694. REGISTER_CURL_CONSTANT(CURLE_READ_ERROR);
  695. REGISTER_CURL_CONSTANT(CURLE_RECV_ERROR);
  696. REGISTER_CURL_CONSTANT(CURLE_SEND_ERROR);
  697. REGISTER_CURL_CONSTANT(CURLE_SHARE_IN_USE);
  698. REGISTER_CURL_CONSTANT(CURLE_SSL_CACERT);
  699. REGISTER_CURL_CONSTANT(CURLE_SSL_CERTPROBLEM);
  700. REGISTER_CURL_CONSTANT(CURLE_SSL_CIPHER);
  701. REGISTER_CURL_CONSTANT(CURLE_SSL_CONNECT_ERROR);
  702. REGISTER_CURL_CONSTANT(CURLE_SSL_ENGINE_NOTFOUND);
  703. REGISTER_CURL_CONSTANT(CURLE_SSL_ENGINE_SETFAILED);
  704. REGISTER_CURL_CONSTANT(CURLE_SSL_PEER_CERTIFICATE);
  705. #if LIBCURL_VERSION_NUM >= 0x072700 /* Available since 7.39.0 */
  706. REGISTER_CURL_CONSTANT(CURLE_SSL_PINNEDPUBKEYNOTMATCH);
  707. #endif
  708. REGISTER_CURL_CONSTANT(CURLE_TELNET_OPTION_SYNTAX);
  709. REGISTER_CURL_CONSTANT(CURLE_TOO_MANY_REDIRECTS);
  710. REGISTER_CURL_CONSTANT(CURLE_UNKNOWN_TELNET_OPTION);
  711. REGISTER_CURL_CONSTANT(CURLE_UNSUPPORTED_PROTOCOL);
  712. REGISTER_CURL_CONSTANT(CURLE_URL_MALFORMAT);
  713. REGISTER_CURL_CONSTANT(CURLE_URL_MALFORMAT_USER);
  714. REGISTER_CURL_CONSTANT(CURLE_WRITE_ERROR);
  715. /* cURL info constants */
  716. REGISTER_CURL_CONSTANT(CURLINFO_CONNECT_TIME);
  717. REGISTER_CURL_CONSTANT(CURLINFO_CONTENT_LENGTH_DOWNLOAD);
  718. REGISTER_CURL_CONSTANT(CURLINFO_CONTENT_LENGTH_UPLOAD);
  719. REGISTER_CURL_CONSTANT(CURLINFO_CONTENT_TYPE);
  720. REGISTER_CURL_CONSTANT(CURLINFO_EFFECTIVE_URL);
  721. REGISTER_CURL_CONSTANT(CURLINFO_FILETIME);
  722. REGISTER_CURL_CONSTANT(CURLINFO_HEADER_OUT);
  723. REGISTER_CURL_CONSTANT(CURLINFO_HEADER_SIZE);
  724. REGISTER_CURL_CONSTANT(CURLINFO_HTTP_CODE);
  725. REGISTER_CURL_CONSTANT(CURLINFO_LASTONE);
  726. REGISTER_CURL_CONSTANT(CURLINFO_NAMELOOKUP_TIME);
  727. REGISTER_CURL_CONSTANT(CURLINFO_PRETRANSFER_TIME);
  728. REGISTER_CURL_CONSTANT(CURLINFO_PRIVATE);
  729. REGISTER_CURL_CONSTANT(CURLINFO_REDIRECT_COUNT);
  730. REGISTER_CURL_CONSTANT(CURLINFO_REDIRECT_TIME);
  731. REGISTER_CURL_CONSTANT(CURLINFO_REQUEST_SIZE);
  732. REGISTER_CURL_CONSTANT(CURLINFO_SIZE_DOWNLOAD);
  733. REGISTER_CURL_CONSTANT(CURLINFO_SIZE_UPLOAD);
  734. REGISTER_CURL_CONSTANT(CURLINFO_SPEED_DOWNLOAD);
  735. REGISTER_CURL_CONSTANT(CURLINFO_SPEED_UPLOAD);
  736. REGISTER_CURL_CONSTANT(CURLINFO_SSL_VERIFYRESULT);
  737. REGISTER_CURL_CONSTANT(CURLINFO_STARTTRANSFER_TIME);
  738. REGISTER_CURL_CONSTANT(CURLINFO_TOTAL_TIME);
  739. /* Other */
  740. REGISTER_CURL_CONSTANT(CURLMSG_DONE);
  741. REGISTER_CURL_CONSTANT(CURLVERSION_NOW);
  742. /* Curl Multi Constants */
  743. REGISTER_CURL_CONSTANT(CURLM_BAD_EASY_HANDLE);
  744. REGISTER_CURL_CONSTANT(CURLM_BAD_HANDLE);
  745. REGISTER_CURL_CONSTANT(CURLM_CALL_MULTI_PERFORM);
  746. REGISTER_CURL_CONSTANT(CURLM_INTERNAL_ERROR);
  747. REGISTER_CURL_CONSTANT(CURLM_OK);
  748. REGISTER_CURL_CONSTANT(CURLM_OUT_OF_MEMORY);
  749. #if LIBCURL_VERSION_NUM >= 0x072001 /* Available since 7.32.1 */
  750. REGISTER_CURL_CONSTANT(CURLM_ADDED_ALREADY);
  751. #endif
  752. /* Curl proxy constants */
  753. REGISTER_CURL_CONSTANT(CURLPROXY_HTTP);
  754. REGISTER_CURL_CONSTANT(CURLPROXY_SOCKS4);
  755. REGISTER_CURL_CONSTANT(CURLPROXY_SOCKS5);
  756. /* Curl Share constants */
  757. REGISTER_CURL_CONSTANT(CURLSHOPT_NONE);
  758. REGISTER_CURL_CONSTANT(CURLSHOPT_SHARE);
  759. REGISTER_CURL_CONSTANT(CURLSHOPT_UNSHARE);
  760. /* Curl Http Version constants (CURLOPT_HTTP_VERSION) */
  761. REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_1_0);
  762. REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_1_1);
  763. REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_NONE);
  764. /* Curl Lock constants */
  765. REGISTER_CURL_CONSTANT(CURL_LOCK_DATA_COOKIE);
  766. REGISTER_CURL_CONSTANT(CURL_LOCK_DATA_DNS);
  767. REGISTER_CURL_CONSTANT(CURL_LOCK_DATA_SSL_SESSION);
  768. /* Curl NETRC constants (CURLOPT_NETRC) */
  769. REGISTER_CURL_CONSTANT(CURL_NETRC_IGNORED);
  770. REGISTER_CURL_CONSTANT(CURL_NETRC_OPTIONAL);
  771. REGISTER_CURL_CONSTANT(CURL_NETRC_REQUIRED);
  772. /* Curl SSL Version constants (CURLOPT_SSLVERSION) */
  773. REGISTER_CURL_CONSTANT(CURL_SSLVERSION_DEFAULT);
  774. REGISTER_CURL_CONSTANT(CURL_SSLVERSION_SSLv2);
  775. REGISTER_CURL_CONSTANT(CURL_SSLVERSION_SSLv3);
  776. REGISTER_CURL_CONSTANT(CURL_SSLVERSION_TLSv1);
  777. /* Curl TIMECOND constants (CURLOPT_TIMECONDITION) */
  778. REGISTER_CURL_CONSTANT(CURL_TIMECOND_IFMODSINCE);
  779. REGISTER_CURL_CONSTANT(CURL_TIMECOND_IFUNMODSINCE);
  780. REGISTER_CURL_CONSTANT(CURL_TIMECOND_LASTMOD);
  781. REGISTER_CURL_CONSTANT(CURL_TIMECOND_NONE);
  782. /* Curl version constants */
  783. REGISTER_CURL_CONSTANT(CURL_VERSION_ASYNCHDNS);
  784. REGISTER_CURL_CONSTANT(CURL_VERSION_CONV);
  785. REGISTER_CURL_CONSTANT(CURL_VERSION_DEBUG);
  786. REGISTER_CURL_CONSTANT(CURL_VERSION_GSSNEGOTIATE);
  787. REGISTER_CURL_CONSTANT(CURL_VERSION_IDN);
  788. REGISTER_CURL_CONSTANT(CURL_VERSION_IPV6);
  789. REGISTER_CURL_CONSTANT(CURL_VERSION_KERBEROS4);
  790. REGISTER_CURL_CONSTANT(CURL_VERSION_LARGEFILE);
  791. REGISTER_CURL_CONSTANT(CURL_VERSION_LIBZ);
  792. REGISTER_CURL_CONSTANT(CURL_VERSION_NTLM);
  793. REGISTER_CURL_CONSTANT(CURL_VERSION_SPNEGO);
  794. REGISTER_CURL_CONSTANT(CURL_VERSION_SSL);
  795. REGISTER_CURL_CONSTANT(CURL_VERSION_SSPI);
  796. /* Available since 7.10.6 */
  797. REGISTER_CURL_CONSTANT(CURLOPT_HTTPAUTH);
  798. /* http authentication options */
  799. REGISTER_CURL_CONSTANT(CURLAUTH_ANY);
  800. REGISTER_CURL_CONSTANT(CURLAUTH_ANYSAFE);
  801. REGISTER_CURL_CONSTANT(CURLAUTH_BASIC);
  802. REGISTER_CURL_CONSTANT(CURLAUTH_DIGEST);
  803. REGISTER_CURL_CONSTANT(CURLAUTH_GSSNEGOTIATE);
  804. REGISTER_CURL_CONSTANT(CURLAUTH_NONE);
  805. REGISTER_CURL_CONSTANT(CURLAUTH_NTLM);
  806. /* Available since 7.10.7 */
  807. REGISTER_CURL_CONSTANT(CURLINFO_HTTP_CONNECTCODE);
  808. REGISTER_CURL_CONSTANT(CURLOPT_FTP_CREATE_MISSING_DIRS);
  809. REGISTER_CURL_CONSTANT(CURLOPT_PROXYAUTH);
  810. /* Available since 7.10.8 */
  811. REGISTER_CURL_CONSTANT(CURLE_FILESIZE_EXCEEDED);
  812. REGISTER_CURL_CONSTANT(CURLE_LDAP_INVALID_URL);
  813. REGISTER_CURL_CONSTANT(CURLINFO_HTTPAUTH_AVAIL);
  814. REGISTER_CURL_CONSTANT(CURLINFO_RESPONSE_CODE);
  815. REGISTER_CURL_CONSTANT(CURLINFO_PROXYAUTH_AVAIL);
  816. REGISTER_CURL_CONSTANT(CURLOPT_FTP_RESPONSE_TIMEOUT);
  817. REGISTER_CURL_CONSTANT(CURLOPT_IPRESOLVE);
  818. REGISTER_CURL_CONSTANT(CURLOPT_MAXFILESIZE);
  819. REGISTER_CURL_CONSTANT(CURL_IPRESOLVE_V4);
  820. REGISTER_CURL_CONSTANT(CURL_IPRESOLVE_V6);
  821. REGISTER_CURL_CONSTANT(CURL_IPRESOLVE_WHATEVER);
  822. /* Available since 7.11.0 */
  823. REGISTER_CURL_CONSTANT(CURLE_FTP_SSL_FAILED);
  824. REGISTER_CURL_CONSTANT(CURLFTPSSL_ALL);
  825. REGISTER_CURL_CONSTANT(CURLFTPSSL_CONTROL);
  826. REGISTER_CURL_CONSTANT(CURLFTPSSL_NONE);
  827. REGISTER_CURL_CONSTANT(CURLFTPSSL_TRY);
  828. REGISTER_CURL_CONSTANT(CURLOPT_FTP_SSL);
  829. REGISTER_CURL_CONSTANT(CURLOPT_NETRC_FILE);
  830. /* Available since 7.11.2 */
  831. REGISTER_CURL_CONSTANT(CURLOPT_TCP_NODELAY);
  832. /* Available since 7.12.2 */
  833. REGISTER_CURL_CONSTANT(CURLFTPAUTH_DEFAULT);
  834. REGISTER_CURL_CONSTANT(CURLFTPAUTH_SSL);
  835. REGISTER_CURL_CONSTANT(CURLFTPAUTH_TLS);
  836. REGISTER_CURL_CONSTANT(CURLOPT_FTPSSLAUTH);
  837. /* Available since 7.13.0 */
  838. REGISTER_CURL_CONSTANT(CURLOPT_FTP_ACCOUNT);
  839. /* Available since 7.12.2 */
  840. REGISTER_CURL_CONSTANT(CURLINFO_OS_ERRNO);
  841. /* Available since 7.12.3 */
  842. REGISTER_CURL_CONSTANT(CURLINFO_NUM_CONNECTS);
  843. REGISTER_CURL_CONSTANT(CURLINFO_SSL_ENGINES);
  844. /* Available since 7.14.1 */
  845. REGISTER_CURL_CONSTANT(CURLINFO_COOKIELIST);
  846. REGISTER_CURL_CONSTANT(CURLOPT_COOKIELIST);
  847. REGISTER_CURL_CONSTANT(CURLOPT_IGNORE_CONTENT_LENGTH);
  848. /* Available since 7.15.0 */
  849. REGISTER_CURL_CONSTANT(CURLOPT_FTP_SKIP_PASV_IP);
  850. /* Available since 7.15.1 */
  851. REGISTER_CURL_CONSTANT(CURLOPT_FTP_FILEMETHOD);
  852. /* Available since 7.15.2 */
  853. REGISTER_CURL_CONSTANT(CURLOPT_CONNECT_ONLY);
  854. REGISTER_CURL_CONSTANT(CURLOPT_LOCALPORT);
  855. REGISTER_CURL_CONSTANT(CURLOPT_LOCALPORTRANGE);
  856. /* Available since 7.15.3 */
  857. REGISTER_CURL_CONSTANT(CURLFTPMETHOD_MULTICWD);
  858. REGISTER_CURL_CONSTANT(CURLFTPMETHOD_NOCWD);
  859. REGISTER_CURL_CONSTANT(CURLFTPMETHOD_SINGLECWD);
  860. /* Available since 7.15.4 */
  861. REGISTER_CURL_CONSTANT(CURLINFO_FTP_ENTRY_PATH);
  862. /* Available since 7.15.5 */
  863. REGISTER_CURL_CONSTANT(CURLOPT_FTP_ALTERNATIVE_TO_USER);
  864. REGISTER_CURL_CONSTANT(CURLOPT_MAX_RECV_SPEED_LARGE);
  865. REGISTER_CURL_CONSTANT(CURLOPT_MAX_SEND_SPEED_LARGE);
  866. #if LIBCURL_VERSION_NUM >= 0x071000 /* Available since 7.16.0 */
  867. REGISTER_CURL_CONSTANT(CURLE_SSL_CACERT_BADFILE);
  868. REGISTER_CURL_CONSTANT(CURLOPT_SSL_SESSIONID_CACHE);
  869. REGISTER_CURL_CONSTANT(CURLMOPT_PIPELINING);
  870. #endif
  871. #if LIBCURL_VERSION_NUM >= 0x071001 /* Available since 7.16.1 */
  872. REGISTER_CURL_CONSTANT(CURLE_SSH);
  873. REGISTER_CURL_CONSTANT(CURLOPT_FTP_SSL_CCC);
  874. REGISTER_CURL_CONSTANT(CURLOPT_SSH_AUTH_TYPES);
  875. REGISTER_CURL_CONSTANT(CURLOPT_SSH_PRIVATE_KEYFILE);
  876. REGISTER_CURL_CONSTANT(CURLOPT_SSH_PUBLIC_KEYFILE);
  877. REGISTER_CURL_CONSTANT(CURLFTPSSL_CCC_ACTIVE);
  878. REGISTER_CURL_CONSTANT(CURLFTPSSL_CCC_NONE);
  879. REGISTER_CURL_CONSTANT(CURLFTPSSL_CCC_PASSIVE);
  880. #endif
  881. #if LIBCURL_VERSION_NUM >= 0x071002 /* Available since 7.16.2 */
  882. REGISTER_CURL_CONSTANT(CURLOPT_CONNECTTIMEOUT_MS);
  883. REGISTER_CURL_CONSTANT(CURLOPT_HTTP_CONTENT_DECODING);
  884. REGISTER_CURL_CONSTANT(CURLOPT_HTTP_TRANSFER_DECODING);
  885. REGISTER_CURL_CONSTANT(CURLOPT_TIMEOUT_MS);
  886. #endif
  887. #if LIBCURL_VERSION_NUM >= 0x071003 /* Available since 7.16.3 */
  888. REGISTER_CURL_CONSTANT(CURLMOPT_MAXCONNECTS);
  889. #endif
  890. #if LIBCURL_VERSION_NUM >= 0x071004 /* Available since 7.16.4 */
  891. REGISTER_CURL_CONSTANT(CURLOPT_KRBLEVEL);
  892. REGISTER_CURL_CONSTANT(CURLOPT_NEW_DIRECTORY_PERMS);
  893. REGISTER_CURL_CONSTANT(CURLOPT_NEW_FILE_PERMS);
  894. #endif
  895. #if LIBCURL_VERSION_NUM >= 0x071100 /* Available since 7.17.0 */
  896. REGISTER_CURL_CONSTANT(CURLOPT_APPEND);
  897. REGISTER_CURL_CONSTANT(CURLOPT_DIRLISTONLY);
  898. REGISTER_CURL_CONSTANT(CURLOPT_USE_SSL);
  899. /* Curl SSL Constants */
  900. REGISTER_CURL_CONSTANT(CURLUSESSL_ALL);
  901. REGISTER_CURL_CONSTANT(CURLUSESSL_CONTROL);
  902. REGISTER_CURL_CONSTANT(CURLUSESSL_NONE);
  903. REGISTER_CURL_CONSTANT(CURLUSESSL_TRY);
  904. #endif
  905. #if LIBCURL_VERSION_NUM >= 0x071101 /* Available since 7.17.1 */
  906. REGISTER_CURL_CONSTANT(CURLOPT_SSH_HOST_PUBLIC_KEY_MD5);
  907. #endif
  908. #if LIBCURL_VERSION_NUM >= 0x071200 /* Available since 7.18.0 */
  909. REGISTER_CURL_CONSTANT(CURLOPT_PROXY_TRANSFER_MODE);
  910. REGISTER_CURL_CONSTANT(CURLPAUSE_ALL);
  911. REGISTER_CURL_CONSTANT(CURLPAUSE_CONT);
  912. REGISTER_CURL_CONSTANT(CURLPAUSE_RECV);
  913. REGISTER_CURL_CONSTANT(CURLPAUSE_RECV_CONT);
  914. REGISTER_CURL_CONSTANT(CURLPAUSE_SEND);
  915. REGISTER_CURL_CONSTANT(CURLPAUSE_SEND_CONT);
  916. REGISTER_CURL_CONSTANT(CURL_READFUNC_PAUSE);
  917. REGISTER_CURL_CONSTANT(CURL_WRITEFUNC_PAUSE);
  918. REGISTER_CURL_CONSTANT(CURLPROXY_SOCKS4A);
  919. REGISTER_CURL_CONSTANT(CURLPROXY_SOCKS5_HOSTNAME);
  920. #endif
  921. #if LIBCURL_VERSION_NUM >= 0x071202 /* Available since 7.18.2 */
  922. REGISTER_CURL_CONSTANT(CURLINFO_REDIRECT_URL);
  923. #endif
  924. #if LIBCURL_VERSION_NUM >= 0x071300 /* Available since 7.19.0 */
  925. REGISTER_CURL_CONSTANT(CURLINFO_APPCONNECT_TIME);
  926. REGISTER_CURL_CONSTANT(CURLINFO_PRIMARY_IP);
  927. REGISTER_CURL_CONSTANT(CURLOPT_ADDRESS_SCOPE);
  928. REGISTER_CURL_CONSTANT(CURLOPT_CRLFILE);
  929. REGISTER_CURL_CONSTANT(CURLOPT_ISSUERCERT);
  930. REGISTER_CURL_CONSTANT(CURLOPT_KEYPASSWD);
  931. REGISTER_CURL_CONSTANT(CURLSSH_AUTH_ANY);
  932. REGISTER_CURL_CONSTANT(CURLSSH_AUTH_DEFAULT);
  933. REGISTER_CURL_CONSTANT(CURLSSH_AUTH_HOST);
  934. REGISTER_CURL_CONSTANT(CURLSSH_AUTH_KEYBOARD);
  935. REGISTER_CURL_CONSTANT(CURLSSH_AUTH_NONE);
  936. REGISTER_CURL_CONSTANT(CURLSSH_AUTH_PASSWORD);
  937. REGISTER_CURL_CONSTANT(CURLSSH_AUTH_PUBLICKEY);
  938. #endif
  939. #if LIBCURL_VERSION_NUM >= 0x071301 /* Available since 7.19.1 */
  940. REGISTER_CURL_CONSTANT(CURLINFO_CERTINFO);
  941. REGISTER_CURL_CONSTANT(CURLOPT_CERTINFO);
  942. REGISTER_CURL_CONSTANT(CURLOPT_PASSWORD);
  943. REGISTER_CURL_CONSTANT(CURLOPT_POSTREDIR);
  944. REGISTER_CURL_CONSTANT(CURLOPT_PROXYPASSWORD);
  945. REGISTER_CURL_CONSTANT(CURLOPT_PROXYUSERNAME);
  946. REGISTER_CURL_CONSTANT(CURLOPT_USERNAME);
  947. REGISTER_CURL_CONSTANT(CURL_REDIR_POST_301);
  948. REGISTER_CURL_CONSTANT(CURL_REDIR_POST_302);
  949. REGISTER_CURL_CONSTANT(CURL_REDIR_POST_ALL);
  950. #endif
  951. #if LIBCURL_VERSION_NUM >= 0x071303 /* Available since 7.19.3 */
  952. REGISTER_CURL_CONSTANT(CURLAUTH_DIGEST_IE);
  953. #endif
  954. #if LIBCURL_VERSION_NUM >= 0x071304 /* Available since 7.19.4 */
  955. REGISTER_CURL_CONSTANT(CURLINFO_CONDITION_UNMET);
  956. REGISTER_CURL_CONSTANT(CURLOPT_NOPROXY);
  957. REGISTER_CURL_CONSTANT(CURLOPT_PROTOCOLS);
  958. REGISTER_CURL_CONSTANT(CURLOPT_REDIR_PROTOCOLS);
  959. REGISTER_CURL_CONSTANT(CURLOPT_SOCKS5_GSSAPI_NEC);
  960. REGISTER_CURL_CONSTANT(CURLOPT_SOCKS5_GSSAPI_SERVICE);
  961. REGISTER_CURL_CONSTANT(CURLOPT_TFTP_BLKSIZE);
  962. REGISTER_CURL_CONSTANT(CURLPROTO_ALL);
  963. REGISTER_CURL_CONSTANT(CURLPROTO_DICT);
  964. REGISTER_CURL_CONSTANT(CURLPROTO_FILE);
  965. REGISTER_CURL_CONSTANT(CURLPROTO_FTP);
  966. REGISTER_CURL_CONSTANT(CURLPROTO_FTPS);
  967. REGISTER_CURL_CONSTANT(CURLPROTO_HTTP);
  968. REGISTER_CURL_CONSTANT(CURLPROTO_HTTPS);
  969. REGISTER_CURL_CONSTANT(CURLPROTO_LDAP);
  970. REGISTER_CURL_CONSTANT(CURLPROTO_LDAPS);
  971. REGISTER_CURL_CONSTANT(CURLPROTO_SCP);
  972. REGISTER_CURL_CONSTANT(CURLPROTO_SFTP);
  973. REGISTER_CURL_CONSTANT(CURLPROTO_TELNET);
  974. REGISTER_CURL_CONSTANT(CURLPROTO_TFTP);
  975. REGISTER_CURL_CONSTANT(CURLPROXY_HTTP_1_0);
  976. REGISTER_CURL_CONSTANT(CURLFTP_CREATE_DIR);
  977. REGISTER_CURL_CONSTANT(CURLFTP_CREATE_DIR_NONE);
  978. REGISTER_CURL_CONSTANT(CURLFTP_CREATE_DIR_RETRY);
  979. #endif
  980. #if LIBCURL_VERSION_NUM >= 0x071306 /* Available since 7.19.6 */
  981. REGISTER_CURL_CONSTANT(CURL_VERSION_CURLDEBUG);
  982. REGISTER_CURL_CONSTANT(CURLOPT_SSH_KNOWNHOSTS);
  983. #endif
  984. #if LIBCURL_VERSION_NUM >= 0x071400 /* Available since 7.20.0 */
  985. REGISTER_CURL_CONSTANT(CURLINFO_RTSP_CLIENT_CSEQ);
  986. REGISTER_CURL_CONSTANT(CURLINFO_RTSP_CSEQ_RECV);
  987. REGISTER_CURL_CONSTANT(CURLINFO_RTSP_SERVER_CSEQ);
  988. REGISTER_CURL_CONSTANT(CURLINFO_RTSP_SESSION_ID);
  989. REGISTER_CURL_CONSTANT(CURLOPT_FTP_USE_PRET);
  990. REGISTER_CURL_CONSTANT(CURLOPT_MAIL_FROM);
  991. REGISTER_CURL_CONSTANT(CURLOPT_MAIL_RCPT);
  992. REGISTER_CURL_CONSTANT(CURLOPT_RTSP_CLIENT_CSEQ);
  993. REGISTER_CURL_CONSTANT(CURLOPT_RTSP_REQUEST);
  994. REGISTER_CURL_CONSTANT(CURLOPT_RTSP_SERVER_CSEQ);
  995. REGISTER_CURL_CONSTANT(CURLOPT_RTSP_SESSION_ID);
  996. REGISTER_CURL_CONSTANT(CURLOPT_RTSP_STREAM_URI);
  997. REGISTER_CURL_CONSTANT(CURLOPT_RTSP_TRANSPORT);
  998. REGISTER_CURL_CONSTANT(CURLPROTO_IMAP);
  999. REGISTER_CURL_CONSTANT(CURLPROTO_IMAPS);
  1000. REGISTER_CURL_CONSTANT(CURLPROTO_POP3);
  1001. REGISTER_CURL_CONSTANT(CURLPROTO_POP3S);
  1002. REGISTER_CURL_CONSTANT(CURLPROTO_RTSP);
  1003. REGISTER_CURL_CONSTANT(CURLPROTO_SMTP);
  1004. REGISTER_CURL_CONSTANT(CURLPROTO_SMTPS);
  1005. REGISTER_CURL_CONSTANT(CURL_RTSPREQ_ANNOUNCE);
  1006. REGISTER_CURL_CONSTANT(CURL_RTSPREQ_DESCRIBE);
  1007. REGISTER_CURL_CONSTANT(CURL_RTSPREQ_GET_PARAMETER);
  1008. REGISTER_CURL_CONSTANT(CURL_RTSPREQ_OPTIONS);
  1009. REGISTER_CURL_CONSTANT(CURL_RTSPREQ_PAUSE);
  1010. REGISTER_CURL_CONSTANT(CURL_RTSPREQ_PLAY);
  1011. REGISTER_CURL_CONSTANT(CURL_RTSPREQ_RECEIVE);
  1012. REGISTER_CURL_CONSTANT(CURL_RTSPREQ_RECORD);
  1013. REGISTER_CURL_CONSTANT(CURL_RTSPREQ_SET_PARAMETER);
  1014. REGISTER_CURL_CONSTANT(CURL_RTSPREQ_SETUP);
  1015. REGISTER_CURL_CONSTANT(CURL_RTSPREQ_TEARDOWN);
  1016. #endif
  1017. #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
  1018. REGISTER_CURL_CONSTANT(CURLINFO_LOCAL_IP);
  1019. REGISTER_CURL_CONSTANT(CURLINFO_LOCAL_PORT);
  1020. REGISTER_CURL_CONSTANT(CURLINFO_PRIMARY_PORT);
  1021. REGISTER_CURL_CONSTANT(CURLOPT_FNMATCH_FUNCTION);
  1022. REGISTER_CURL_CONSTANT(CURLOPT_WILDCARDMATCH);
  1023. REGISTER_CURL_CONSTANT(CURLPROTO_RTMP);
  1024. REGISTER_CURL_CONSTANT(CURLPROTO_RTMPE);
  1025. REGISTER_CURL_CONSTANT(CURLPROTO_RTMPS);
  1026. REGISTER_CURL_CONSTANT(CURLPROTO_RTMPT);
  1027. REGISTER_CURL_CONSTANT(CURLPROTO_RTMPTE);
  1028. REGISTER_CURL_CONSTANT(CURLPROTO_RTMPTS);
  1029. REGISTER_CURL_CONSTANT(CURL_FNMATCHFUNC_FAIL);
  1030. REGISTER_CURL_CONSTANT(CURL_FNMATCHFUNC_MATCH);
  1031. REGISTER_CURL_CONSTANT(CURL_FNMATCHFUNC_NOMATCH);
  1032. #endif
  1033. #if LIBCURL_VERSION_NUM >= 0x071502 /* Available since 7.21.2 */
  1034. REGISTER_CURL_CONSTANT(CURLPROTO_GOPHER);
  1035. #endif
  1036. #if LIBCURL_VERSION_NUM >= 0x071503 /* Available since 7.21.3 */
  1037. REGISTER_CURL_CONSTANT(CURLAUTH_ONLY);
  1038. REGISTER_CURL_CONSTANT(CURLOPT_RESOLVE);
  1039. #endif
  1040. #if LIBCURL_VERSION_NUM >= 0x071504 /* Available since 7.21.4 */
  1041. REGISTER_CURL_CONSTANT(CURLOPT_TLSAUTH_PASSWORD);
  1042. REGISTER_CURL_CONSTANT(CURLOPT_TLSAUTH_TYPE);
  1043. REGISTER_CURL_CONSTANT(CURLOPT_TLSAUTH_USERNAME);
  1044. REGISTER_CURL_CONSTANT(CURL_TLSAUTH_SRP);
  1045. REGISTER_CURL_CONSTANT(CURL_VERSION_TLSAUTH_SRP);
  1046. #endif
  1047. #if LIBCURL_VERSION_NUM >= 0x071506 /* Available since 7.21.6 */
  1048. REGISTER_CURL_CONSTANT(CURLOPT_ACCEPT_ENCODING);
  1049. REGISTER_CURL_CONSTANT(CURLOPT_TRANSFER_ENCODING);
  1050. #endif
  1051. #if LIBCURL_VERSION_NUM >= 0x071600 /* Available since 7.22.0 */
  1052. REGISTER_CURL_CONSTANT(CURLAUTH_NTLM_WB);
  1053. REGISTER_CURL_CONSTANT(CURLGSSAPI_DELEGATION_FLAG);
  1054. REGISTER_CURL_CONSTANT(CURLGSSAPI_DELEGATION_POLICY_FLAG);
  1055. REGISTER_CURL_CONSTANT(CURLOPT_GSSAPI_DELEGATION);
  1056. REGISTER_CURL_CONSTANT(CURL_VERSION_NTLM_WB);
  1057. #endif
  1058. #if LIBCURL_VERSION_NUM >= 0x071800 /* Available since 7.24.0 */
  1059. REGISTER_CURL_CONSTANT(CURLOPT_ACCEPTTIMEOUT_MS);
  1060. REGISTER_CURL_CONSTANT(CURLOPT_DNS_SERVERS);
  1061. #endif
  1062. #if LIBCURL_VERSION_NUM >= 0x071900 /* Available since 7.25.0 */
  1063. REGISTER_CURL_CONSTANT(CURLOPT_MAIL_AUTH);
  1064. REGISTER_CURL_CONSTANT(CURLOPT_SSL_OPTIONS);
  1065. REGISTER_CURL_CONSTANT(CURLOPT_TCP_KEEPALIVE);
  1066. REGISTER_CURL_CONSTANT(CURLOPT_TCP_KEEPIDLE);
  1067. REGISTER_CURL_CONSTANT(CURLOPT_TCP_KEEPINTVL);
  1068. REGISTER_CURL_CONSTANT(CURLSSLOPT_ALLOW_BEAST);
  1069. #endif
  1070. #if LIBCURL_VERSION_NUM >= 0x071901 /* Available since 7.25.1 */
  1071. REGISTER_CURL_CONSTANT(CURL_REDIR_POST_303);
  1072. #endif
  1073. #if LIBCURL_VERSION_NUM >= 0x071c00 /* Available since 7.28.0 */
  1074. REGISTER_CURL_CONSTANT(CURLSSH_AUTH_AGENT);
  1075. #endif
  1076. #if LIBCURL_VERSION_NUM >= 0x071e00 /* Available since 7.30.0 */
  1077. REGISTER_CURL_CONSTANT(CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE);
  1078. REGISTER_CURL_CONSTANT(CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE);
  1079. REGISTER_CURL_CONSTANT(CURLMOPT_MAX_HOST_CONNECTIONS);
  1080. REGISTER_CURL_CONSTANT(CURLMOPT_MAX_PIPELINE_LENGTH);
  1081. REGISTER_CURL_CONSTANT(CURLMOPT_MAX_TOTAL_CONNECTIONS);
  1082. #endif
  1083. #if LIBCURL_VERSION_NUM >= 0x071f00 /* Available since 7.31.0 */
  1084. REGISTER_CURL_CONSTANT(CURLOPT_SASL_IR);
  1085. #endif
  1086. #if LIBCURL_VERSION_NUM >= 0x072100 /* Available since 7.33.0 */
  1087. REGISTER_CURL_CONSTANT(CURLOPT_DNS_INTERFACE);
  1088. REGISTER_CURL_CONSTANT(CURLOPT_DNS_LOCAL_IP4);
  1089. REGISTER_CURL_CONSTANT(CURLOPT_DNS_LOCAL_IP6);
  1090. REGISTER_CURL_CONSTANT(CURLOPT_XOAUTH2_BEARER);
  1091. REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_2_0);
  1092. REGISTER_CURL_CONSTANT(CURL_VERSION_HTTP2);
  1093. #endif
  1094. #if LIBCURL_VERSION_NUM >= 0x072200 /* Available since 7.34.0 */
  1095. REGISTER_CURL_CONSTANT(CURLOPT_LOGIN_OPTIONS);
  1096. REGISTER_CURL_CONSTANT(CURL_SSLVERSION_TLSv1_0);
  1097. REGISTER_CURL_CONSTANT(CURL_SSLVERSION_TLSv1_1);
  1098. REGISTER_CURL_CONSTANT(CURL_SSLVERSION_TLSv1_2);
  1099. #endif
  1100. #if LIBCURL_VERSION_NUM >= 0x072400 /* Available since 7.36.0 */
  1101. REGISTER_CURL_CONSTANT(CURLOPT_EXPECT_100_TIMEOUT_MS);
  1102. REGISTER_CURL_CONSTANT(CURLOPT_SSL_ENABLE_ALPN);
  1103. REGISTER_CURL_CONSTANT(CURLOPT_SSL_ENABLE_NPN);
  1104. #endif
  1105. #if LIBCURL_VERSION_NUM >= 0x072500 /* Available since 7.37.0 */
  1106. REGISTER_CURL_CONSTANT(CURLHEADER_SEPARATE);
  1107. REGISTER_CURL_CONSTANT(CURLHEADER_UNIFIED);
  1108. REGISTER_CURL_CONSTANT(CURLOPT_HEADEROPT);
  1109. REGISTER_CURL_CONSTANT(CURLOPT_PROXYHEADER);
  1110. #endif
  1111. #if LIBCURL_VERSION_NUM >= 0x072600 /* Available since 7.38.0 */
  1112. REGISTER_CURL_CONSTANT(CURLAUTH_NEGOTIATE);
  1113. REGISTER_CURL_CONSTANT(CURL_VERSION_GSSAPI);
  1114. #endif
  1115. #if LIBCURL_VERSION_NUM >= 0x072700 /* Available since 7.39.0 */
  1116. REGISTER_CURL_CONSTANT(CURLOPT_PINNEDPUBLICKEY);
  1117. #endif
  1118. #if LIBCURL_VERSION_NUM >= 0x072800 /* Available since 7.40.0 */
  1119. REGISTER_CURL_CONSTANT(CURLOPT_UNIX_SOCKET_PATH);
  1120. REGISTER_CURL_CONSTANT(CURLPROTO_SMB);
  1121. REGISTER_CURL_CONSTANT(CURLPROTO_SMBS);
  1122. REGISTER_CURL_CONSTANT(CURL_VERSION_KERBEROS5);
  1123. REGISTER_CURL_CONSTANT(CURL_VERSION_UNIX_SOCKETS);
  1124. #endif
  1125. #if LIBCURL_VERSION_NUM >= 0x072900 /* Available since 7.41.0 */
  1126. REGISTER_CURL_CONSTANT(CURLOPT_SSL_VERIFYSTATUS);
  1127. #endif
  1128. #if LIBCURL_VERSION_NUM >= 0x072a00 /* Available since 7.42.0 */
  1129. REGISTER_CURL_CONSTANT(CURLOPT_PATH_AS_IS);
  1130. REGISTER_CURL_CONSTANT(CURLOPT_SSL_FALSESTART);
  1131. #endif
  1132. #if LIBCURL_VERSION_NUM >= 0x072b00 /* Available since 7.43.0 */
  1133. REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_2);
  1134. REGISTER_CURL_CONSTANT(CURLOPT_PIPEWAIT);
  1135. REGISTER_CURL_CONSTANT(CURLOPT_PROXY_SERVICE_NAME);
  1136. REGISTER_CURL_CONSTANT(CURLOPT_SERVICE_NAME);
  1137. REGISTER_CURL_CONSTANT(CURLPIPE_NOTHING);
  1138. REGISTER_CURL_CONSTANT(CURLPIPE_HTTP1);
  1139. REGISTER_CURL_CONSTANT(CURLPIPE_MULTIPLEX);
  1140. #endif
  1141. #if LIBCURL_VERSION_NUM >= 0x072c00 /* Available since 7.44.0 */
  1142. REGISTER_CURL_CONSTANT(CURLSSLOPT_NO_REVOKE);
  1143. #endif
  1144. #if LIBCURL_VERSION_NUM >= 0x072d00 /* Available since 7.45.0 */
  1145. REGISTER_CURL_CONSTANT(CURLOPT_DEFAULT_PROTOCOL);
  1146. #endif
  1147. #if LIBCURL_VERSION_NUM >= 0x072e00 /* Available since 7.46.0 */
  1148. REGISTER_CURL_CONSTANT(CURLOPT_STREAM_WEIGHT);
  1149. REGISTER_CURL_CONSTANT(CURLMOPT_PUSHFUNCTION);
  1150. REGISTER_CURL_CONSTANT(CURL_PUSH_OK);
  1151. REGISTER_CURL_CONSTANT(CURL_PUSH_DENY);
  1152. #endif
  1153. #if LIBCURL_VERSION_NUM >= 0x072f00 /* Available since 7.47.0 */
  1154. REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_2TLS);
  1155. REGISTER_CURL_CONSTANT(CURL_VERSION_PSL);
  1156. #endif
  1157. #if LIBCURL_VERSION_NUM >= 0x073000 /* Available since 7.48.0 */
  1158. REGISTER_CURL_CONSTANT(CURLOPT_TFTP_NO_OPTIONS);
  1159. #endif
  1160. #if LIBCURL_VERSION_NUM >= 0x073100 /* Available since 7.49.0 */
  1161. REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE);
  1162. REGISTER_CURL_CONSTANT(CURLOPT_CONNECT_TO);
  1163. REGISTER_CURL_CONSTANT(CURLOPT_TCP_FASTOPEN);
  1164. #endif
  1165. #if LIBCURL_VERSION_NUM >= 0x073200 /* Available since 7.50.0 */
  1166. REGISTER_CURL_CONSTANT(CURLINFO_HTTP_VERSION);
  1167. #endif
  1168. #if LIBCURL_VERSION_NUM >= 0x073300 /* Available since 7.51.0 */
  1169. REGISTER_CURL_CONSTANT(CURLE_WEIRD_SERVER_REPLY);
  1170. REGISTER_CURL_CONSTANT(CURLOPT_KEEP_SENDING_ON_ERROR);
  1171. #endif
  1172. #if LIBCURL_VERSION_NUM >= 0x073400 /* Available since 7.52.0 */
  1173. REGISTER_CURL_CONSTANT(CURL_SSLVERSION_TLSv1_3);
  1174. REGISTER_CURL_CONSTANT(CURL_VERSION_HTTPS_PROXY);
  1175. REGISTER_CURL_CONSTANT(CURLINFO_PROTOCOL);
  1176. REGISTER_CURL_CONSTANT(CURLINFO_PROXY_SSL_VERIFYRESULT);
  1177. REGISTER_CURL_CONSTANT(CURLINFO_SCHEME);
  1178. REGISTER_CURL_CONSTANT(CURLOPT_PRE_PROXY);
  1179. REGISTER_CURL_CONSTANT(CURLOPT_PROXY_CAINFO);
  1180. REGISTER_CURL_CONSTANT(CURLOPT_PROXY_CAPATH);
  1181. REGISTER_CURL_CONSTANT(CURLOPT_PROXY_CRLFILE);
  1182. REGISTER_CURL_CONSTANT(CURLOPT_PROXY_KEYPASSWD);
  1183. REGISTER_CURL_CONSTANT(CURLOPT_PROXY_PINNEDPUBLICKEY);
  1184. REGISTER_CURL_CONSTANT(CURLOPT_PROXY_SSL_CIPHER_LIST);
  1185. REGISTER_CURL_CONSTANT(CURLOPT_PROXY_SSL_OPTIONS);
  1186. REGISTER_CURL_CONSTANT(CURLOPT_PROXY_SSL_VERIFYHOST);
  1187. REGISTER_CURL_CONSTANT(CURLOPT_PROXY_SSL_VERIFYPEER);
  1188. REGISTER_CURL_CONSTANT(CURLOPT_PROXY_SSLCERT);
  1189. REGISTER_CURL_CONSTANT(CURLOPT_PROXY_SSLCERTTYPE);
  1190. REGISTER_CURL_CONSTANT(CURLOPT_PROXY_SSLKEY);
  1191. REGISTER_CURL_CONSTANT(CURLOPT_PROXY_SSLKEYTYPE);
  1192. REGISTER_CURL_CONSTANT(CURLOPT_PROXY_SSLVERSION);
  1193. REGISTER_CURL_CONSTANT(CURLOPT_PROXY_TLSAUTH_PASSWORD);
  1194. REGISTER_CURL_CONSTANT(CURLOPT_PROXY_TLSAUTH_TYPE);
  1195. REGISTER_CURL_CONSTANT(CURLOPT_PROXY_TLSAUTH_USERNAME);
  1196. REGISTER_CURL_CONSTANT(CURLPROXY_HTTPS);
  1197. #endif
  1198. #if LIBCURL_VERSION_NUM >= 0x073500 /* Available since 7.53.0 */
  1199. REGISTER_CURL_CONSTANT(CURL_MAX_READ_SIZE);
  1200. REGISTER_CURL_CONSTANT(CURLOPT_ABSTRACT_UNIX_SOCKET);
  1201. #endif
  1202. #if LIBCURL_VERSION_NUM >= 0x073600 /* Available since 7.54.0 */
  1203. REGISTER_CURL_CONSTANT(CURL_SSLVERSION_MAX_DEFAULT);
  1204. REGISTER_CURL_CONSTANT(CURL_SSLVERSION_MAX_NONE);
  1205. REGISTER_CURL_CONSTANT(CURL_SSLVERSION_MAX_TLSv1_0);
  1206. REGISTER_CURL_CONSTANT(CURL_SSLVERSION_MAX_TLSv1_1);
  1207. REGISTER_CURL_CONSTANT(CURL_SSLVERSION_MAX_TLSv1_2);
  1208. REGISTER_CURL_CONSTANT(CURL_SSLVERSION_MAX_TLSv1_3);
  1209. REGISTER_CURL_CONSTANT(CURLOPT_SUPPRESS_CONNECT_HEADERS);
  1210. #endif
  1211. #if LIBCURL_VERSION_NUM >= 0x073601 /* Available since 7.54.1 */
  1212. REGISTER_CURL_CONSTANT(CURLAUTH_GSSAPI);
  1213. #endif
  1214. #if LIBCURL_VERSION_NUM >= 0x073700 /* Available since 7.55.0 */
  1215. REGISTER_CURL_CONSTANT(CURLINFO_CONTENT_LENGTH_DOWNLOAD_T);
  1216. REGISTER_CURL_CONSTANT(CURLINFO_CONTENT_LENGTH_UPLOAD_T);
  1217. REGISTER_CURL_CONSTANT(CURLINFO_SIZE_DOWNLOAD_T);
  1218. REGISTER_CURL_CONSTANT(CURLINFO_SIZE_UPLOAD_T);
  1219. REGISTER_CURL_CONSTANT(CURLINFO_SPEED_DOWNLOAD_T);
  1220. REGISTER_CURL_CONSTANT(CURLINFO_SPEED_UPLOAD_T);
  1221. REGISTER_CURL_CONSTANT(CURLOPT_REQUEST_TARGET);
  1222. REGISTER_CURL_CONSTANT(CURLOPT_SOCKS5_AUTH);
  1223. #endif
  1224. #if LIBCURL_VERSION_NUM >= 0x073800 /* Available since 7.56.0 */
  1225. REGISTER_CURL_CONSTANT(CURLOPT_SSH_COMPRESSION);
  1226. REGISTER_CURL_CONSTANT(CURL_VERSION_MULTI_SSL);
  1227. #endif
  1228. #if LIBCURL_VERSION_NUM >= 0x073900 /* Available since 7.57.0 */
  1229. REGISTER_CURL_CONSTANT(CURL_VERSION_BROTLI);
  1230. REGISTER_CURL_CONSTANT(CURL_LOCK_DATA_CONNECT);
  1231. #endif
  1232. #if LIBCURL_VERSION_NUM >= 0x073a00 /* Available since 7.58.0 */
  1233. REGISTER_CURL_CONSTANT(CURLSSH_AUTH_GSSAPI);
  1234. #endif
  1235. #if LIBCURL_VERSION_NUM >= 0x073b00 /* Available since 7.59.0 */
  1236. REGISTER_CURL_CONSTANT(CURLINFO_FILETIME_T);
  1237. REGISTER_CURL_CONSTANT(CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS);
  1238. REGISTER_CURL_CONSTANT(CURLOPT_TIMEVALUE_LARGE);
  1239. #endif
  1240. #if LIBCURL_VERSION_NUM >= 0x073c00 /* Available since 7.60.0 */
  1241. REGISTER_CURL_CONSTANT(CURLOPT_DNS_SHUFFLE_ADDRESSES);
  1242. REGISTER_CURL_CONSTANT(CURLOPT_HAPROXYPROTOCOL);
  1243. #endif
  1244. #if LIBCURL_VERSION_NUM >= 0x073d00 /* Available since 7.61.0 */
  1245. REGISTER_CURL_CONSTANT(CURL_LOCK_DATA_PSL);
  1246. REGISTER_CURL_CONSTANT(CURLAUTH_BEARER);
  1247. REGISTER_CURL_CONSTANT(CURLINFO_APPCONNECT_TIME_T);
  1248. REGISTER_CURL_CONSTANT(CURLINFO_CONNECT_TIME_T);
  1249. REGISTER_CURL_CONSTANT(CURLINFO_NAMELOOKUP_TIME_T);
  1250. REGISTER_CURL_CONSTANT(CURLINFO_PRETRANSFER_TIME_T);
  1251. REGISTER_CURL_CONSTANT(CURLINFO_REDIRECT_TIME_T);
  1252. REGISTER_CURL_CONSTANT(CURLINFO_STARTTRANSFER_TIME_T);
  1253. REGISTER_CURL_CONSTANT(CURLINFO_TOTAL_TIME_T);
  1254. REGISTER_CURL_CONSTANT(CURLOPT_DISALLOW_USERNAME_IN_URL);
  1255. REGISTER_CURL_CONSTANT(CURLOPT_PROXY_TLS13_CIPHERS);
  1256. REGISTER_CURL_CONSTANT(CURLOPT_TLS13_CIPHERS);
  1257. #endif
  1258. #if LIBCURL_VERSION_NUM >= 0x074000 /* Available since 7.64.0 */
  1259. REGISTER_CURL_CONSTANT(CURLOPT_HTTP09_ALLOWED);
  1260. #endif
  1261. #if LIBCURL_VERSION_NUM >= 0x074001 /* Available since 7.64.1 */
  1262. REGISTER_CURL_CONSTANT(CURL_VERSION_ALTSVC);
  1263. #endif
  1264. REGISTER_CURL_CONSTANT(CURLOPT_SAFE_UPLOAD);
  1265. #ifdef PHP_CURL_NEED_OPENSSL_TSL
  1266. if (!CRYPTO_get_id_callback()) {
  1267. int i, c = CRYPTO_num_locks();
  1268. php_curl_openssl_tsl = malloc(c * sizeof(MUTEX_T));
  1269. if (!php_curl_openssl_tsl) {
  1270. return FAILURE;
  1271. }
  1272. for (i = 0; i < c; ++i) {
  1273. php_curl_openssl_tsl[i] = tsrm_mutex_alloc();
  1274. }
  1275. CRYPTO_set_id_callback(php_curl_ssl_id);
  1276. CRYPTO_set_locking_callback(php_curl_ssl_lock);
  1277. }
  1278. #endif
  1279. #ifdef PHP_CURL_NEED_GNUTLS_TSL
  1280. gcry_control(GCRYCTL_SET_THREAD_CBS, &php_curl_gnutls_tsl);
  1281. #endif
  1282. if (curl_global_init(CURL_GLOBAL_DEFAULT) != CURLE_OK) {
  1283. return FAILURE;
  1284. }
  1285. curlfile_register_class();
  1286. return SUCCESS;
  1287. }
  1288. /* }}} */
  1289. /* {{{ PHP_MSHUTDOWN_FUNCTION
  1290. */
  1291. PHP_MSHUTDOWN_FUNCTION(curl)
  1292. {
  1293. curl_global_cleanup();
  1294. #ifdef PHP_CURL_NEED_OPENSSL_TSL
  1295. if (php_curl_openssl_tsl) {
  1296. int i, c = CRYPTO_num_locks();
  1297. CRYPTO_set_id_callback(NULL);
  1298. CRYPTO_set_locking_callback(NULL);
  1299. for (i = 0; i < c; ++i) {
  1300. tsrm_mutex_free(php_curl_openssl_tsl[i]);
  1301. }
  1302. free(php_curl_openssl_tsl);
  1303. php_curl_openssl_tsl = NULL;
  1304. }
  1305. #endif
  1306. UNREGISTER_INI_ENTRIES();
  1307. return SUCCESS;
  1308. }
  1309. /* }}} */
  1310. /* {{{ curl_write_nothing
  1311. * Used as a work around. See _php_curl_close_ex
  1312. */
  1313. static size_t curl_write_nothing(char *data, size_t size, size_t nmemb, void *ctx)
  1314. {
  1315. return size * nmemb;
  1316. }
  1317. /* }}} */
  1318. /* {{{ curl_write
  1319. */
  1320. static size_t curl_write(char *data, size_t size, size_t nmemb, void *ctx)
  1321. {
  1322. php_curl *ch = (php_curl *) ctx;
  1323. php_curl_write *t = ch->handlers->write;
  1324. size_t length = size * nmemb;
  1325. #if PHP_CURL_DEBUG
  1326. fprintf(stderr, "curl_write() called\n");
  1327. fprintf(stderr, "data = %s, size = %d, nmemb = %d, ctx = %x\n", data, size, nmemb, ctx);
  1328. #endif
  1329. switch (t->method) {
  1330. case PHP_CURL_STDOUT:
  1331. PHPWRITE(data, length);
  1332. break;
  1333. case PHP_CURL_FILE:
  1334. return fwrite(data, size, nmemb, t->fp);
  1335. case PHP_CURL_RETURN:
  1336. if (length > 0) {
  1337. smart_str_appendl(&t->buf, data, (int) length);
  1338. }
  1339. break;
  1340. case PHP_CURL_USER: {
  1341. zval argv[2];
  1342. zval retval;
  1343. int error;
  1344. zend_fcall_info fci;
  1345. GC_ADDREF(ch->res);
  1346. ZVAL_RES(&argv[0], ch->res);
  1347. ZVAL_STRINGL(&argv[1], data, length);
  1348. fci.size = sizeof(fci);
  1349. fci.object = NULL;
  1350. ZVAL_COPY_VALUE(&fci.function_name, &t->func_name);
  1351. fci.retval = &retval;
  1352. fci.param_count = 2;
  1353. fci.params = argv;
  1354. fci.no_separation = 0;
  1355. ch->in_callback = 1;
  1356. error = zend_call_function(&fci, &t->fci_cache);
  1357. ch->in_callback = 0;
  1358. if (error == FAILURE) {
  1359. php_error_docref(NULL, E_WARNING, "Could not call the CURLOPT_WRITEFUNCTION");
  1360. length = -1;
  1361. } else if (!Z_ISUNDEF(retval)) {
  1362. _php_curl_verify_handlers(ch, 1);
  1363. length = zval_get_long(&retval);
  1364. }
  1365. zval_ptr_dtor(&argv[0]);
  1366. zval_ptr_dtor(&argv[1]);
  1367. break;
  1368. }
  1369. }
  1370. return length;
  1371. }
  1372. /* }}} */
  1373. #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
  1374. /* {{{ curl_fnmatch
  1375. */
  1376. static int curl_fnmatch(void *ctx, const char *pattern, const char *string)
  1377. {
  1378. php_curl *ch = (php_curl *) ctx;
  1379. php_curl_fnmatch *t = ch->handlers->fnmatch;
  1380. int rval = CURL_FNMATCHFUNC_FAIL;
  1381. switch (t->method) {
  1382. case PHP_CURL_USER: {
  1383. zval argv[3];
  1384. zval retval;
  1385. int error;
  1386. zend_fcall_info fci;
  1387. GC_ADDREF(ch->res);
  1388. ZVAL_RES(&argv[0], ch->res);
  1389. ZVAL_STRING(&argv[1], pattern);
  1390. ZVAL_STRING(&argv[2], string);
  1391. fci.size = sizeof(fci);
  1392. ZVAL_COPY_VALUE(&fci.function_name, &t->func_name);
  1393. fci.object = NULL;
  1394. fci.retval = &retval;
  1395. fci.param_count = 3;
  1396. fci.params = argv;
  1397. fci.no_separation = 0;
  1398. ch->in_callback = 1;
  1399. error = zend_call_function(&fci, &t->fci_cache);
  1400. ch->in_callback = 0;
  1401. if (error == FAILURE) {
  1402. php_error_docref(NULL, E_WARNING, "Cannot call the CURLOPT_FNMATCH_FUNCTION");
  1403. } else if (!Z_ISUNDEF(retval)) {
  1404. _php_curl_verify_handlers(ch, 1);
  1405. rval = zval_get_long(&retval);
  1406. }
  1407. zval_ptr_dtor(&argv[0]);
  1408. zval_ptr_dtor(&argv[1]);
  1409. zval_ptr_dtor(&argv[2]);
  1410. break;
  1411. }
  1412. }
  1413. return rval;
  1414. }
  1415. /* }}} */
  1416. #endif
  1417. /* {{{ curl_progress
  1418. */
  1419. static size_t curl_progress(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
  1420. {
  1421. php_curl *ch = (php_curl *)clientp;
  1422. php_curl_progress *t = ch->handlers->progress;
  1423. size_t rval = 0;
  1424. #if PHP_CURL_DEBUG
  1425. fprintf(stderr, "curl_progress() called\n");
  1426. fprintf(stderr, "clientp = %x, dltotal = %f, dlnow = %f, ultotal = %f, ulnow = %f\n", clientp, dltotal, dlnow, ultotal, ulnow);
  1427. #endif
  1428. switch (t->method) {
  1429. case PHP_CURL_USER: {
  1430. zval argv[5];
  1431. zval retval;
  1432. int error;
  1433. zend_fcall_info fci;
  1434. GC_ADDREF(ch->res);
  1435. ZVAL_RES(&argv[0], ch->res);
  1436. ZVAL_LONG(&argv[1], (zend_long)dltotal);
  1437. ZVAL_LONG(&argv[2], (zend_long)dlnow);
  1438. ZVAL_LONG(&argv[3], (zend_long)ultotal);
  1439. ZVAL_LONG(&argv[4], (zend_long)ulnow);
  1440. fci.size = sizeof(fci);
  1441. ZVAL_COPY_VALUE(&fci.function_name, &t->func_name);
  1442. fci.object = NULL;
  1443. fci.retval = &retval;
  1444. fci.param_count = 5;
  1445. fci.params = argv;
  1446. fci.no_separation = 0;
  1447. ch->in_callback = 1;
  1448. error = zend_call_function(&fci, &t->fci_cache);
  1449. ch->in_callback = 0;
  1450. if (error == FAILURE) {
  1451. php_error_docref(NULL, E_WARNING, "Cannot call the CURLOPT_PROGRESSFUNCTION");
  1452. } else if (!Z_ISUNDEF(retval)) {
  1453. _php_curl_verify_handlers(ch, 1);
  1454. if (0 != zval_get_long(&retval)) {
  1455. rval = 1;
  1456. }
  1457. }
  1458. zval_ptr_dtor(&argv[0]);
  1459. break;
  1460. }
  1461. }
  1462. return rval;
  1463. }
  1464. /* }}} */
  1465. /* {{{ curl_read
  1466. */
  1467. static size_t curl_read(char *data, size_t size, size_t nmemb, void *ctx)
  1468. {
  1469. php_curl *ch = (php_curl *)ctx;
  1470. php_curl_read *t = ch->handlers->read;
  1471. int length = 0;
  1472. switch (t->method) {
  1473. case PHP_CURL_DIRECT:
  1474. if (t->fp) {
  1475. length = fread(data, size, nmemb, t->fp);
  1476. }
  1477. break;
  1478. case PHP_CURL_USER: {
  1479. zval argv[3];
  1480. zval retval;
  1481. int error;
  1482. zend_fcall_info fci;
  1483. GC_ADDREF(ch->res);
  1484. ZVAL_RES(&argv[0], ch->res);
  1485. if (t->res) {
  1486. GC_ADDREF(t->res);
  1487. ZVAL_RES(&argv[1], t->res);
  1488. } else {
  1489. ZVAL_NULL(&argv[1]);
  1490. }
  1491. ZVAL_LONG(&argv[2], (int)size * nmemb);
  1492. fci.size = sizeof(fci);
  1493. ZVAL_COPY_VALUE(&fci.function_name, &t->func_name);
  1494. fci.object = NULL;
  1495. fci.retval = &retval;
  1496. fci.param_count = 3;
  1497. fci.params = argv;
  1498. fci.no_separation = 0;
  1499. ch->in_callback = 1;
  1500. error = zend_call_function(&fci, &t->fci_cache);
  1501. ch->in_callback = 0;
  1502. if (error == FAILURE) {
  1503. php_error_docref(NULL, E_WARNING, "Cannot call the CURLOPT_READFUNCTION");
  1504. length = CURL_READFUNC_ABORT;
  1505. } else if (!Z_ISUNDEF(retval)) {
  1506. _php_curl_verify_handlers(ch, 1);
  1507. if (Z_TYPE(retval) == IS_STRING) {
  1508. length = MIN((int) (size * nmemb), Z_STRLEN(retval));
  1509. memcpy(data, Z_STRVAL(retval), length);
  1510. }
  1511. zval_ptr_dtor(&retval);
  1512. }
  1513. zval_ptr_dtor(&argv[0]);
  1514. zval_ptr_dtor(&argv[1]);
  1515. break;
  1516. }
  1517. }
  1518. return length;
  1519. }
  1520. /* }}} */
  1521. /* {{{ curl_write_header
  1522. */
  1523. static size_t curl_write_header(char *data, size_t size, size_t nmemb, void *ctx)
  1524. {
  1525. php_curl *ch = (php_curl *) ctx;
  1526. php_curl_write *t = ch->handlers->write_header;
  1527. size_t length = size * nmemb;
  1528. switch (t->method) {
  1529. case PHP_CURL_STDOUT:
  1530. /* Handle special case write when we're returning the entire transfer
  1531. */
  1532. if (ch->handlers->write->method == PHP_CURL_RETURN && length > 0) {
  1533. smart_str_appendl(&ch->handlers->write->buf, data, (int) length);
  1534. } else {
  1535. PHPWRITE(data, length);
  1536. }
  1537. break;
  1538. case PHP_CURL_FILE:
  1539. return fwrite(data, size, nmemb, t->fp);
  1540. case PHP_CURL_USER: {
  1541. zval argv[2];
  1542. zval retval;
  1543. int error;
  1544. zend_fcall_info fci;
  1545. GC_ADDREF(ch->res);
  1546. ZVAL_RES(&argv[0], ch->res);
  1547. ZVAL_STRINGL(&argv[1], data, length);
  1548. fci.size = sizeof(fci);
  1549. ZVAL_COPY_VALUE(&fci.function_name, &t->func_name);
  1550. fci.object = NULL;
  1551. fci.retval = &retval;
  1552. fci.param_count = 2;
  1553. fci.params = argv;
  1554. fci.no_separation = 0;
  1555. ch->in_callback = 1;
  1556. error = zend_call_function(&fci, &t->fci_cache);
  1557. ch->in_callback = 0;
  1558. if (error == FAILURE) {
  1559. php_error_docref(NULL, E_WARNING, "Could not call the CURLOPT_HEADERFUNCTION");
  1560. length = -1;
  1561. } else if (!Z_ISUNDEF(retval)) {
  1562. _php_curl_verify_handlers(ch, 1);
  1563. length = zval_get_long(&retval);
  1564. }
  1565. zval_ptr_dtor(&argv[0]);
  1566. zval_ptr_dtor(&argv[1]);
  1567. break;
  1568. }
  1569. case PHP_CURL_IGNORE:
  1570. return length;
  1571. default:
  1572. return -1;
  1573. }
  1574. return length;
  1575. }
  1576. /* }}} */
  1577. static int curl_debug(CURL *cp, curl_infotype type, char *buf, size_t buf_len, void *ctx) /* {{{ */
  1578. {
  1579. php_curl *ch = (php_curl *)ctx;
  1580. if (type == CURLINFO_HEADER_OUT) {
  1581. if (ch->header.str) {
  1582. zend_string_release_ex(ch->header.str, 0);
  1583. }
  1584. if (buf_len > 0) {
  1585. ch->header.str = zend_string_init(buf, buf_len, 0);
  1586. }
  1587. }
  1588. return 0;
  1589. }
  1590. /* }}} */
  1591. /* {{{ curl_free_string
  1592. */
  1593. static void curl_free_string(void **string)
  1594. {
  1595. efree((char *)*string);
  1596. }
  1597. /* }}} */
  1598. /* {{{ curl_free_post
  1599. */
  1600. static void curl_free_post(void **post)
  1601. {
  1602. #if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
  1603. curl_mime_free((curl_mime *)*post);
  1604. #else
  1605. curl_formfree((struct HttpPost *)*post);
  1606. #endif
  1607. }
  1608. /* }}} */
  1609. /* {{{ curl_free_slist
  1610. */
  1611. static void curl_free_slist(zval *el)
  1612. {
  1613. curl_slist_free_all(((struct curl_slist *)Z_PTR_P(el)));
  1614. }
  1615. /* }}} */
  1616. /* {{{ proto array curl_version([int version])
  1617. Return cURL version information. */
  1618. PHP_FUNCTION(curl_version)
  1619. {
  1620. curl_version_info_data *d;
  1621. zend_long uversion = CURLVERSION_NOW;
  1622. ZEND_PARSE_PARAMETERS_START(0, 1)
  1623. Z_PARAM_OPTIONAL
  1624. Z_PARAM_LONG(uversion)
  1625. ZEND_PARSE_PARAMETERS_END();
  1626. d = curl_version_info(uversion);
  1627. if (d == NULL) {
  1628. RETURN_FALSE;
  1629. }
  1630. array_init(return_value);
  1631. CAAL("version_number", d->version_num);
  1632. CAAL("age", d->age);
  1633. CAAL("features", d->features);
  1634. CAAL("ssl_version_number", d->ssl_version_num);
  1635. CAAS("version", d->version);
  1636. CAAS("host", d->host);
  1637. CAAS("ssl_version", d->ssl_version);
  1638. CAAS("libz_version", d->libz_version);
  1639. /* Add an array of protocols */
  1640. {
  1641. char **p = (char **) d->protocols;
  1642. zval protocol_list;
  1643. array_init(&protocol_list);
  1644. while (*p != NULL) {
  1645. add_next_index_string(&protocol_list, *p);
  1646. p++;
  1647. }
  1648. CAAZ("protocols", &protocol_list);
  1649. }
  1650. if (d->age >= 1) {
  1651. CAAS("ares", d->ares);
  1652. CAAL("ares_num", d->ares_num);
  1653. }
  1654. if (d->age >= 2) {
  1655. CAAS("libidn", d->libidn);
  1656. }
  1657. #if LIBCURL_VERSION_NUM >= 0x071001 /* Available since 7.16.1 */
  1658. if (d->age >= 3) {
  1659. CAAL("iconv_ver_num", d->iconv_ver_num);
  1660. CAAS("libssh_version", d->libssh_version);
  1661. }
  1662. #endif
  1663. #if LIBCURL_VERSION_NUM >= 0x073900 /* Available since 7.57.0 */
  1664. if (d->age >= 4) {
  1665. CAAL("brotli_ver_num", d->brotli_ver_num);
  1666. CAAS("brotli_version", d->brotli_version);
  1667. }
  1668. #endif
  1669. }
  1670. /* }}} */
  1671. /* {{{ alloc_curl_handle
  1672. */
  1673. php_curl *alloc_curl_handle()
  1674. {
  1675. php_curl *ch = ecalloc(1, sizeof(php_curl));
  1676. ch->to_free = ecalloc(1, sizeof(struct _php_curl_free));
  1677. ch->handlers = ecalloc(1, sizeof(php_curl_handlers));
  1678. ch->handlers->write = ecalloc(1, sizeof(php_curl_write));
  1679. ch->handlers->write_header = ecalloc(1, sizeof(php_curl_write));
  1680. ch->handlers->read = ecalloc(1, sizeof(php_curl_read));
  1681. ch->handlers->progress = NULL;
  1682. #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
  1683. ch->handlers->fnmatch = NULL;
  1684. #endif
  1685. ch->clone = emalloc(sizeof(uint32_t));
  1686. *ch->clone = 1;
  1687. memset(&ch->err, 0, sizeof(struct _php_curl_error));
  1688. zend_llist_init(&ch->to_free->str, sizeof(char *), (llist_dtor_func_t)curl_free_string, 0);
  1689. zend_llist_init(&ch->to_free->post, sizeof(struct HttpPost *), (llist_dtor_func_t)curl_free_post, 0);
  1690. ch->to_free->slist = emalloc(sizeof(HashTable));
  1691. zend_hash_init(ch->to_free->slist, 4, NULL, curl_free_slist, 0);
  1692. return ch;
  1693. }
  1694. /* }}} */
  1695. #if LIBCURL_VERSION_NUM >= 0x071301 /* Available since 7.19.1 */
  1696. /* {{{ create_certinfo
  1697. */
  1698. static void create_certinfo(struct curl_certinfo *ci, zval *listcode)
  1699. {
  1700. int i;
  1701. if (ci) {
  1702. zval certhash;
  1703. for (i=0; i<ci->num_of_certs; i++) {
  1704. struct curl_slist *slist;
  1705. array_init(&certhash);
  1706. for (slist = ci->certinfo[i]; slist; slist = slist->next) {
  1707. int len;
  1708. char s[64];
  1709. char *tmp;
  1710. strncpy(s, slist->data, sizeof(s));
  1711. s[sizeof(s)-1] = '\0';
  1712. tmp = memchr(s, ':', sizeof(s));
  1713. if(tmp) {
  1714. *tmp = '\0';
  1715. len = strlen(s);
  1716. add_assoc_string(&certhash, s, &slist->data[len+1]);
  1717. } else {
  1718. php_error_docref(NULL, E_WARNING, "Could not extract hash key from certificate info");
  1719. }
  1720. }
  1721. add_next_index_zval(listcode, &certhash);
  1722. }
  1723. }
  1724. }
  1725. /* }}} */
  1726. #endif
  1727. /* {{{ _php_curl_set_default_options()
  1728. Set default options for a handle */
  1729. static void _php_curl_set_default_options(php_curl *ch)
  1730. {
  1731. char *cainfo;
  1732. curl_easy_setopt(ch->cp, CURLOPT_NOPROGRESS, 1);
  1733. curl_easy_setopt(ch->cp, CURLOPT_VERBOSE, 0);
  1734. curl_easy_setopt(ch->cp, CURLOPT_ERRORBUFFER, ch->err.str);
  1735. curl_easy_setopt(ch->cp, CURLOPT_WRITEFUNCTION, curl_write);
  1736. curl_easy_setopt(ch->cp, CURLOPT_FILE, (void *) ch);
  1737. curl_easy_setopt(ch->cp, CURLOPT_READFUNCTION, curl_read);
  1738. curl_easy_setopt(ch->cp, CURLOPT_INFILE, (void *) ch);
  1739. curl_easy_setopt(ch->cp, CURLOPT_HEADERFUNCTION, curl_write_header);
  1740. curl_easy_setopt(ch->cp, CURLOPT_WRITEHEADER, (void *) ch);
  1741. #if !defined(ZTS)
  1742. curl_easy_setopt(ch->cp, CURLOPT_DNS_USE_GLOBAL_CACHE, 1);
  1743. #endif
  1744. curl_easy_setopt(ch->cp, CURLOPT_DNS_CACHE_TIMEOUT, 120);
  1745. curl_easy_setopt(ch->cp, CURLOPT_MAXREDIRS, 20); /* prevent infinite redirects */
  1746. cainfo = INI_STR("openssl.cafile");
  1747. if (!(cainfo && cainfo[0] != '\0')) {
  1748. cainfo = INI_STR("curl.cainfo");
  1749. }
  1750. if (cainfo && cainfo[0] != '\0') {
  1751. curl_easy_setopt(ch->cp, CURLOPT_CAINFO, cainfo);
  1752. }
  1753. #if defined(ZTS)
  1754. curl_easy_setopt(ch->cp, CURLOPT_NOSIGNAL, 1);
  1755. #endif
  1756. }
  1757. /* }}} */
  1758. /* {{{ proto resource curl_init([string url])
  1759. Initialize a cURL session */
  1760. PHP_FUNCTION(curl_init)
  1761. {
  1762. php_curl *ch;
  1763. CURL *cp;
  1764. zend_string *url = NULL;
  1765. ZEND_PARSE_PARAMETERS_START(0,1)
  1766. Z_PARAM_OPTIONAL
  1767. Z_PARAM_STR(url)
  1768. ZEND_PARSE_PARAMETERS_END();
  1769. cp = curl_easy_init();
  1770. if (!cp) {
  1771. php_error_docref(NULL, E_WARNING, "Could not initialize a new cURL handle");
  1772. RETURN_FALSE;
  1773. }
  1774. ch = alloc_curl_handle();
  1775. ch->cp = cp;
  1776. ch->handlers->write->method = PHP_CURL_STDOUT;
  1777. ch->handlers->read->method = PHP_CURL_DIRECT;
  1778. ch->handlers->write_header->method = PHP_CURL_IGNORE;
  1779. _php_curl_set_default_options(ch);
  1780. if (url) {
  1781. if (php_curl_option_url(ch, ZSTR_VAL(url), ZSTR_LEN(url)) == FAILURE) {
  1782. _php_curl_close_ex(ch);
  1783. RETURN_FALSE;
  1784. }
  1785. }
  1786. ZVAL_RES(return_value, zend_register_resource(ch, le_curl));
  1787. ch->res = Z_RES_P(return_value);
  1788. }
  1789. /* }}} */
  1790. void _php_setup_easy_copy_handlers(php_curl *ch, php_curl *source)
  1791. {
  1792. if (!Z_ISUNDEF(source->handlers->write->stream)) {
  1793. Z_ADDREF(source->handlers->write->stream);
  1794. }
  1795. ch->handlers->write->stream = source->handlers->write->stream;
  1796. ch->handlers->write->method = source->handlers->write->method;
  1797. if (!Z_ISUNDEF(source->handlers->read->stream)) {
  1798. Z_ADDREF(source->handlers->read->stream);
  1799. }
  1800. ch->handlers->read->stream = source->handlers->read->stream;
  1801. ch->handlers->read->method = source->handlers->read->method;
  1802. ch->handlers->write_header->method = source->handlers->write_header->method;
  1803. if (!Z_ISUNDEF(source->handlers->write_header->stream)) {
  1804. Z_ADDREF(source->handlers->write_header->stream);
  1805. }
  1806. ch->handlers->write_header->stream = source->handlers->write_header->stream;
  1807. ch->handlers->write->fp = source->handlers->write->fp;
  1808. ch->handlers->write_header->fp = source->handlers->write_header->fp;
  1809. ch->handlers->read->fp = source->handlers->read->fp;
  1810. ch->handlers->read->res = source->handlers->read->res;
  1811. #if CURLOPT_PASSWDDATA != 0
  1812. if (!Z_ISUNDEF(source->handlers->passwd)) {
  1813. ZVAL_COPY(&ch->handlers->passwd, &source->handlers->passwd);
  1814. curl_easy_setopt(source->cp, CURLOPT_PASSWDDATA, (void *) ch);
  1815. }
  1816. #endif
  1817. if (!Z_ISUNDEF(source->handlers->write->func_name)) {
  1818. ZVAL_COPY(&ch->handlers->write->func_name, &source->handlers->write->func_name);
  1819. }
  1820. if (!Z_ISUNDEF(source->handlers->read->func_name)) {
  1821. ZVAL_COPY(&ch->handlers->read->func_name, &source->handlers->read->func_name);
  1822. }
  1823. if (!Z_ISUNDEF(source->handlers->write_header->func_name)) {
  1824. ZVAL_COPY(&ch->handlers->write_header->func_name, &source->handlers->write_header->func_name);
  1825. }
  1826. curl_easy_setopt(ch->cp, CURLOPT_ERRORBUFFER, ch->err.str);
  1827. curl_easy_setopt(ch->cp, CURLOPT_FILE, (void *) ch);
  1828. curl_easy_setopt(ch->cp, CURLOPT_INFILE, (void *) ch);
  1829. curl_easy_setopt(ch->cp, CURLOPT_WRITEHEADER, (void *) ch);
  1830. if (source->handlers->progress) {
  1831. ch->handlers->progress = ecalloc(1, sizeof(php_curl_progress));
  1832. if (!Z_ISUNDEF(source->handlers->progress->func_name)) {
  1833. ZVAL_COPY(&ch->handlers->progress->func_name, &source->handlers->progress->func_name);
  1834. }
  1835. ch->handlers->progress->method = source->handlers->progress->method;
  1836. curl_easy_setopt(ch->cp, CURLOPT_PROGRESSDATA, (void *) ch);
  1837. }
  1838. #if LIBCURL_VERSION_NUM >= 0x071500
  1839. if (source->handlers->fnmatch) {
  1840. ch->handlers->fnmatch = ecalloc(1, sizeof(php_curl_fnmatch));
  1841. if (!Z_ISUNDEF(source->handlers->fnmatch->func_name)) {
  1842. ZVAL_COPY(&ch->handlers->fnmatch->func_name, &source->handlers->fnmatch->func_name);
  1843. }
  1844. ch->handlers->fnmatch->method = source->handlers->fnmatch->method;
  1845. curl_easy_setopt(ch->cp, CURLOPT_FNMATCH_DATA, (void *) ch);
  1846. }
  1847. #endif
  1848. efree(ch->to_free->slist);
  1849. efree(ch->to_free);
  1850. ch->to_free = source->to_free;
  1851. efree(ch->clone);
  1852. ch->clone = source->clone;
  1853. /* Keep track of cloned copies to avoid invoking curl destructors for every clone */
  1854. (*source->clone)++;
  1855. }
  1856. /* {{{ proto resource curl_copy_handle(resource ch)
  1857. Copy a cURL handle along with all of it's preferences */
  1858. PHP_FUNCTION(curl_copy_handle)
  1859. {
  1860. CURL *cp;
  1861. zval *zid;
  1862. php_curl *ch, *dupch;
  1863. ZEND_PARSE_PARAMETERS_START(1,1)
  1864. Z_PARAM_RESOURCE(zid)
  1865. ZEND_PARSE_PARAMETERS_END();
  1866. if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
  1867. RETURN_FALSE;
  1868. }
  1869. cp = curl_easy_duphandle(ch->cp);
  1870. if (!cp) {
  1871. php_error_docref(NULL, E_WARNING, "Cannot duplicate cURL handle");
  1872. RETURN_FALSE;
  1873. }
  1874. dupch = alloc_curl_handle();
  1875. dupch->cp = cp;
  1876. _php_setup_easy_copy_handlers(dupch, ch);
  1877. ZVAL_RES(return_value, zend_register_resource(dupch, le_curl));
  1878. dupch->res = Z_RES_P(return_value);
  1879. }
  1880. /* }}} */
  1881. static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{ */
  1882. {
  1883. CURLcode error = CURLE_OK;
  1884. zend_long lval;
  1885. switch (option) {
  1886. /* Long options */
  1887. case CURLOPT_SSL_VERIFYHOST:
  1888. lval = zval_get_long(zvalue);
  1889. if (lval == 1) {
  1890. #if LIBCURL_VERSION_NUM <= 0x071c00 /* 7.28.0 */
  1891. php_error_docref(NULL, E_NOTICE, "CURLOPT_SSL_VERIFYHOST with value 1 is deprecated and will be removed as of libcurl 7.28.1. It is recommended to use value 2 instead");
  1892. #else
  1893. php_error_docref(NULL, E_NOTICE, "CURLOPT_SSL_VERIFYHOST no longer accepts the value 1, value 2 will be used instead");
  1894. error = curl_easy_setopt(ch->cp, option, 2);
  1895. break;
  1896. #endif
  1897. }
  1898. case CURLOPT_AUTOREFERER:
  1899. case CURLOPT_BUFFERSIZE:
  1900. case CURLOPT_CONNECTTIMEOUT:
  1901. case CURLOPT_COOKIESESSION:
  1902. case CURLOPT_CRLF:
  1903. case CURLOPT_DNS_CACHE_TIMEOUT:
  1904. case CURLOPT_DNS_USE_GLOBAL_CACHE:
  1905. case CURLOPT_FAILONERROR:
  1906. case CURLOPT_FILETIME:
  1907. case CURLOPT_FORBID_REUSE:
  1908. case CURLOPT_FRESH_CONNECT:
  1909. case CURLOPT_FTP_USE_EPRT:
  1910. case CURLOPT_FTP_USE_EPSV:
  1911. case CURLOPT_HEADER:
  1912. case CURLOPT_HTTPGET:
  1913. case CURLOPT_HTTPPROXYTUNNEL:
  1914. case CURLOPT_HTTP_VERSION:
  1915. case CURLOPT_INFILESIZE:
  1916. case CURLOPT_LOW_SPEED_LIMIT:
  1917. case CURLOPT_LOW_SPEED_TIME:
  1918. case CURLOPT_MAXCONNECTS:
  1919. case CURLOPT_MAXREDIRS:
  1920. case CURLOPT_NETRC:
  1921. case CURLOPT_NOBODY:
  1922. case CURLOPT_NOPROGRESS:
  1923. case CURLOPT_NOSIGNAL:
  1924. case CURLOPT_PORT:
  1925. case CURLOPT_POST:
  1926. case CURLOPT_PROXYPORT:
  1927. case CURLOPT_PROXYTYPE:
  1928. case CURLOPT_PUT:
  1929. case CURLOPT_RESUME_FROM:
  1930. case CURLOPT_SSLVERSION:
  1931. case CURLOPT_SSL_VERIFYPEER:
  1932. case CURLOPT_TIMECONDITION:
  1933. case CURLOPT_TIMEOUT:
  1934. case CURLOPT_TIMEVALUE:
  1935. case CURLOPT_TRANSFERTEXT:
  1936. case CURLOPT_UNRESTRICTED_AUTH:
  1937. case CURLOPT_UPLOAD:
  1938. case CURLOPT_VERBOSE:
  1939. case CURLOPT_HTTPAUTH:
  1940. case CURLOPT_FTP_CREATE_MISSING_DIRS:
  1941. case CURLOPT_PROXYAUTH:
  1942. case CURLOPT_FTP_RESPONSE_TIMEOUT:
  1943. case CURLOPT_IPRESOLVE:
  1944. case CURLOPT_MAXFILESIZE:
  1945. case CURLOPT_TCP_NODELAY:
  1946. case CURLOPT_FTPSSLAUTH:
  1947. case CURLOPT_IGNORE_CONTENT_LENGTH:
  1948. case CURLOPT_FTP_SKIP_PASV_IP:
  1949. case CURLOPT_FTP_FILEMETHOD:
  1950. case CURLOPT_CONNECT_ONLY:
  1951. case CURLOPT_LOCALPORT:
  1952. case CURLOPT_LOCALPORTRANGE:
  1953. #if LIBCURL_VERSION_NUM >= 0x071000 /* Available since 7.16.0 */
  1954. case CURLOPT_SSL_SESSIONID_CACHE:
  1955. #endif
  1956. #if LIBCURL_VERSION_NUM >= 0x071001 /* Available since 7.16.1 */
  1957. case CURLOPT_FTP_SSL_CCC:
  1958. case CURLOPT_SSH_AUTH_TYPES:
  1959. #endif
  1960. #if LIBCURL_VERSION_NUM >= 0x071002 /* Available since 7.16.2 */
  1961. case CURLOPT_CONNECTTIMEOUT_MS:
  1962. case CURLOPT_HTTP_CONTENT_DECODING:
  1963. case CURLOPT_HTTP_TRANSFER_DECODING:
  1964. case CURLOPT_TIMEOUT_MS:
  1965. #endif
  1966. #if LIBCURL_VERSION_NUM >= 0x071004 /* Available since 7.16.4 */
  1967. case CURLOPT_NEW_DIRECTORY_PERMS:
  1968. case CURLOPT_NEW_FILE_PERMS:
  1969. #endif
  1970. #if LIBCURL_VERSION_NUM >= 0x071100 /* Available since 7.17.0 */
  1971. case CURLOPT_USE_SSL:
  1972. case CURLOPT_APPEND:
  1973. case CURLOPT_DIRLISTONLY:
  1974. #else
  1975. case CURLOPT_FTP_SSL:
  1976. case CURLOPT_FTPAPPEND:
  1977. case CURLOPT_FTPLISTONLY:
  1978. #endif
  1979. #if LIBCURL_VERSION_NUM >= 0x071200 /* Available since 7.18.0 */
  1980. case CURLOPT_PROXY_TRANSFER_MODE:
  1981. #endif
  1982. #if LIBCURL_VERSION_NUM >= 0x071300 /* Available since 7.19.0 */
  1983. case CURLOPT_ADDRESS_SCOPE:
  1984. #endif
  1985. #if LIBCURL_VERSION_NUM > 0x071301 /* Available since 7.19.1 */
  1986. case CURLOPT_CERTINFO:
  1987. #endif
  1988. #if LIBCURL_VERSION_NUM >= 0x071304 /* Available since 7.19.4 */
  1989. case CURLOPT_PROTOCOLS:
  1990. case CURLOPT_REDIR_PROTOCOLS:
  1991. case CURLOPT_SOCKS5_GSSAPI_NEC:
  1992. case CURLOPT_TFTP_BLKSIZE:
  1993. #endif
  1994. #if LIBCURL_VERSION_NUM >= 0x071400 /* Available since 7.20.0 */
  1995. case CURLOPT_FTP_USE_PRET:
  1996. case CURLOPT_RTSP_CLIENT_CSEQ:
  1997. case CURLOPT_RTSP_REQUEST:
  1998. case CURLOPT_RTSP_SERVER_CSEQ:
  1999. #endif
  2000. #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
  2001. case CURLOPT_WILDCARDMATCH:
  2002. #endif
  2003. #if LIBCURL_VERSION_NUM >= 0x071504 /* Available since 7.21.4 */
  2004. case CURLOPT_TLSAUTH_TYPE:
  2005. #endif
  2006. #if LIBCURL_VERSION_NUM >= 0x071600 /* Available since 7.22.0 */
  2007. case CURLOPT_GSSAPI_DELEGATION:
  2008. #endif
  2009. #if LIBCURL_VERSION_NUM >= 0x071800 /* Available since 7.24.0 */
  2010. case CURLOPT_ACCEPTTIMEOUT_MS:
  2011. #endif
  2012. #if LIBCURL_VERSION_NUM >= 0x071900 /* Available since 7.25.0 */
  2013. case CURLOPT_SSL_OPTIONS:
  2014. case CURLOPT_TCP_KEEPALIVE:
  2015. case CURLOPT_TCP_KEEPIDLE:
  2016. case CURLOPT_TCP_KEEPINTVL:
  2017. #endif
  2018. #if LIBCURL_VERSION_NUM >= 0x071f00 /* Available since 7.31.0 */
  2019. case CURLOPT_SASL_IR:
  2020. #endif
  2021. #if LIBCURL_VERSION_NUM >= 0x072400 /* Available since 7.36.0 */
  2022. case CURLOPT_EXPECT_100_TIMEOUT_MS:
  2023. case CURLOPT_SSL_ENABLE_ALPN:
  2024. case CURLOPT_SSL_ENABLE_NPN:
  2025. #endif
  2026. #if LIBCURL_VERSION_NUM >= 0x072500 /* Available since 7.37.0 */
  2027. case CURLOPT_HEADEROPT:
  2028. #endif
  2029. #if LIBCURL_VERSION_NUM >= 0x072900 /* Available since 7.41.0 */
  2030. case CURLOPT_SSL_VERIFYSTATUS:
  2031. #endif
  2032. #if LIBCURL_VERSION_NUM >= 0x072a00 /* Available since 7.42.0 */
  2033. case CURLOPT_PATH_AS_IS:
  2034. case CURLOPT_SSL_FALSESTART:
  2035. #endif
  2036. #if LIBCURL_VERSION_NUM >= 0x072b00 /* Available since 7.43.0 */
  2037. case CURLOPT_PIPEWAIT:
  2038. #endif
  2039. #if LIBCURL_VERSION_NUM >= 0x072e00 /* Available since 7.46.0 */
  2040. case CURLOPT_STREAM_WEIGHT:
  2041. #endif
  2042. #if LIBCURL_VERSION_NUM >= 0x073000 /* Available since 7.48.0 */
  2043. case CURLOPT_TFTP_NO_OPTIONS:
  2044. #endif
  2045. #if LIBCURL_VERSION_NUM >= 0x073100 /* Available since 7.49.0 */
  2046. case CURLOPT_TCP_FASTOPEN:
  2047. #endif
  2048. #if LIBCURL_VERSION_NUM >= 0x073300 /* Available since 7.51.0 */
  2049. case CURLOPT_KEEP_SENDING_ON_ERROR:
  2050. #endif
  2051. #if LIBCURL_VERSION_NUM >= 0x073400 /* Available since 7.52.0 */
  2052. case CURLOPT_PROXY_SSL_OPTIONS:
  2053. case CURLOPT_PROXY_SSL_VERIFYHOST:
  2054. case CURLOPT_PROXY_SSL_VERIFYPEER:
  2055. case CURLOPT_PROXY_SSLVERSION:
  2056. #endif
  2057. #if LIBCURL_VERSION_NUM >= 0x073600 /* Available since 7.54.0 */
  2058. case CURLOPT_SUPPRESS_CONNECT_HEADERS:
  2059. #endif
  2060. #if LIBCURL_VERSION_NUM >= 0x073700 /* Available since 7.55.0 */
  2061. case CURLOPT_SOCKS5_AUTH:
  2062. #endif
  2063. #if LIBCURL_VERSION_NUM >= 0x073800 /* Available since 7.56.0 */
  2064. case CURLOPT_SSH_COMPRESSION:
  2065. #endif
  2066. #if LIBCURL_VERSION_NUM >= 0x073b00 /* Available since 7.59.0 */
  2067. case CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS:
  2068. #endif
  2069. #if LIBCURL_VERSION_NUM >= 0x073c00 /* Available since 7.60.0 */
  2070. case CURLOPT_DNS_SHUFFLE_ADDRESSES:
  2071. case CURLOPT_HAPROXYPROTOCOL:
  2072. #endif
  2073. #if LIBCURL_VERSION_NUM >= 0x073d00 /* Available since 7.61.0 */
  2074. case CURLOPT_DISALLOW_USERNAME_IN_URL:
  2075. #endif
  2076. #if LIBCURL_VERSION_NUM >= 0x074000 /* Available since 7.64.0 */
  2077. case CURLOPT_HTTP09_ALLOWED:
  2078. #endif
  2079. lval = zval_get_long(zvalue);
  2080. #if LIBCURL_VERSION_NUM >= 0x071304
  2081. if ((option == CURLOPT_PROTOCOLS || option == CURLOPT_REDIR_PROTOCOLS) &&
  2082. (PG(open_basedir) && *PG(open_basedir)) && (lval & CURLPROTO_FILE)) {
  2083. php_error_docref(NULL, E_WARNING, "CURLPROTO_FILE cannot be activated when an open_basedir is set");
  2084. return 1;
  2085. }
  2086. #endif
  2087. # if defined(ZTS)
  2088. if (option == CURLOPT_DNS_USE_GLOBAL_CACHE && lval) {
  2089. php_error_docref(NULL, E_WARNING, "CURLOPT_DNS_USE_GLOBAL_CACHE cannot be activated when thread safety is enabled");
  2090. return 1;
  2091. }
  2092. # endif
  2093. error = curl_easy_setopt(ch->cp, option, lval);
  2094. break;
  2095. case CURLOPT_SAFE_UPLOAD:
  2096. if (!zend_is_true(zvalue)) {
  2097. php_error_docref(NULL, E_WARNING, "Disabling safe uploads is no longer supported");
  2098. return FAILURE;
  2099. }
  2100. break;
  2101. /* String options */
  2102. case CURLOPT_CAINFO:
  2103. case CURLOPT_CAPATH:
  2104. case CURLOPT_COOKIE:
  2105. case CURLOPT_EGDSOCKET:
  2106. case CURLOPT_INTERFACE:
  2107. case CURLOPT_PROXY:
  2108. case CURLOPT_PROXYUSERPWD:
  2109. case CURLOPT_REFERER:
  2110. case CURLOPT_SSLCERTTYPE:
  2111. case CURLOPT_SSLENGINE:
  2112. case CURLOPT_SSLENGINE_DEFAULT:
  2113. case CURLOPT_SSLKEY:
  2114. case CURLOPT_SSLKEYPASSWD:
  2115. case CURLOPT_SSLKEYTYPE:
  2116. case CURLOPT_SSL_CIPHER_LIST:
  2117. case CURLOPT_USERAGENT:
  2118. case CURLOPT_USERPWD:
  2119. case CURLOPT_COOKIELIST:
  2120. case CURLOPT_FTP_ALTERNATIVE_TO_USER:
  2121. #if LIBCURL_VERSION_NUM >= 0x071101 /* Available since 7.17.1 */
  2122. case CURLOPT_SSH_HOST_PUBLIC_KEY_MD5:
  2123. #endif
  2124. #if LIBCURL_VERSION_NUM >= 0x071301 /* Available since 7.19.1 */
  2125. case CURLOPT_PASSWORD:
  2126. case CURLOPT_PROXYPASSWORD:
  2127. case CURLOPT_PROXYUSERNAME:
  2128. case CURLOPT_USERNAME:
  2129. #endif
  2130. #if LIBCURL_VERSION_NUM >= 0x071304 /* Available since 7.19.4 */
  2131. case CURLOPT_NOPROXY:
  2132. case CURLOPT_SOCKS5_GSSAPI_SERVICE:
  2133. #endif
  2134. #if LIBCURL_VERSION_NUM >= 0x071400 /* Available since 7.20.0 */
  2135. case CURLOPT_MAIL_FROM:
  2136. case CURLOPT_RTSP_STREAM_URI:
  2137. case CURLOPT_RTSP_TRANSPORT:
  2138. #endif
  2139. #if LIBCURL_VERSION_NUM >= 0x071504 /* Available since 7.21.4 */
  2140. case CURLOPT_TLSAUTH_PASSWORD:
  2141. case CURLOPT_TLSAUTH_USERNAME:
  2142. #endif
  2143. #if LIBCURL_VERSION_NUM >= 0x071506 /* Available since 7.21.6 */
  2144. case CURLOPT_ACCEPT_ENCODING:
  2145. case CURLOPT_TRANSFER_ENCODING:
  2146. #else
  2147. case CURLOPT_ENCODING:
  2148. #endif
  2149. #if LIBCURL_VERSION_NUM >= 0x071800 /* Available since 7.24.0 */
  2150. case CURLOPT_DNS_SERVERS:
  2151. #endif
  2152. #if LIBCURL_VERSION_NUM >= 0x071900 /* Available since 7.25.0 */
  2153. case CURLOPT_MAIL_AUTH:
  2154. #endif
  2155. #if LIBCURL_VERSION_NUM >= 0x072200 /* Available since 7.34.0 */
  2156. case CURLOPT_LOGIN_OPTIONS:
  2157. #endif
  2158. #if LIBCURL_VERSION_NUM >= 0x072700 /* Available since 7.39.0 */
  2159. case CURLOPT_PINNEDPUBLICKEY:
  2160. #endif
  2161. #if LIBCURL_VERSION_NUM >= 0x072b00 /* Available since 7.43.0 */
  2162. case CURLOPT_PROXY_SERVICE_NAME:
  2163. case CURLOPT_SERVICE_NAME:
  2164. #endif
  2165. #if LIBCURL_VERSION_NUM >= 0x072d00 /* Available since 7.45.0 */
  2166. case CURLOPT_DEFAULT_PROTOCOL:
  2167. #endif
  2168. #if LIBCURL_VERSION_NUM >= 0x073400 /* Available since 7.52.0 */
  2169. case CURLOPT_PRE_PROXY:
  2170. case CURLOPT_PROXY_CAINFO:
  2171. case CURLOPT_PROXY_CAPATH:
  2172. case CURLOPT_PROXY_CRLFILE:
  2173. case CURLOPT_PROXY_KEYPASSWD:
  2174. case CURLOPT_PROXY_PINNEDPUBLICKEY:
  2175. case CURLOPT_PROXY_SSL_CIPHER_LIST:
  2176. case CURLOPT_PROXY_SSLCERT:
  2177. case CURLOPT_PROXY_SSLCERTTYPE:
  2178. case CURLOPT_PROXY_SSLKEY:
  2179. case CURLOPT_PROXY_SSLKEYTYPE:
  2180. case CURLOPT_PROXY_TLSAUTH_PASSWORD:
  2181. case CURLOPT_PROXY_TLSAUTH_TYPE:
  2182. case CURLOPT_PROXY_TLSAUTH_USERNAME:
  2183. #endif
  2184. #if LIBCURL_VERSION_NUM >= 0x073500 /* Available since 7.53.0 */
  2185. case CURLOPT_ABSTRACT_UNIX_SOCKET:
  2186. #endif
  2187. #if LIBCURL_VERSION_NUM >= 0x073700 /* Available since 7.55.0 */
  2188. case CURLOPT_REQUEST_TARGET:
  2189. #endif
  2190. #if LIBCURL_VERSION_NUM >= 0x073d00 /* Available since 7.61.0 */
  2191. case CURLOPT_PROXY_TLS13_CIPHERS:
  2192. case CURLOPT_TLS13_CIPHERS:
  2193. #endif
  2194. {
  2195. zend_string *tmp_str;
  2196. zend_string *str = zval_get_tmp_string(zvalue, &tmp_str);
  2197. int ret = php_curl_option_str(ch, option, ZSTR_VAL(str), ZSTR_LEN(str), 0);
  2198. zend_tmp_string_release(tmp_str);
  2199. return ret;
  2200. }
  2201. /* Curl nullable string options */
  2202. case CURLOPT_CUSTOMREQUEST:
  2203. case CURLOPT_FTPPORT:
  2204. case CURLOPT_RANGE:
  2205. case CURLOPT_FTP_ACCOUNT:
  2206. #if LIBCURL_VERSION_NUM >= 0x071400 /* Available since 7.20.0 */
  2207. case CURLOPT_RTSP_SESSION_ID:
  2208. #endif
  2209. #if LIBCURL_VERSION_NUM >= 0x072100 /* Available since 7.33.0 */
  2210. case CURLOPT_DNS_INTERFACE:
  2211. case CURLOPT_DNS_LOCAL_IP4:
  2212. case CURLOPT_DNS_LOCAL_IP6:
  2213. case CURLOPT_XOAUTH2_BEARER:
  2214. #endif
  2215. #if LIBCURL_VERSION_NUM >= 0x072800 /* Available since 7.40.0 */
  2216. case CURLOPT_UNIX_SOCKET_PATH:
  2217. #endif
  2218. #if LIBCURL_VERSION_NUM >= 0x071004 /* Available since 7.16.4 */
  2219. case CURLOPT_KRBLEVEL:
  2220. #else
  2221. case CURLOPT_KRB4LEVEL:
  2222. #endif
  2223. {
  2224. if (Z_ISNULL_P(zvalue)) {
  2225. error = curl_easy_setopt(ch->cp, option, NULL);
  2226. } else {
  2227. zend_string *tmp_str;
  2228. zend_string *str = zval_get_tmp_string(zvalue, &tmp_str);
  2229. int ret = php_curl_option_str(ch, option, ZSTR_VAL(str), ZSTR_LEN(str), 0);
  2230. zend_tmp_string_release(tmp_str);
  2231. return ret;
  2232. }
  2233. break;
  2234. }
  2235. /* Curl private option */
  2236. case CURLOPT_PRIVATE:
  2237. {
  2238. zend_string *tmp_str;
  2239. zend_string *str = zval_get_tmp_string(zvalue, &tmp_str);
  2240. int ret = php_curl_option_str(ch, option, ZSTR_VAL(str), ZSTR_LEN(str), 1);
  2241. zend_tmp_string_release(tmp_str);
  2242. return ret;
  2243. }
  2244. /* Curl url option */
  2245. case CURLOPT_URL:
  2246. {
  2247. zend_string *tmp_str;
  2248. zend_string *str = zval_get_tmp_string(zvalue, &tmp_str);
  2249. int ret = php_curl_option_url(ch, ZSTR_VAL(str), ZSTR_LEN(str));
  2250. zend_tmp_string_release(tmp_str);
  2251. return ret;
  2252. }
  2253. /* Curl file handle options */
  2254. case CURLOPT_FILE:
  2255. case CURLOPT_INFILE:
  2256. case CURLOPT_STDERR:
  2257. case CURLOPT_WRITEHEADER: {
  2258. FILE *fp = NULL;
  2259. php_stream *what = NULL;
  2260. if (Z_TYPE_P(zvalue) != IS_NULL) {
  2261. what = (php_stream *)zend_fetch_resource2_ex(zvalue, "File-Handle", php_file_le_stream(), php_file_le_pstream());
  2262. if (!what) {
  2263. return FAILURE;
  2264. }
  2265. if (FAILURE == php_stream_cast(what, PHP_STREAM_AS_STDIO, (void *) &fp, REPORT_ERRORS)) {
  2266. return FAILURE;
  2267. }
  2268. if (!fp) {
  2269. return FAILURE;
  2270. }
  2271. }
  2272. error = CURLE_OK;
  2273. switch (option) {
  2274. case CURLOPT_FILE:
  2275. if (!what) {
  2276. if (!Z_ISUNDEF(ch->handlers->write->stream)) {
  2277. zval_ptr_dtor(&ch->handlers->write->stream);
  2278. ZVAL_UNDEF(&ch->handlers->write->stream);
  2279. }
  2280. ch->handlers->write->fp = NULL;
  2281. ch->handlers->write->method = PHP_CURL_STDOUT;
  2282. } else if (what->mode[0] != 'r' || what->mode[1] == '+') {
  2283. zval_ptr_dtor(&ch->handlers->write->stream);
  2284. ch->handlers->write->fp = fp;
  2285. ch->handlers->write->method = PHP_CURL_FILE;
  2286. ZVAL_COPY(&ch->handlers->write->stream, zvalue);
  2287. } else {
  2288. php_error_docref(NULL, E_WARNING, "the provided file handle is not writable");
  2289. return FAILURE;
  2290. }
  2291. break;
  2292. case CURLOPT_WRITEHEADER:
  2293. if (!what) {
  2294. if (!Z_ISUNDEF(ch->handlers->write_header->stream)) {
  2295. zval_ptr_dtor(&ch->handlers->write_header->stream);
  2296. ZVAL_UNDEF(&ch->handlers->write_header->stream);
  2297. }
  2298. ch->handlers->write_header->fp = NULL;
  2299. ch->handlers->write_header->method = PHP_CURL_IGNORE;
  2300. } else if (what->mode[0] != 'r' || what->mode[1] == '+') {
  2301. zval_ptr_dtor(&ch->handlers->write_header->stream);
  2302. ch->handlers->write_header->fp = fp;
  2303. ch->handlers->write_header->method = PHP_CURL_FILE;
  2304. ZVAL_COPY(&ch->handlers->write_header->stream, zvalue);
  2305. } else {
  2306. php_error_docref(NULL, E_WARNING, "the provided file handle is not writable");
  2307. return FAILURE;
  2308. }
  2309. break;
  2310. case CURLOPT_INFILE:
  2311. if (!what) {
  2312. if (!Z_ISUNDEF(ch->handlers->read->stream)) {
  2313. zval_ptr_dtor(&ch->handlers->read->stream);
  2314. ZVAL_UNDEF(&ch->handlers->read->stream);
  2315. }
  2316. ch->handlers->read->fp = NULL;
  2317. ch->handlers->read->res = NULL;
  2318. } else {
  2319. zval_ptr_dtor(&ch->handlers->read->stream);
  2320. ch->handlers->read->fp = fp;
  2321. ch->handlers->read->res = Z_RES_P(zvalue);
  2322. ZVAL_COPY(&ch->handlers->read->stream, zvalue);
  2323. }
  2324. break;
  2325. case CURLOPT_STDERR:
  2326. if (!what) {
  2327. if (!Z_ISUNDEF(ch->handlers->std_err)) {
  2328. zval_ptr_dtor(&ch->handlers->std_err);
  2329. ZVAL_UNDEF(&ch->handlers->std_err);
  2330. }
  2331. } else if (what->mode[0] != 'r' || what->mode[1] == '+') {
  2332. zval_ptr_dtor(&ch->handlers->std_err);
  2333. ZVAL_COPY(&ch->handlers->std_err, zvalue);
  2334. } else {
  2335. php_error_docref(NULL, E_WARNING, "the provided file handle is not writable");
  2336. return FAILURE;
  2337. }
  2338. /* break omitted intentionally */
  2339. default:
  2340. error = curl_easy_setopt(ch->cp, option, fp);
  2341. break;
  2342. }
  2343. break;
  2344. }
  2345. /* Curl linked list options */
  2346. case CURLOPT_HTTP200ALIASES:
  2347. case CURLOPT_HTTPHEADER:
  2348. case CURLOPT_POSTQUOTE:
  2349. case CURLOPT_PREQUOTE:
  2350. case CURLOPT_QUOTE:
  2351. case CURLOPT_TELNETOPTIONS:
  2352. #if LIBCURL_VERSION_NUM >= 0x071400 /* Available since 7.20.0 */
  2353. case CURLOPT_MAIL_RCPT:
  2354. #endif
  2355. #if LIBCURL_VERSION_NUM >= 0x071503 /* Available since 7.21.3 */
  2356. case CURLOPT_RESOLVE:
  2357. #endif
  2358. #if LIBCURL_VERSION_NUM >= 0x072500 /* Available since 7.37.0 */
  2359. case CURLOPT_PROXYHEADER:
  2360. #endif
  2361. #if LIBCURL_VERSION_NUM >= 0x073100 /* Available since 7.49.0 */
  2362. case CURLOPT_CONNECT_TO:
  2363. #endif
  2364. {
  2365. zval *current;
  2366. HashTable *ph;
  2367. zend_string *val, *tmp_val;
  2368. struct curl_slist *slist = NULL;
  2369. ph = HASH_OF(zvalue);
  2370. if (!ph) {
  2371. char *name = NULL;
  2372. switch (option) {
  2373. case CURLOPT_HTTPHEADER:
  2374. name = "CURLOPT_HTTPHEADER";
  2375. break;
  2376. case CURLOPT_QUOTE:
  2377. name = "CURLOPT_QUOTE";
  2378. break;
  2379. case CURLOPT_HTTP200ALIASES:
  2380. name = "CURLOPT_HTTP200ALIASES";
  2381. break;
  2382. case CURLOPT_POSTQUOTE:
  2383. name = "CURLOPT_POSTQUOTE";
  2384. break;
  2385. case CURLOPT_PREQUOTE:
  2386. name = "CURLOPT_PREQUOTE";
  2387. break;
  2388. case CURLOPT_TELNETOPTIONS:
  2389. name = "CURLOPT_TELNETOPTIONS";
  2390. break;
  2391. #if LIBCURL_VERSION_NUM >= 0x071400 /* Available since 7.20.0 */
  2392. case CURLOPT_MAIL_RCPT:
  2393. name = "CURLOPT_MAIL_RCPT";
  2394. break;
  2395. #endif
  2396. #if LIBCURL_VERSION_NUM >= 0x071503 /* Available since 7.21.3 */
  2397. case CURLOPT_RESOLVE:
  2398. name = "CURLOPT_RESOLVE";
  2399. break;
  2400. #endif
  2401. #if LIBCURL_VERSION_NUM >= 0x072500 /* Available since 7.37.0 */
  2402. case CURLOPT_PROXYHEADER:
  2403. name = "CURLOPT_PROXYHEADER";
  2404. break;
  2405. #endif
  2406. #if LIBCURL_VERSION_NUM >= 0x073100 /* Available since 7.49.0 */
  2407. case CURLOPT_CONNECT_TO:
  2408. name = "CURLOPT_CONNECT_TO";
  2409. break;
  2410. #endif
  2411. }
  2412. php_error_docref(NULL, E_WARNING, "You must pass either an object or an array with the %s argument", name);
  2413. return FAILURE;
  2414. }
  2415. ZEND_HASH_FOREACH_VAL_IND(ph, current) {
  2416. ZVAL_DEREF(current);
  2417. val = zval_get_tmp_string(current, &tmp_val);
  2418. slist = curl_slist_append(slist, ZSTR_VAL(val));
  2419. zend_tmp_string_release(tmp_val);
  2420. if (!slist) {
  2421. php_error_docref(NULL, E_WARNING, "Could not build curl_slist");
  2422. return 1;
  2423. }
  2424. } ZEND_HASH_FOREACH_END();
  2425. if (slist) {
  2426. if ((*ch->clone) == 1) {
  2427. zend_hash_index_update_ptr(ch->to_free->slist, option, slist);
  2428. } else {
  2429. zend_hash_next_index_insert_ptr(ch->to_free->slist, slist);
  2430. }
  2431. }
  2432. error = curl_easy_setopt(ch->cp, option, slist);
  2433. break;
  2434. }
  2435. case CURLOPT_BINARYTRANSFER:
  2436. /* Do nothing, just backward compatibility */
  2437. break;
  2438. case CURLOPT_FOLLOWLOCATION:
  2439. lval = zend_is_true(zvalue);
  2440. #if LIBCURL_VERSION_NUM < 0x071304
  2441. if (lval && PG(open_basedir) && *PG(open_basedir)) {
  2442. php_error_docref(NULL, E_WARNING, "CURLOPT_FOLLOWLOCATION cannot be activated when an open_basedir is set");
  2443. return FAILURE;
  2444. }
  2445. #endif
  2446. error = curl_easy_setopt(ch->cp, option, lval);
  2447. break;
  2448. case CURLOPT_HEADERFUNCTION:
  2449. if (!Z_ISUNDEF(ch->handlers->write_header->func_name)) {
  2450. zval_ptr_dtor(&ch->handlers->write_header->func_name);
  2451. ch->handlers->write_header->fci_cache = empty_fcall_info_cache;
  2452. }
  2453. ZVAL_COPY(&ch->handlers->write_header->func_name, zvalue);
  2454. ch->handlers->write_header->method = PHP_CURL_USER;
  2455. break;
  2456. case CURLOPT_POSTFIELDS:
  2457. if (Z_TYPE_P(zvalue) == IS_ARRAY || Z_TYPE_P(zvalue) == IS_OBJECT) {
  2458. zval *current;
  2459. HashTable *postfields;
  2460. zend_string *string_key;
  2461. zend_ulong num_key;
  2462. #if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
  2463. curl_mime *mime = NULL;
  2464. curl_mimepart *part;
  2465. CURLcode form_error;
  2466. #else
  2467. struct HttpPost *first = NULL;
  2468. struct HttpPost *last = NULL;
  2469. CURLFORMcode form_error;
  2470. #endif
  2471. postfields = HASH_OF(zvalue);
  2472. if (!postfields) {
  2473. php_error_docref(NULL, E_WARNING, "Couldn't get HashTable in CURLOPT_POSTFIELDS");
  2474. return FAILURE;
  2475. }
  2476. #if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
  2477. if (zend_hash_num_elements(postfields) > 0) {
  2478. mime = curl_mime_init(ch->cp);
  2479. if (mime == NULL) {
  2480. return FAILURE;
  2481. }
  2482. }
  2483. #endif
  2484. ZEND_HASH_FOREACH_KEY_VAL_IND(postfields, num_key, string_key, current) {
  2485. zend_string *postval, *tmp_postval;
  2486. /* Pretend we have a string_key here */
  2487. if (!string_key) {
  2488. string_key = zend_long_to_str(num_key);
  2489. } else {
  2490. zend_string_addref(string_key);
  2491. }
  2492. ZVAL_DEREF(current);
  2493. if (Z_TYPE_P(current) == IS_OBJECT &&
  2494. instanceof_function(Z_OBJCE_P(current), curl_CURLFile_class)) {
  2495. /* new-style file upload */
  2496. zval *prop, rv;
  2497. char *type = NULL, *filename = NULL;
  2498. prop = zend_read_property(curl_CURLFile_class, current, "name", sizeof("name")-1, 0, &rv);
  2499. if (Z_TYPE_P(prop) != IS_STRING) {
  2500. php_error_docref(NULL, E_WARNING, "Invalid filename for key %s", ZSTR_VAL(string_key));
  2501. } else {
  2502. postval = Z_STR_P(prop);
  2503. if (php_check_open_basedir(ZSTR_VAL(postval))) {
  2504. return 1;
  2505. }
  2506. prop = zend_read_property(curl_CURLFile_class, current, "mime", sizeof("mime")-1, 0, &rv);
  2507. if (Z_TYPE_P(prop) == IS_STRING && Z_STRLEN_P(prop) > 0) {
  2508. type = Z_STRVAL_P(prop);
  2509. }
  2510. prop = zend_read_property(curl_CURLFile_class, current, "postname", sizeof("postname")-1, 0, &rv);
  2511. if (Z_TYPE_P(prop) == IS_STRING && Z_STRLEN_P(prop) > 0) {
  2512. filename = Z_STRVAL_P(prop);
  2513. }
  2514. #if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
  2515. part = curl_mime_addpart(mime);
  2516. if (part == NULL) {
  2517. zend_string_release_ex(string_key, 0);
  2518. return FAILURE;
  2519. }
  2520. if ((form_error = curl_mime_name(part, ZSTR_VAL(string_key))) != CURLE_OK
  2521. || (form_error = curl_mime_filedata(part, ZSTR_VAL(postval))) != CURLE_OK
  2522. || (form_error = curl_mime_filename(part, filename ? filename : ZSTR_VAL(postval))) != CURLE_OK
  2523. || (form_error = curl_mime_type(part, type ? type : "application/octet-stream")) != CURLE_OK) {
  2524. error = form_error;
  2525. }
  2526. #else
  2527. form_error = curl_formadd(&first, &last,
  2528. CURLFORM_COPYNAME, ZSTR_VAL(string_key),
  2529. CURLFORM_NAMELENGTH, ZSTR_LEN(string_key),
  2530. CURLFORM_FILENAME, filename ? filename : ZSTR_VAL(postval),
  2531. CURLFORM_CONTENTTYPE, type ? type : "application/octet-stream",
  2532. CURLFORM_FILE, ZSTR_VAL(postval),
  2533. CURLFORM_END);
  2534. if (form_error != CURL_FORMADD_OK) {
  2535. /* Not nice to convert between enums but we only have place for one error type */
  2536. error = (CURLcode)form_error;
  2537. }
  2538. #endif
  2539. }
  2540. zend_string_release_ex(string_key, 0);
  2541. continue;
  2542. }
  2543. postval = zval_get_tmp_string(current, &tmp_postval);
  2544. #if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
  2545. part = curl_mime_addpart(mime);
  2546. if (part == NULL) {
  2547. zend_tmp_string_release(tmp_postval);
  2548. zend_string_release_ex(string_key, 0);
  2549. return FAILURE;
  2550. }
  2551. if ((form_error = curl_mime_name(part, ZSTR_VAL(string_key))) != CURLE_OK
  2552. || (form_error = curl_mime_data(part, ZSTR_VAL(postval), ZSTR_LEN(postval))) != CURLE_OK) {
  2553. error = form_error;
  2554. }
  2555. #else
  2556. /* The arguments after _NAMELENGTH and _CONTENTSLENGTH
  2557. * must be explicitly cast to long in curl_formadd
  2558. * use since curl needs a long not an int. */
  2559. form_error = curl_formadd(&first, &last,
  2560. CURLFORM_COPYNAME, ZSTR_VAL(string_key),
  2561. CURLFORM_NAMELENGTH, ZSTR_LEN(string_key),
  2562. CURLFORM_COPYCONTENTS, ZSTR_VAL(postval),
  2563. CURLFORM_CONTENTSLENGTH, ZSTR_LEN(postval),
  2564. CURLFORM_END);
  2565. if (form_error != CURL_FORMADD_OK) {
  2566. /* Not nice to convert between enums but we only have place for one error type */
  2567. error = (CURLcode)form_error;
  2568. }
  2569. #endif
  2570. zend_tmp_string_release(tmp_postval);
  2571. zend_string_release_ex(string_key, 0);
  2572. } ZEND_HASH_FOREACH_END();
  2573. SAVE_CURL_ERROR(ch, error);
  2574. if (error != CURLE_OK) {
  2575. return FAILURE;
  2576. }
  2577. if ((*ch->clone) == 1) {
  2578. zend_llist_clean(&ch->to_free->post);
  2579. }
  2580. #if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
  2581. zend_llist_add_element(&ch->to_free->post, &mime);
  2582. error = curl_easy_setopt(ch->cp, CURLOPT_MIMEPOST, mime);
  2583. #else
  2584. zend_llist_add_element(&ch->to_free->post, &first);
  2585. error = curl_easy_setopt(ch->cp, CURLOPT_HTTPPOST, first);
  2586. #endif
  2587. } else {
  2588. #if LIBCURL_VERSION_NUM >= 0x071101
  2589. zend_string *tmp_str;
  2590. zend_string *str = zval_get_tmp_string(zvalue, &tmp_str);
  2591. /* with curl 7.17.0 and later, we can use COPYPOSTFIELDS, but we have to provide size before */
  2592. error = curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDSIZE, ZSTR_LEN(str));
  2593. error = curl_easy_setopt(ch->cp, CURLOPT_COPYPOSTFIELDS, ZSTR_VAL(str));
  2594. zend_tmp_string_release(tmp_str);
  2595. #else
  2596. char *post = NULL;
  2597. zend_string *tmp_str;
  2598. zend_string *str = zval_get_tmp_string(zvalue, &tmp_str);
  2599. post = estrndup(ZSTR_VAL(str), ZSTR_LEN(str));
  2600. zend_llist_add_element(&ch->to_free->str, &post);
  2601. curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDS, post);
  2602. error = curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDSIZE, ZSTR_LEN(str));
  2603. zend_tmp_string_release(tmp_str);
  2604. #endif
  2605. }
  2606. break;
  2607. case CURLOPT_PROGRESSFUNCTION:
  2608. curl_easy_setopt(ch->cp, CURLOPT_PROGRESSFUNCTION, curl_progress);
  2609. curl_easy_setopt(ch->cp, CURLOPT_PROGRESSDATA, ch);
  2610. if (ch->handlers->progress == NULL) {
  2611. ch->handlers->progress = ecalloc(1, sizeof(php_curl_progress));
  2612. } else if (!Z_ISUNDEF(ch->handlers->progress->func_name)) {
  2613. zval_ptr_dtor(&ch->handlers->progress->func_name);
  2614. ch->handlers->progress->fci_cache = empty_fcall_info_cache;
  2615. }
  2616. ZVAL_COPY(&ch->handlers->progress->func_name, zvalue);
  2617. ch->handlers->progress->method = PHP_CURL_USER;
  2618. break;
  2619. case CURLOPT_READFUNCTION:
  2620. if (!Z_ISUNDEF(ch->handlers->read->func_name)) {
  2621. zval_ptr_dtor(&ch->handlers->read->func_name);
  2622. ch->handlers->read->fci_cache = empty_fcall_info_cache;
  2623. }
  2624. ZVAL_COPY(&ch->handlers->read->func_name, zvalue);
  2625. ch->handlers->read->method = PHP_CURL_USER;
  2626. break;
  2627. case CURLOPT_RETURNTRANSFER:
  2628. if (zend_is_true(zvalue)) {
  2629. ch->handlers->write->method = PHP_CURL_RETURN;
  2630. } else {
  2631. ch->handlers->write->method = PHP_CURL_STDOUT;
  2632. }
  2633. break;
  2634. case CURLOPT_WRITEFUNCTION:
  2635. if (!Z_ISUNDEF(ch->handlers->write->func_name)) {
  2636. zval_ptr_dtor(&ch->handlers->write->func_name);
  2637. ch->handlers->write->fci_cache = empty_fcall_info_cache;
  2638. }
  2639. ZVAL_COPY(&ch->handlers->write->func_name, zvalue);
  2640. ch->handlers->write->method = PHP_CURL_USER;
  2641. break;
  2642. /* Curl off_t options */
  2643. case CURLOPT_MAX_RECV_SPEED_LARGE:
  2644. case CURLOPT_MAX_SEND_SPEED_LARGE:
  2645. #if LIBCURL_VERSION_NUM >= 0x073b00 /* Available since 7.59.0 */
  2646. case CURLOPT_TIMEVALUE_LARGE:
  2647. #endif
  2648. lval = zval_get_long(zvalue);
  2649. error = curl_easy_setopt(ch->cp, option, (curl_off_t)lval);
  2650. break;
  2651. #if LIBCURL_VERSION_NUM >= 0x071301 /* Available since 7.19.1 */
  2652. case CURLOPT_POSTREDIR:
  2653. lval = zval_get_long(zvalue);
  2654. error = curl_easy_setopt(ch->cp, CURLOPT_POSTREDIR, lval & CURL_REDIR_POST_ALL);
  2655. break;
  2656. #endif
  2657. /* the following options deal with files, therefore the open_basedir check
  2658. * is required.
  2659. */
  2660. case CURLOPT_COOKIEFILE:
  2661. case CURLOPT_COOKIEJAR:
  2662. case CURLOPT_RANDOM_FILE:
  2663. case CURLOPT_SSLCERT:
  2664. case CURLOPT_NETRC_FILE:
  2665. #if LIBCURL_VERSION_NUM >= 0x071001 /* Available since 7.16.1 */
  2666. case CURLOPT_SSH_PRIVATE_KEYFILE:
  2667. case CURLOPT_SSH_PUBLIC_KEYFILE:
  2668. #endif
  2669. #if LIBCURL_VERSION_NUM >= 0x071300 /* Available since 7.19.0 */
  2670. case CURLOPT_CRLFILE:
  2671. case CURLOPT_ISSUERCERT:
  2672. #endif
  2673. #if LIBCURL_VERSION_NUM >= 0x071306 /* Available since 7.19.6 */
  2674. case CURLOPT_SSH_KNOWNHOSTS:
  2675. #endif
  2676. {
  2677. zend_string *tmp_str;
  2678. zend_string *str = zval_get_tmp_string(zvalue, &tmp_str);
  2679. int ret;
  2680. if (ZSTR_LEN(str) && php_check_open_basedir(ZSTR_VAL(str))) {
  2681. zend_tmp_string_release(tmp_str);
  2682. return FAILURE;
  2683. }
  2684. ret = php_curl_option_str(ch, option, ZSTR_VAL(str), ZSTR_LEN(str), 0);
  2685. zend_tmp_string_release(tmp_str);
  2686. return ret;
  2687. }
  2688. case CURLINFO_HEADER_OUT:
  2689. if (zend_is_true(zvalue)) {
  2690. curl_easy_setopt(ch->cp, CURLOPT_DEBUGFUNCTION, curl_debug);
  2691. curl_easy_setopt(ch->cp, CURLOPT_DEBUGDATA, (void *)ch);
  2692. curl_easy_setopt(ch->cp, CURLOPT_VERBOSE, 1);
  2693. } else {
  2694. curl_easy_setopt(ch->cp, CURLOPT_DEBUGFUNCTION, NULL);
  2695. curl_easy_setopt(ch->cp, CURLOPT_DEBUGDATA, NULL);
  2696. curl_easy_setopt(ch->cp, CURLOPT_VERBOSE, 0);
  2697. }
  2698. break;
  2699. case CURLOPT_SHARE:
  2700. {
  2701. php_curlsh *sh;
  2702. if ((sh = (php_curlsh *)zend_fetch_resource_ex(zvalue, le_curl_share_handle_name, le_curl_share_handle))) {
  2703. curl_easy_setopt(ch->cp, CURLOPT_SHARE, sh->share);
  2704. }
  2705. }
  2706. break;
  2707. #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
  2708. case CURLOPT_FNMATCH_FUNCTION:
  2709. curl_easy_setopt(ch->cp, CURLOPT_FNMATCH_FUNCTION, curl_fnmatch);
  2710. curl_easy_setopt(ch->cp, CURLOPT_FNMATCH_DATA, ch);
  2711. if (ch->handlers->fnmatch == NULL) {
  2712. ch->handlers->fnmatch = ecalloc(1, sizeof(php_curl_fnmatch));
  2713. } else if (!Z_ISUNDEF(ch->handlers->fnmatch->func_name)) {
  2714. zval_ptr_dtor(&ch->handlers->fnmatch->func_name);
  2715. ch->handlers->fnmatch->fci_cache = empty_fcall_info_cache;
  2716. }
  2717. ZVAL_COPY(&ch->handlers->fnmatch->func_name, zvalue);
  2718. ch->handlers->fnmatch->method = PHP_CURL_USER;
  2719. break;
  2720. #endif
  2721. }
  2722. SAVE_CURL_ERROR(ch, error);
  2723. if (error != CURLE_OK) {
  2724. return FAILURE;
  2725. } else {
  2726. return SUCCESS;
  2727. }
  2728. }
  2729. /* }}} */
  2730. /* {{{ proto bool curl_setopt(resource ch, int option, mixed value)
  2731. Set an option for a cURL transfer */
  2732. PHP_FUNCTION(curl_setopt)
  2733. {
  2734. zval *zid, *zvalue;
  2735. zend_long options;
  2736. php_curl *ch;
  2737. ZEND_PARSE_PARAMETERS_START(3, 3)
  2738. Z_PARAM_RESOURCE(zid)
  2739. Z_PARAM_LONG(options)
  2740. Z_PARAM_ZVAL(zvalue)
  2741. ZEND_PARSE_PARAMETERS_END();
  2742. if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
  2743. RETURN_FALSE;
  2744. }
  2745. if (options <= 0 && options != CURLOPT_SAFE_UPLOAD) {
  2746. php_error_docref(NULL, E_WARNING, "Invalid curl configuration option");
  2747. RETURN_FALSE;
  2748. }
  2749. if (_php_curl_setopt(ch, options, zvalue) == SUCCESS) {
  2750. RETURN_TRUE;
  2751. } else {
  2752. RETURN_FALSE;
  2753. }
  2754. }
  2755. /* }}} */
  2756. /* {{{ proto bool curl_setopt_array(resource ch, array options)
  2757. Set an array of option for a cURL transfer */
  2758. PHP_FUNCTION(curl_setopt_array)
  2759. {
  2760. zval *zid, *arr, *entry;
  2761. php_curl *ch;
  2762. zend_ulong option;
  2763. zend_string *string_key;
  2764. ZEND_PARSE_PARAMETERS_START(2, 2)
  2765. Z_PARAM_RESOURCE(zid)
  2766. Z_PARAM_ARRAY(arr)
  2767. ZEND_PARSE_PARAMETERS_END();
  2768. if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
  2769. RETURN_FALSE;
  2770. }
  2771. ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(arr), option, string_key, entry) {
  2772. if (string_key) {
  2773. php_error_docref(NULL, E_WARNING,
  2774. "Array keys must be CURLOPT constants or equivalent integer values");
  2775. RETURN_FALSE;
  2776. }
  2777. ZVAL_DEREF(entry);
  2778. if (_php_curl_setopt(ch, (zend_long) option, entry) == FAILURE) {
  2779. RETURN_FALSE;
  2780. }
  2781. } ZEND_HASH_FOREACH_END();
  2782. RETURN_TRUE;
  2783. }
  2784. /* }}} */
  2785. /* {{{ _php_curl_cleanup_handle(ch)
  2786. Cleanup an execution phase */
  2787. void _php_curl_cleanup_handle(php_curl *ch)
  2788. {
  2789. smart_str_free(&ch->handlers->write->buf);
  2790. if (ch->header.str) {
  2791. zend_string_release_ex(ch->header.str, 0);
  2792. ch->header.str = NULL;
  2793. }
  2794. memset(ch->err.str, 0, CURL_ERROR_SIZE + 1);
  2795. ch->err.no = 0;
  2796. }
  2797. /* }}} */
  2798. /* {{{ proto bool curl_exec(resource ch)
  2799. Perform a cURL session */
  2800. PHP_FUNCTION(curl_exec)
  2801. {
  2802. CURLcode error;
  2803. zval *zid;
  2804. php_curl *ch;
  2805. ZEND_PARSE_PARAMETERS_START(1, 1)
  2806. Z_PARAM_RESOURCE(zid)
  2807. ZEND_PARSE_PARAMETERS_END();
  2808. if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
  2809. RETURN_FALSE;
  2810. }
  2811. _php_curl_verify_handlers(ch, 1);
  2812. _php_curl_cleanup_handle(ch);
  2813. error = curl_easy_perform(ch->cp);
  2814. SAVE_CURL_ERROR(ch, error);
  2815. /* CURLE_PARTIAL_FILE is returned by HEAD requests */
  2816. if (error != CURLE_OK && error != CURLE_PARTIAL_FILE) {
  2817. smart_str_free(&ch->handlers->write->buf);
  2818. RETURN_FALSE;
  2819. }
  2820. if (!Z_ISUNDEF(ch->handlers->std_err)) {
  2821. php_stream *stream;
  2822. stream = (php_stream*)zend_fetch_resource2_ex(&ch->handlers->std_err, NULL, php_file_le_stream(), php_file_le_pstream());
  2823. if (stream) {
  2824. php_stream_flush(stream);
  2825. }
  2826. }
  2827. if (ch->handlers->write->method == PHP_CURL_RETURN && ch->handlers->write->buf.s) {
  2828. smart_str_0(&ch->handlers->write->buf);
  2829. RETURN_STR_COPY(ch->handlers->write->buf.s);
  2830. }
  2831. /* flush the file handle, so any remaining data is synched to disk */
  2832. if (ch->handlers->write->method == PHP_CURL_FILE && ch->handlers->write->fp) {
  2833. fflush(ch->handlers->write->fp);
  2834. }
  2835. if (ch->handlers->write_header->method == PHP_CURL_FILE && ch->handlers->write_header->fp) {
  2836. fflush(ch->handlers->write_header->fp);
  2837. }
  2838. if (ch->handlers->write->method == PHP_CURL_RETURN) {
  2839. RETURN_EMPTY_STRING();
  2840. } else {
  2841. RETURN_TRUE;
  2842. }
  2843. }
  2844. /* }}} */
  2845. /* {{{ proto mixed curl_getinfo(resource ch [, int option])
  2846. Get information regarding a specific transfer */
  2847. PHP_FUNCTION(curl_getinfo)
  2848. {
  2849. zval *zid;
  2850. php_curl *ch;
  2851. zend_long option = 0;
  2852. ZEND_PARSE_PARAMETERS_START(1, 2)
  2853. Z_PARAM_RESOURCE(zid)
  2854. Z_PARAM_OPTIONAL
  2855. Z_PARAM_LONG(option)
  2856. ZEND_PARSE_PARAMETERS_END();
  2857. if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
  2858. RETURN_FALSE;
  2859. }
  2860. if (ZEND_NUM_ARGS() < 2) {
  2861. char *s_code;
  2862. /* libcurl expects long datatype. So far no cases are known where
  2863. it would be an issue. Using zend_long would truncate a 64-bit
  2864. var on Win64, so the exact long datatype fits everywhere, as
  2865. long as there's no 32-bit int overflow. */
  2866. long l_code;
  2867. double d_code;
  2868. #if LIBCURL_VERSION_NUM > 0x071301 /* 7.19.1 */
  2869. struct curl_certinfo *ci = NULL;
  2870. zval listcode;
  2871. #endif
  2872. #if LIBCURL_VERSION_NUM >= 0x073700 /* 7.55.0 */
  2873. curl_off_t co;
  2874. #endif
  2875. array_init(return_value);
  2876. if (curl_easy_getinfo(ch->cp, CURLINFO_EFFECTIVE_URL, &s_code) == CURLE_OK) {
  2877. CAAS("url", s_code);
  2878. }
  2879. if (curl_easy_getinfo(ch->cp, CURLINFO_CONTENT_TYPE, &s_code) == CURLE_OK) {
  2880. if (s_code != NULL) {
  2881. CAAS("content_type", s_code);
  2882. } else {
  2883. zval retnull;
  2884. ZVAL_NULL(&retnull);
  2885. CAAZ("content_type", &retnull);
  2886. }
  2887. }
  2888. if (curl_easy_getinfo(ch->cp, CURLINFO_HTTP_CODE, &l_code) == CURLE_OK) {
  2889. CAAL("http_code", l_code);
  2890. }
  2891. if (curl_easy_getinfo(ch->cp, CURLINFO_HEADER_SIZE, &l_code) == CURLE_OK) {
  2892. CAAL("header_size", l_code);
  2893. }
  2894. if (curl_easy_getinfo(ch->cp, CURLINFO_REQUEST_SIZE, &l_code) == CURLE_OK) {
  2895. CAAL("request_size", l_code);
  2896. }
  2897. if (curl_easy_getinfo(ch->cp, CURLINFO_FILETIME, &l_code) == CURLE_OK) {
  2898. CAAL("filetime", l_code);
  2899. }
  2900. if (curl_easy_getinfo(ch->cp, CURLINFO_SSL_VERIFYRESULT, &l_code) == CURLE_OK) {
  2901. CAAL("ssl_verify_result", l_code);
  2902. }
  2903. if (curl_easy_getinfo(ch->cp, CURLINFO_REDIRECT_COUNT, &l_code) == CURLE_OK) {
  2904. CAAL("redirect_count", l_code);
  2905. }
  2906. if (curl_easy_getinfo(ch->cp, CURLINFO_TOTAL_TIME, &d_code) == CURLE_OK) {
  2907. CAAD("total_time", d_code);
  2908. }
  2909. if (curl_easy_getinfo(ch->cp, CURLINFO_NAMELOOKUP_TIME, &d_code) == CURLE_OK) {
  2910. CAAD("namelookup_time", d_code);
  2911. }
  2912. if (curl_easy_getinfo(ch->cp, CURLINFO_CONNECT_TIME, &d_code) == CURLE_OK) {
  2913. CAAD("connect_time", d_code);
  2914. }
  2915. if (curl_easy_getinfo(ch->cp, CURLINFO_PRETRANSFER_TIME, &d_code) == CURLE_OK) {
  2916. CAAD("pretransfer_time", d_code);
  2917. }
  2918. if (curl_easy_getinfo(ch->cp, CURLINFO_SIZE_UPLOAD, &d_code) == CURLE_OK) {
  2919. CAAD("size_upload", d_code);
  2920. }
  2921. if (curl_easy_getinfo(ch->cp, CURLINFO_SIZE_DOWNLOAD, &d_code) == CURLE_OK) {
  2922. CAAD("size_download", d_code);
  2923. }
  2924. if (curl_easy_getinfo(ch->cp, CURLINFO_SPEED_DOWNLOAD, &d_code) == CURLE_OK) {
  2925. CAAD("speed_download", d_code);
  2926. }
  2927. if (curl_easy_getinfo(ch->cp, CURLINFO_SPEED_UPLOAD, &d_code) == CURLE_OK) {
  2928. CAAD("speed_upload", d_code);
  2929. }
  2930. if (curl_easy_getinfo(ch->cp, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d_code) == CURLE_OK) {
  2931. CAAD("download_content_length", d_code);
  2932. }
  2933. if (curl_easy_getinfo(ch->cp, CURLINFO_CONTENT_LENGTH_UPLOAD, &d_code) == CURLE_OK) {
  2934. CAAD("upload_content_length", d_code);
  2935. }
  2936. if (curl_easy_getinfo(ch->cp, CURLINFO_STARTTRANSFER_TIME, &d_code) == CURLE_OK) {
  2937. CAAD("starttransfer_time", d_code);
  2938. }
  2939. if (curl_easy_getinfo(ch->cp, CURLINFO_REDIRECT_TIME, &d_code) == CURLE_OK) {
  2940. CAAD("redirect_time", d_code);
  2941. }
  2942. #if LIBCURL_VERSION_NUM >= 0x071202 /* Available since 7.18.2 */
  2943. if (curl_easy_getinfo(ch->cp, CURLINFO_REDIRECT_URL, &s_code) == CURLE_OK) {
  2944. CAAS("redirect_url", s_code);
  2945. }
  2946. #endif
  2947. #if LIBCURL_VERSION_NUM >= 0x071300 /* Available since 7.19.0 */
  2948. if (curl_easy_getinfo(ch->cp, CURLINFO_PRIMARY_IP, &s_code) == CURLE_OK) {
  2949. CAAS("primary_ip", s_code);
  2950. }
  2951. #endif
  2952. #if LIBCURL_VERSION_NUM >= 0x071301 /* Available since 7.19.1 */
  2953. if (curl_easy_getinfo(ch->cp, CURLINFO_CERTINFO, &ci) == CURLE_OK) {
  2954. array_init(&listcode);
  2955. create_certinfo(ci, &listcode);
  2956. CAAZ("certinfo", &listcode);
  2957. }
  2958. #endif
  2959. #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
  2960. if (curl_easy_getinfo(ch->cp, CURLINFO_PRIMARY_PORT, &l_code) == CURLE_OK) {
  2961. CAAL("primary_port", l_code);
  2962. }
  2963. if (curl_easy_getinfo(ch->cp, CURLINFO_LOCAL_IP, &s_code) == CURLE_OK) {
  2964. CAAS("local_ip", s_code);
  2965. }
  2966. if (curl_easy_getinfo(ch->cp, CURLINFO_LOCAL_PORT, &l_code) == CURLE_OK) {
  2967. CAAL("local_port", l_code);
  2968. }
  2969. #endif
  2970. #if LIBCURL_VERSION_NUM >= 0x073200 /* Available since 7.50.0 */
  2971. if (curl_easy_getinfo(ch->cp, CURLINFO_HTTP_VERSION, &l_code) == CURLE_OK) {
  2972. CAAL("http_version", l_code);
  2973. }
  2974. #endif
  2975. #if LIBCURL_VERSION_NUM >= 0x073400 /* Available since 7.52.0 */
  2976. if (curl_easy_getinfo(ch->cp, CURLINFO_PROTOCOL, &l_code) == CURLE_OK) {
  2977. CAAL("protocol", l_code);
  2978. }
  2979. if (curl_easy_getinfo(ch->cp, CURLINFO_PROXY_SSL_VERIFYRESULT, &l_code) == CURLE_OK) {
  2980. CAAL("ssl_verifyresult", l_code);
  2981. }
  2982. if (curl_easy_getinfo(ch->cp, CURLINFO_SCHEME, &s_code) == CURLE_OK) {
  2983. CAAS("scheme", s_code);
  2984. }
  2985. #endif
  2986. #if LIBCURL_VERSION_NUM >= 0x073d00 /* Available since 7.61.0 */
  2987. if (curl_easy_getinfo(ch->cp, CURLINFO_APPCONNECT_TIME_T, &co) == CURLE_OK) {
  2988. CAAL("appconnect_time_us", co);
  2989. }
  2990. if (curl_easy_getinfo(ch->cp, CURLINFO_CONNECT_TIME_T, &co) == CURLE_OK) {
  2991. CAAL("connect_time_us", co);
  2992. }
  2993. if (curl_easy_getinfo(ch->cp, CURLINFO_NAMELOOKUP_TIME_T, &co) == CURLE_OK) {
  2994. CAAL("namelookup_time_us", co);
  2995. }
  2996. if (curl_easy_getinfo(ch->cp, CURLINFO_PRETRANSFER_TIME_T, &co) == CURLE_OK) {
  2997. CAAL("pretransfer_time_us", co);
  2998. }
  2999. if (curl_easy_getinfo(ch->cp, CURLINFO_REDIRECT_TIME_T, &co) == CURLE_OK) {
  3000. CAAL("redirect_time_us", co);
  3001. }
  3002. if (curl_easy_getinfo(ch->cp, CURLINFO_STARTTRANSFER_TIME_T, &co) == CURLE_OK) {
  3003. CAAL("starttransfer_time_us", co);
  3004. }
  3005. if (curl_easy_getinfo(ch->cp, CURLINFO_TOTAL_TIME_T, &co) == CURLE_OK) {
  3006. CAAL("total_time_us", co);
  3007. }
  3008. #endif
  3009. if (ch->header.str) {
  3010. CAASTR("request_header", ch->header.str);
  3011. }
  3012. } else {
  3013. switch (option) {
  3014. case CURLINFO_HEADER_OUT:
  3015. if (ch->header.str) {
  3016. RETURN_STR_COPY(ch->header.str);
  3017. } else {
  3018. RETURN_FALSE;
  3019. }
  3020. #if LIBCURL_VERSION_NUM >= 0x071301 /* Available since 7.19.1 */
  3021. case CURLINFO_CERTINFO: {
  3022. struct curl_certinfo *ci = NULL;
  3023. array_init(return_value);
  3024. if (curl_easy_getinfo(ch->cp, CURLINFO_CERTINFO, &ci) == CURLE_OK) {
  3025. create_certinfo(ci, return_value);
  3026. } else {
  3027. RETURN_FALSE;
  3028. }
  3029. break;
  3030. }
  3031. #endif
  3032. default: {
  3033. int type = CURLINFO_TYPEMASK & option;
  3034. switch (type) {
  3035. case CURLINFO_STRING:
  3036. {
  3037. char *s_code = NULL;
  3038. if (curl_easy_getinfo(ch->cp, option, &s_code) == CURLE_OK && s_code) {
  3039. RETURN_STRING(s_code);
  3040. } else {
  3041. RETURN_FALSE;
  3042. }
  3043. break;
  3044. }
  3045. case CURLINFO_LONG:
  3046. {
  3047. zend_long code = 0;
  3048. if (curl_easy_getinfo(ch->cp, option, &code) == CURLE_OK) {
  3049. RETURN_LONG(code);
  3050. } else {
  3051. RETURN_FALSE;
  3052. }
  3053. break;
  3054. }
  3055. case CURLINFO_DOUBLE:
  3056. {
  3057. double code = 0.0;
  3058. if (curl_easy_getinfo(ch->cp, option, &code) == CURLE_OK) {
  3059. RETURN_DOUBLE(code);
  3060. } else {
  3061. RETURN_FALSE;
  3062. }
  3063. break;
  3064. }
  3065. case CURLINFO_SLIST:
  3066. {
  3067. struct curl_slist *slist;
  3068. array_init(return_value);
  3069. if (curl_easy_getinfo(ch->cp, option, &slist) == CURLE_OK) {
  3070. while (slist) {
  3071. add_next_index_string(return_value, slist->data);
  3072. slist = slist->next;
  3073. }
  3074. curl_slist_free_all(slist);
  3075. } else {
  3076. RETURN_FALSE;
  3077. }
  3078. break;
  3079. }
  3080. #if LIBCURL_VERSION_NUM >= 0x073700 /* Available since 7.55.0 */
  3081. case CURLINFO_OFF_T:
  3082. {
  3083. curl_off_t c_off;
  3084. if (curl_easy_getinfo(ch->cp, option, &c_off) == CURLE_OK) {
  3085. RETURN_LONG((long) c_off);
  3086. } else {
  3087. RETURN_FALSE;
  3088. }
  3089. break;
  3090. }
  3091. #endif
  3092. default:
  3093. RETURN_FALSE;
  3094. }
  3095. }
  3096. }
  3097. }
  3098. }
  3099. /* }}} */
  3100. /* {{{ proto string curl_error(resource ch)
  3101. Return a string contain the last error for the current session */
  3102. PHP_FUNCTION(curl_error)
  3103. {
  3104. zval *zid;
  3105. php_curl *ch;
  3106. ZEND_PARSE_PARAMETERS_START(1, 1)
  3107. Z_PARAM_RESOURCE(zid)
  3108. ZEND_PARSE_PARAMETERS_END();
  3109. if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
  3110. RETURN_FALSE;
  3111. }
  3112. if (ch->err.no) {
  3113. ch->err.str[CURL_ERROR_SIZE] = 0;
  3114. RETURN_STRING(ch->err.str);
  3115. } else {
  3116. RETURN_EMPTY_STRING();
  3117. }
  3118. }
  3119. /* }}} */
  3120. /* {{{ proto int curl_errno(resource ch)
  3121. Return an integer containing the last error number */
  3122. PHP_FUNCTION(curl_errno)
  3123. {
  3124. zval *zid;
  3125. php_curl *ch;
  3126. ZEND_PARSE_PARAMETERS_START(1,1)
  3127. Z_PARAM_RESOURCE(zid)
  3128. ZEND_PARSE_PARAMETERS_END();
  3129. if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
  3130. RETURN_FALSE;
  3131. }
  3132. RETURN_LONG(ch->err.no);
  3133. }
  3134. /* }}} */
  3135. /* {{{ proto void curl_close(resource ch)
  3136. Close a cURL session */
  3137. PHP_FUNCTION(curl_close)
  3138. {
  3139. zval *zid;
  3140. php_curl *ch;
  3141. ZEND_PARSE_PARAMETERS_START(1, 1)
  3142. Z_PARAM_RESOURCE(zid)
  3143. ZEND_PARSE_PARAMETERS_END();
  3144. if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
  3145. RETURN_FALSE;
  3146. }
  3147. if (ch->in_callback) {
  3148. php_error_docref(NULL, E_WARNING, "Attempt to close cURL handle from a callback");
  3149. return;
  3150. }
  3151. zend_list_close(Z_RES_P(zid));
  3152. }
  3153. /* }}} */
  3154. /* {{{ _php_curl_close_ex()
  3155. List destructor for curl handles */
  3156. static void _php_curl_close_ex(php_curl *ch)
  3157. {
  3158. #if PHP_CURL_DEBUG
  3159. fprintf(stderr, "DTOR CALLED, ch = %x\n", ch);
  3160. #endif
  3161. _php_curl_verify_handlers(ch, 0);
  3162. /*
  3163. * Libcurl is doing connection caching. When easy handle is cleaned up,
  3164. * if the handle was previously used by the curl_multi_api, the connection
  3165. * remains open un the curl multi handle is cleaned up. Some protocols are
  3166. * sending content like the FTP one, and libcurl try to use the
  3167. * WRITEFUNCTION or the HEADERFUNCTION. Since structures used in those
  3168. * callback are freed, we need to use an other callback to which avoid
  3169. * segfaults.
  3170. *
  3171. * Libcurl commit d021f2e8a00 fix this issue and should be part of 7.28.2
  3172. */
  3173. if (ch->cp != NULL) {
  3174. curl_easy_setopt(ch->cp, CURLOPT_HEADERFUNCTION, curl_write_nothing);
  3175. curl_easy_setopt(ch->cp, CURLOPT_WRITEFUNCTION, curl_write_nothing);
  3176. curl_easy_cleanup(ch->cp);
  3177. }
  3178. /* cURL destructors should be invoked only by last curl handle */
  3179. if (--(*ch->clone) == 0) {
  3180. zend_llist_clean(&ch->to_free->str);
  3181. zend_llist_clean(&ch->to_free->post);
  3182. zend_hash_destroy(ch->to_free->slist);
  3183. efree(ch->to_free->slist);
  3184. efree(ch->to_free);
  3185. efree(ch->clone);
  3186. }
  3187. smart_str_free(&ch->handlers->write->buf);
  3188. zval_ptr_dtor(&ch->handlers->write->func_name);
  3189. zval_ptr_dtor(&ch->handlers->read->func_name);
  3190. zval_ptr_dtor(&ch->handlers->write_header->func_name);
  3191. zval_ptr_dtor(&ch->handlers->std_err);
  3192. if (ch->header.str) {
  3193. zend_string_release_ex(ch->header.str, 0);
  3194. }
  3195. zval_ptr_dtor(&ch->handlers->write_header->stream);
  3196. zval_ptr_dtor(&ch->handlers->write->stream);
  3197. zval_ptr_dtor(&ch->handlers->read->stream);
  3198. efree(ch->handlers->write);
  3199. efree(ch->handlers->write_header);
  3200. efree(ch->handlers->read);
  3201. if (ch->handlers->progress) {
  3202. zval_ptr_dtor(&ch->handlers->progress->func_name);
  3203. efree(ch->handlers->progress);
  3204. }
  3205. #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
  3206. if (ch->handlers->fnmatch) {
  3207. zval_ptr_dtor(&ch->handlers->fnmatch->func_name);
  3208. efree(ch->handlers->fnmatch);
  3209. }
  3210. #endif
  3211. efree(ch->handlers);
  3212. efree(ch);
  3213. }
  3214. /* }}} */
  3215. /* {{{ _php_curl_close()
  3216. List destructor for curl handles */
  3217. static void _php_curl_close(zend_resource *rsrc)
  3218. {
  3219. php_curl *ch = (php_curl *) rsrc->ptr;
  3220. _php_curl_close_ex(ch);
  3221. }
  3222. /* }}} */
  3223. /* {{{ proto bool curl_strerror(int code)
  3224. return string describing error code */
  3225. PHP_FUNCTION(curl_strerror)
  3226. {
  3227. zend_long code;
  3228. const char *str;
  3229. ZEND_PARSE_PARAMETERS_START(1, 1)
  3230. Z_PARAM_LONG(code)
  3231. ZEND_PARSE_PARAMETERS_END();
  3232. str = curl_easy_strerror(code);
  3233. if (str) {
  3234. RETURN_STRING(str);
  3235. } else {
  3236. RETURN_NULL();
  3237. }
  3238. }
  3239. /* }}} */
  3240. /* {{{ _php_curl_reset_handlers()
  3241. Reset all handlers of a given php_curl */
  3242. static void _php_curl_reset_handlers(php_curl *ch)
  3243. {
  3244. if (!Z_ISUNDEF(ch->handlers->write->stream)) {
  3245. zval_ptr_dtor(&ch->handlers->write->stream);
  3246. ZVAL_UNDEF(&ch->handlers->write->stream);
  3247. }
  3248. ch->handlers->write->fp = NULL;
  3249. ch->handlers->write->method = PHP_CURL_STDOUT;
  3250. if (!Z_ISUNDEF(ch->handlers->write_header->stream)) {
  3251. zval_ptr_dtor(&ch->handlers->write_header->stream);
  3252. ZVAL_UNDEF(&ch->handlers->write_header->stream);
  3253. }
  3254. ch->handlers->write_header->fp = NULL;
  3255. ch->handlers->write_header->method = PHP_CURL_IGNORE;
  3256. if (!Z_ISUNDEF(ch->handlers->read->stream)) {
  3257. zval_ptr_dtor(&ch->handlers->read->stream);
  3258. ZVAL_UNDEF(&ch->handlers->read->stream);
  3259. }
  3260. ch->handlers->read->fp = NULL;
  3261. ch->handlers->read->res = NULL;
  3262. ch->handlers->read->method = PHP_CURL_DIRECT;
  3263. if (!Z_ISUNDEF(ch->handlers->std_err)) {
  3264. zval_ptr_dtor(&ch->handlers->std_err);
  3265. ZVAL_UNDEF(&ch->handlers->std_err);
  3266. }
  3267. if (ch->handlers->progress) {
  3268. zval_ptr_dtor(&ch->handlers->progress->func_name);
  3269. efree(ch->handlers->progress);
  3270. ch->handlers->progress = NULL;
  3271. }
  3272. #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
  3273. if (ch->handlers->fnmatch) {
  3274. zval_ptr_dtor(&ch->handlers->fnmatch->func_name);
  3275. efree(ch->handlers->fnmatch);
  3276. ch->handlers->fnmatch = NULL;
  3277. }
  3278. #endif
  3279. }
  3280. /* }}} */
  3281. /* {{{ proto void curl_reset(resource ch)
  3282. Reset all options of a libcurl session handle */
  3283. PHP_FUNCTION(curl_reset)
  3284. {
  3285. zval *zid;
  3286. php_curl *ch;
  3287. ZEND_PARSE_PARAMETERS_START(1, 1)
  3288. Z_PARAM_RESOURCE(zid)
  3289. ZEND_PARSE_PARAMETERS_END();
  3290. if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
  3291. RETURN_FALSE;
  3292. }
  3293. if (ch->in_callback) {
  3294. php_error_docref(NULL, E_WARNING, "Attempt to reset cURL handle from a callback");
  3295. return;
  3296. }
  3297. curl_easy_reset(ch->cp);
  3298. _php_curl_reset_handlers(ch);
  3299. _php_curl_set_default_options(ch);
  3300. }
  3301. /* }}} */
  3302. /* {{{ proto void curl_escape(resource ch, string str)
  3303. URL encodes the given string */
  3304. PHP_FUNCTION(curl_escape)
  3305. {
  3306. zend_string *str;
  3307. char *res;
  3308. zval *zid;
  3309. php_curl *ch;
  3310. ZEND_PARSE_PARAMETERS_START(2,2)
  3311. Z_PARAM_RESOURCE(zid)
  3312. Z_PARAM_STR(str)
  3313. ZEND_PARSE_PARAMETERS_END();
  3314. if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
  3315. RETURN_FALSE;
  3316. }
  3317. if (ZEND_SIZE_T_INT_OVFL(ZSTR_LEN(str))) {
  3318. RETURN_FALSE;
  3319. }
  3320. if ((res = curl_easy_escape(ch->cp, ZSTR_VAL(str), ZSTR_LEN(str)))) {
  3321. RETVAL_STRING(res);
  3322. curl_free(res);
  3323. } else {
  3324. RETURN_FALSE;
  3325. }
  3326. }
  3327. /* }}} */
  3328. /* {{{ proto void curl_unescape(resource ch, string str)
  3329. URL decodes the given string */
  3330. PHP_FUNCTION(curl_unescape)
  3331. {
  3332. char *out = NULL;
  3333. int out_len;
  3334. zval *zid;
  3335. zend_string *str;
  3336. php_curl *ch;
  3337. ZEND_PARSE_PARAMETERS_START(2,2)
  3338. Z_PARAM_RESOURCE(zid)
  3339. Z_PARAM_STR(str)
  3340. ZEND_PARSE_PARAMETERS_END();
  3341. if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
  3342. RETURN_FALSE;
  3343. }
  3344. if (ZEND_SIZE_T_INT_OVFL(ZSTR_LEN(str))) {
  3345. RETURN_FALSE;
  3346. }
  3347. if ((out = curl_easy_unescape(ch->cp, ZSTR_VAL(str), ZSTR_LEN(str), &out_len))) {
  3348. RETVAL_STRINGL(out, out_len);
  3349. curl_free(out);
  3350. } else {
  3351. RETURN_FALSE;
  3352. }
  3353. }
  3354. /* }}} */
  3355. #if LIBCURL_VERSION_NUM >= 0x071200 /* 7.18.0 */
  3356. /* {{{ proto void curl_pause(resource ch, int bitmask)
  3357. pause and unpause a connection */
  3358. PHP_FUNCTION(curl_pause)
  3359. {
  3360. zend_long bitmask;
  3361. zval *zid;
  3362. php_curl *ch;
  3363. ZEND_PARSE_PARAMETERS_START(2,2)
  3364. Z_PARAM_RESOURCE(zid)
  3365. Z_PARAM_LONG(bitmask)
  3366. ZEND_PARSE_PARAMETERS_END();
  3367. if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
  3368. RETURN_FALSE;
  3369. }
  3370. RETURN_LONG(curl_easy_pause(ch->cp, bitmask));
  3371. }
  3372. /* }}} */
  3373. #endif
  3374. #endif /* HAVE_CURL */
  3375. /*
  3376. * Local variables:
  3377. * tab-width: 4
  3378. * c-basic-offset: 4
  3379. * End:
  3380. * vim600: fdm=marker
  3381. * vim: noet sw=4 ts=4
  3382. */