interface.c 105 KB

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