PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/curl - multi.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 126 176 71.6 %
Date: 2016-07-26 Functions: 15 17 88.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 7                                                        |
       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             : 
      19             : /* $Id$ */
      20             : 
      21             : #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
      22             : 
      23             : #ifdef HAVE_CONFIG_H
      24             : #include "config.h"
      25             : #endif
      26             : 
      27             : #include "php.h"
      28             : 
      29             : #if HAVE_CURL
      30             : 
      31             : #include "php_curl.h"
      32             : 
      33             : #include <curl/curl.h>
      34             : #include <curl/multi.h>
      35             : 
      36             : #ifdef HAVE_SYS_SELECT_H
      37             : #include <sys/select.h>
      38             : #endif
      39             : 
      40             : #ifdef HAVE_SYS_TIME_H
      41             : #include <sys/time.h>
      42             : #endif
      43             : 
      44             : #ifdef HAVE_SYS_TYPES_H
      45             : #include <sys/types.h>
      46             : #endif
      47             : 
      48             : #ifdef HAVE_UNISTD_H
      49             : #include <unistd.h>
      50             : #endif
      51             : 
      52             : #define SAVE_CURLM_ERROR(__handle, __err) (__handle)->err.no = (int) __err;
      53             : 
      54             : /* {{{ proto resource curl_multi_init(void)
      55             :    Returns a new cURL multi handle */
      56          21 : PHP_FUNCTION(curl_multi_init)
      57             : {
      58             :         php_curlm *mh;
      59             : 
      60          21 :         if (zend_parse_parameters_none() == FAILURE) {
      61           1 :                 return;
      62             :         }
      63             : 
      64          20 :         mh = ecalloc(1, sizeof(php_curlm));
      65          20 :         mh->multi = curl_multi_init();
      66          20 :         mh->handlers = ecalloc(1, sizeof(php_curlm_handlers));
      67             : 
      68          20 :         zend_llist_init(&mh->easyh, sizeof(zval), _php_curl_multi_cleanup_list, 0);
      69             : 
      70          20 :         RETURN_RES(zend_register_resource(mh, le_curl_multi_handle));
      71             : }
      72             : /* }}} */
      73             : 
      74             : /* {{{ proto int curl_multi_add_handle(resource mh, resource ch)
      75             :    Add a normal cURL handle to a cURL multi handle */
      76          31 : PHP_FUNCTION(curl_multi_add_handle)
      77             : {
      78             :         zval      *z_mh;
      79             :         zval      *z_ch;
      80             :         php_curlm *mh;
      81             :         php_curl  *ch;
      82             :         zval tmp_val;
      83          31 :         CURLMcode error = CURLM_OK;
      84             : 
      85          31 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rr", &z_mh, &z_ch) == FAILURE) {
      86           1 :                 return;
      87             :         }
      88             : 
      89          30 :         if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
      90           0 :                 RETURN_FALSE;
      91             :         }
      92             : 
      93          30 :         if ((ch = (php_curl *)zend_fetch_resource(Z_RES_P(z_ch), le_curl_name, le_curl)) == NULL) {
      94           0 :                 RETURN_FALSE;
      95             :         }
      96             : 
      97          30 :         _php_curl_cleanup_handle(ch);
      98             : 
      99             :         /* we want to create a copy of this zval that we store in the multihandle structure element "easyh" */
     100          30 :         ZVAL_DUP(&tmp_val, z_ch);
     101             : 
     102          30 :         zend_llist_add_element(&mh->easyh, &tmp_val);
     103             : 
     104          30 :         error = curl_multi_add_handle(mh->multi, ch->cp);
     105          30 :         SAVE_CURLM_ERROR(mh, error);
     106             : 
     107          30 :         RETURN_LONG((zend_long) error);
     108             : }
     109             : /* }}} */
     110             : 
     111          30 : void _php_curl_multi_cleanup_list(void *data) /* {{{ */
     112             : {
     113          30 :         zval *z_ch = (zval *)data;
     114             :         php_curl *ch;
     115             : 
     116          30 :         if (!z_ch) {
     117           0 :                 return;
     118             :         }
     119          30 :         if (!Z_RES_P(z_ch)->ptr) {
     120           4 :                 return;
     121             :         }
     122          26 :         if ((ch = (php_curl *)zend_fetch_resource(Z_RES_P(z_ch), le_curl_name, le_curl)) == NULL) {
     123           0 :                 return;
     124             :         }
     125             : 
     126          26 :         zend_list_delete(Z_RES_P(z_ch));
     127             : }
     128             : /* }}} */
     129             : 
     130             : /* Used internally as comparison routine passed to zend_list_del_element */
     131          24 : static int curl_compare_resources( zval *z1, zval *z2 ) /* {{{ */
     132             : {
     133          72 :         return (Z_TYPE_P(z1) == Z_TYPE_P(z2) &&
     134             :                         Z_TYPE_P(z1) == IS_RESOURCE &&
     135          24 :                         Z_RES_P(z1) == Z_RES_P(z2));
     136             : }
     137             : /* }}} */
     138             : 
     139             : /* Used to find the php_curl resource for a given curl easy handle */
     140           0 : static zval *_php_curl_multi_find_easy_handle(php_curlm *mh, CURL *easy) /* {{{ */
     141             : {
     142             :         php_curl                        *tmp_ch;
     143             :         zend_llist_position pos;
     144             :         zval                            *pz_ch_temp;
     145             : 
     146           0 :         for(pz_ch_temp = (zval *)zend_llist_get_first_ex(&mh->easyh, &pos); pz_ch_temp;
     147           0 :                 pz_ch_temp = (zval *)zend_llist_get_next_ex(&mh->easyh, &pos)) {
     148             : 
     149           0 :                 if ((tmp_ch = (php_curl *)zend_fetch_resource(Z_RES_P(pz_ch_temp), le_curl_name, le_curl)) == NULL) {
     150           0 :                         return NULL;
     151             :                 }
     152             : 
     153           0 :                 if (tmp_ch->cp == easy) {
     154           0 :                         return pz_ch_temp;
     155             :                 }
     156             :         }
     157             : 
     158           0 :         return NULL;
     159             : }
     160             : /* }}} */
     161             : 
     162             : /* {{{ proto int curl_multi_remove_handle(resource mh, resource ch)
     163             :    Remove a multi handle from a set of cURL handles */
     164          23 : PHP_FUNCTION(curl_multi_remove_handle)
     165             : {
     166             :         zval      *z_mh;
     167             :         zval      *z_ch;
     168             :         php_curlm *mh;
     169             :         php_curl  *ch;
     170          23 :         CURLMcode error = CURLM_OK;
     171             : 
     172          23 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rr", &z_mh, &z_ch) == FAILURE) {
     173           0 :                 return;
     174             :         }
     175             : 
     176          23 :         if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
     177           0 :                 RETURN_FALSE;
     178             :         }
     179             : 
     180          23 :         if ((ch = (php_curl *)zend_fetch_resource(Z_RES_P(z_ch), le_curl_name, le_curl)) == NULL) {
     181           0 :                 RETURN_FALSE;
     182             :         }
     183             : 
     184          23 :         error = curl_multi_remove_handle(mh->multi, ch->cp);
     185          23 :         SAVE_CURLM_ERROR(mh, error);
     186             : 
     187          23 :         RETVAL_LONG((zend_long) error);
     188          23 :         zend_llist_del_element(&mh->easyh, z_ch, (int (*)(void *, void *))curl_compare_resources);
     189             : 
     190             : }
     191             : /* }}} */
     192             : 
     193           1 : static void _make_timeval_struct(struct timeval *to, double timeout) /* {{{ */
     194             : {
     195             :         unsigned long conv;
     196             : 
     197           1 :         conv = (unsigned long) (timeout * 1000000.0);
     198           1 :         to->tv_sec = conv / 1000000;
     199           1 :         to->tv_usec = conv % 1000000;
     200           1 : }
     201             : /* }}} */
     202             : 
     203             : /* {{{ proto int curl_multi_select(resource mh[, double timeout])
     204             :    Get all the sockets associated with the cURL extension, which can then be "selected" */
     205           1 : PHP_FUNCTION(curl_multi_select)
     206             : {
     207             :         zval           *z_mh;
     208             :         php_curlm      *mh;
     209             :         fd_set          readfds;
     210             :         fd_set          writefds;
     211             :         fd_set          exceptfds;
     212             :         int             maxfd;
     213           1 :         double          timeout = 1.0;
     214             :         struct timeval  to;
     215           1 :         CURLMcode error = CURLM_OK;
     216             : 
     217           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|d", &z_mh, &timeout) == FAILURE) {
     218           0 :                 return;
     219             :         }
     220             : 
     221           1 :         if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
     222           0 :                 RETURN_FALSE;
     223             :         }
     224             : 
     225           1 :         _make_timeval_struct(&to, timeout);
     226             : 
     227           1 :         FD_ZERO(&readfds);
     228           1 :         FD_ZERO(&writefds);
     229           1 :         FD_ZERO(&exceptfds);
     230             : 
     231           1 :         error = curl_multi_fdset(mh->multi, &readfds, &writefds, &exceptfds, &maxfd);
     232           1 :         SAVE_CURLM_ERROR(mh, error);
     233             : 
     234           1 :         if (maxfd == -1) {
     235           1 :                 RETURN_LONG(-1);
     236             :         }
     237           0 :         RETURN_LONG(select(maxfd + 1, &readfds, &writefds, &exceptfds, &to));
     238             : }
     239             : /* }}} */
     240             : 
     241             : /* {{{ proto int curl_multi_exec(resource mh, int &still_running)
     242             :    Run the sub-connections of the current cURL handle */
     243         675 : PHP_FUNCTION(curl_multi_exec)
     244             : {
     245             :         zval      *z_mh;
     246             :         zval      *z_still_running;
     247             :         php_curlm *mh;
     248             :         int        still_running;
     249         675 :         CURLMcode error = CURLM_OK;
     250             : 
     251         675 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rz/", &z_mh, &z_still_running) == FAILURE) {
     252           0 :                 return;
     253             :         }
     254             : 
     255         675 :         if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
     256           0 :                 RETURN_FALSE;
     257             :         }
     258             : 
     259             :         {
     260             :                 zend_llist_position pos;
     261             :                 php_curl *ch;
     262             :                 zval    *pz_ch;
     263             : 
     264        2700 :                 for (pz_ch = (zval *)zend_llist_get_first_ex(&mh->easyh, &pos); pz_ch;
     265        1350 :                         pz_ch = (zval *)zend_llist_get_next_ex(&mh->easyh, &pos)) {
     266             : 
     267        1350 :                         if ((ch = (php_curl *)zend_fetch_resource(Z_RES_P(pz_ch), le_curl_name, le_curl)) == NULL) {
     268           0 :                                 RETURN_FALSE;
     269             :                         }
     270             : 
     271        1350 :                         _php_curl_verify_handlers(ch, 1);
     272             :                 }
     273             :         }
     274             : 
     275         675 :         convert_to_long(z_still_running);
     276         675 :         still_running = Z_LVAL_P(z_still_running);
     277         675 :         error = curl_multi_perform(mh->multi, &still_running);
     278         675 :         ZVAL_LONG(z_still_running, still_running);
     279             : 
     280         675 :         SAVE_CURLM_ERROR(mh, error);
     281         675 :         RETURN_LONG((zend_long) error);
     282             : }
     283             : /* }}} */
     284             : 
     285             : /* {{{ proto string curl_multi_getcontent(resource ch)
     286             :    Return the content of a cURL handle if CURLOPT_RETURNTRANSFER is set */
     287          14 : PHP_FUNCTION(curl_multi_getcontent)
     288             : {
     289             :         zval     *z_ch;
     290             :         php_curl *ch;
     291             : 
     292          14 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_ch) == FAILURE) {
     293           4 :                 return;
     294             :         }
     295             : 
     296          10 :         if ((ch = (php_curl *)zend_fetch_resource(Z_RES_P(z_ch), le_curl_name, le_curl)) == NULL) {
     297           0 :                 RETURN_FALSE;
     298             :         }
     299             : 
     300          10 :         if (ch->handlers->write->method == PHP_CURL_RETURN) {
     301           9 :                 if (!ch->handlers->write->buf.s) {
     302           0 :                         RETURN_EMPTY_STRING();
     303             :                 }
     304           9 :                 smart_str_0(&ch->handlers->write->buf);
     305           9 :                 RETURN_STR_COPY(ch->handlers->write->buf.s);
     306             :         }
     307             : 
     308           1 :         RETURN_NULL();
     309             : }
     310             : /* }}} */
     311             : 
     312             : /* {{{ proto array curl_multi_info_read(resource mh [, long msgs_in_queue])
     313             :    Get information about the current transfers */
     314           0 : PHP_FUNCTION(curl_multi_info_read)
     315             : {
     316             :         zval      *z_mh;
     317             :         php_curlm *mh;
     318             :         CURLMsg   *tmp_msg;
     319             :         int        queued_msgs;
     320           0 :         zval      *zmsgs_in_queue = NULL;
     321             : 
     322           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|z/", &z_mh, &zmsgs_in_queue) == FAILURE) {
     323           0 :                 return;
     324             :         }
     325             : 
     326           0 :         if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
     327           0 :                 RETURN_FALSE;
     328             :         }
     329             : 
     330           0 :         tmp_msg = curl_multi_info_read(mh->multi, &queued_msgs);
     331           0 :         if (tmp_msg == NULL) {
     332           0 :                 RETURN_FALSE;
     333             :         }
     334           0 :         if (zmsgs_in_queue) {
     335           0 :                 zval_dtor(zmsgs_in_queue);
     336           0 :                 ZVAL_LONG(zmsgs_in_queue, queued_msgs);
     337             :         }
     338             : 
     339           0 :         array_init(return_value);
     340           0 :         add_assoc_long(return_value, "msg", tmp_msg->msg);
     341           0 :         add_assoc_long(return_value, "result", tmp_msg->data.result);
     342             : 
     343             :         /* find the original easy curl handle */
     344             :         {
     345           0 :                 zval    *pz_ch = _php_curl_multi_find_easy_handle(mh, tmp_msg->easy_handle);
     346           0 :                 if (pz_ch != NULL) {
     347             :                         /* we are adding a reference to the underlying php_curl
     348             :                            resource, so we need to add one to the resource's refcount
     349             :                            in order to ensure it doesn't get destroyed when the
     350             :                            underlying curl easy handle goes out of scope.
     351             :                            Normally you would call zval_copy_ctor( pz_ch ), or
     352             :                            SEPARATE_ZVAL, but those create new zvals, which is already
     353             :                            being done in add_assoc_resource */
     354             :                         Z_ADDREF_P(pz_ch);
     355             : 
     356             :                         /* add_assoc_resource automatically creates a new zval to
     357             :                            wrap the "resource" represented by the current pz_ch */
     358             : 
     359           0 :                         add_assoc_zval(return_value, "handle", pz_ch);
     360             :                 }
     361             :         }
     362             : }
     363             : /* }}} */
     364             : 
     365             : /* {{{ proto void curl_multi_close(resource mh)
     366             :    Close a set of cURL handles */
     367          15 : PHP_FUNCTION(curl_multi_close)
     368             : {
     369             :         zval      *z_mh;
     370             :         php_curlm *mh;
     371             : 
     372          15 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_mh) == FAILURE) {
     373           0 :                 return;
     374             :         }
     375             : 
     376          15 :         if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
     377           0 :                 RETURN_FALSE;
     378             :         }
     379             : 
     380          15 :         zend_list_close(Z_RES_P(z_mh));
     381             : }
     382             : /* }}} */
     383             : 
     384          20 : void _php_curl_multi_close(zend_resource *rsrc) /* {{{ */
     385             : {
     386          20 :         php_curlm *mh = (php_curlm *)rsrc->ptr;
     387          20 :         if (mh) {
     388             :                 zend_llist_position pos;
     389             :                 php_curl *ch;
     390             :                 zval    *pz_ch;
     391             : 
     392          47 :                 for (pz_ch = (zval *)zend_llist_get_first_ex(&mh->easyh, &pos); pz_ch;
     393           7 :                         pz_ch = (zval *)zend_llist_get_next_ex(&mh->easyh, &pos)) {
     394             :                         /* ptr is NULL means it already be freed */
     395           7 :                         if (Z_RES_P(pz_ch)->ptr) {
     396           3 :                                 if ((ch = (php_curl *) zend_fetch_resource(Z_RES_P(pz_ch), le_curl_name, le_curl))) {
     397           3 :                                         _php_curl_verify_handlers(ch, 0);
     398             :                                 }
     399             :                         }
     400             :                 }
     401             : 
     402          20 :                 curl_multi_cleanup(mh->multi);
     403          20 :                 zend_llist_clean(&mh->easyh);
     404          20 :                 if (mh->handlers->server_push) {
     405           0 :                         efree(mh->handlers->server_push);
     406             :                 }
     407          20 :                 if (mh->handlers) {
     408          20 :                         efree(mh->handlers);
     409             :                 }
     410          20 :                 efree(mh);
     411          20 :                 rsrc->ptr = NULL;
     412             :         }
     413          20 : }
     414             : /* }}} */
     415             : 
     416             : /* {{{ proto int curl_multi_errno(resource mh)
     417             :          Return an integer containing the last multi curl error number */
     418           2 : PHP_FUNCTION(curl_multi_errno)
     419             : {
     420             :         zval        *z_mh;
     421             :         php_curlm   *mh;
     422             : 
     423           2 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_mh) == FAILURE) {
     424           0 :                 return;
     425             :         }
     426             : 
     427           2 :         if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
     428           0 :                 RETURN_FALSE;
     429             :         }
     430             : 
     431           2 :         RETURN_LONG(mh->err.no);
     432             : }
     433             : /* }}} */
     434             : 
     435             : #if LIBCURL_VERSION_NUM >= 0x070c00 /* Available since 7.12.0 */
     436             : /* {{{ proto bool curl_multi_strerror(int code)
     437             :          return string describing error code */
     438           4 : PHP_FUNCTION(curl_multi_strerror)
     439             : {
     440             :         zend_long code;
     441             :         const char *str;
     442             : 
     443           4 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &code) == FAILURE) {
     444           0 :                 return;
     445             :         }
     446             : 
     447           4 :         str = curl_multi_strerror(code);
     448           4 :         if (str) {
     449           8 :                 RETURN_STRING(str);
     450             :         } else {
     451           0 :                 RETURN_NULL();
     452             :         }
     453             : }
     454             : /* }}} */
     455             : #endif
     456             : 
     457             : #if LIBCURL_VERSION_NUM >= 0x072C00 /* Available since 7.44.0 */
     458             : 
     459             : static int _php_server_push_callback(CURL *parent_ch, CURL *easy, size_t num_headers, struct curl_pushheaders *push_headers, void *userp) /* {{{ */
     460             : {
     461             :         php_curl                                *ch;
     462             :         php_curl                                *parent;
     463             :         php_curlm                               *mh                     = (php_curlm *)userp;
     464             :         size_t                                  rval                    = CURL_PUSH_DENY;
     465             :         php_curlm_server_push   *t                              = mh->handlers->server_push;
     466             :         zval                                    *pz_parent_ch   = NULL;
     467             :         zval                                    pz_ch;
     468             :         zval                                    headers;
     469             :         zval                                    retval;
     470             :         zend_resource                   *res;
     471             :         char                                    *header;
     472             :         int                                     error;
     473             :         zend_fcall_info                 fci                     = empty_fcall_info;
     474             : 
     475             :         pz_parent_ch = _php_curl_multi_find_easy_handle(mh, parent_ch);
     476             :         if (pz_parent_ch == NULL) {
     477             :                 return rval;
     478             :         }
     479             : 
     480             :         parent = (php_curl*)zend_fetch_resource(Z_RES_P(pz_parent_ch), le_curl_name, le_curl);
     481             : 
     482             :         ch = alloc_curl_handle();
     483             :         ch->cp = easy;
     484             :         _php_setup_easy_copy_handlers(ch, parent);
     485             : 
     486             :         Z_ADDREF_P(pz_parent_ch);
     487             : 
     488             :         res = zend_register_resource(ch, le_curl);
     489             :         ZVAL_RES(&pz_ch, res);
     490             : 
     491             :         size_t i;
     492             :         array_init(&headers);
     493             :         for(i=0; i<num_headers; i++) {
     494             :                 header = curl_pushheader_bynum(push_headers, i);
     495             :                 add_next_index_string(&headers, header);
     496             :         }
     497             : 
     498             :         zend_fcall_info_init(&t->func_name, 0, &fci, &t->fci_cache, NULL, NULL);
     499             : 
     500             :         zend_fcall_info_argn(
     501             :                 &fci, 3,
     502             :                 pz_parent_ch,
     503             :                 &pz_ch,
     504             :                 &headers
     505             :         );
     506             : 
     507             :         fci.retval = &retval;
     508             : 
     509             :         error = zend_call_function(&fci, &t->fci_cache);
     510             :         zend_fcall_info_args_clear(&fci, 1);
     511             :         zval_dtor(&headers);
     512             : 
     513             :         if (error == FAILURE) {
     514             :                 php_error_docref(NULL, E_WARNING, "Cannot call the CURLMOPT_PUSHFUNCTION");
     515             :         } else if (!Z_ISUNDEF(retval)) {
     516             :                 if (CURL_PUSH_DENY != zval_get_long(&retval)) {
     517             :                     rval = CURL_PUSH_OK;
     518             : 
     519             :                         /* we want to create a copy of this zval that we store in the multihandle structure element "easyh" */
     520             :                         zval tmp_val;
     521             :                         ZVAL_DUP(&tmp_val, &pz_ch);
     522             :                         zend_llist_add_element(&mh->easyh, &tmp_val);
     523             :                 } else {
     524             :                         /* libcurl will free this easy handle, avoid double free */
     525             :                         ch->cp = NULL;
     526             :                 }
     527             :         }
     528             : 
     529             :         return rval;
     530             : }
     531             : 
     532             : #endif
     533             : 
     534             : #if LIBCURL_VERSION_NUM >= 0x070f04 /* 7.15.4 */
     535           3 : static int _php_curl_multi_setopt(php_curlm *mh, zend_long option, zval *zvalue, zval *return_value) /* {{{ */
     536             : {
     537           3 :         CURLMcode error = CURLM_OK;
     538             : 
     539           3 :         switch (option) {
     540             : #if LIBCURL_VERSION_NUM >= 0x071000 /* 7.16.0 */
     541             :                 case CURLMOPT_PIPELINING:
     542             : #endif
     543             : #if LIBCURL_VERSION_NUM >= 0x071003 /* 7.16.3 */
     544             :                 case CURLMOPT_MAXCONNECTS:
     545             : #endif
     546             : #if LIBCURL_VERSION_NUM >= 0x071e00 /* 7.30.0 */
     547             :                 case CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE:
     548             :                 case CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE:
     549             :                 case CURLMOPT_MAX_HOST_CONNECTIONS:
     550             :                 case CURLMOPT_MAX_PIPELINE_LENGTH:
     551             :                 case CURLMOPT_MAX_TOTAL_CONNECTIONS:
     552             : #endif
     553           1 :                         error = curl_multi_setopt(mh->multi, option, zval_get_long(zvalue));
     554           1 :                         break;
     555             : #if LIBCURL_VERSION_NUM > 0x072D00 /* Available since 7.46.0 */
     556             :                 case CURLMOPT_PUSHFUNCTION:
     557             :                         if (mh->handlers->server_push == NULL) {
     558             :                                 mh->handlers->server_push = ecalloc(1, sizeof(php_curlm_server_push));
     559             :                         } else if (!Z_ISUNDEF(mh->handlers->server_push->func_name)) {
     560             :                                 zval_ptr_dtor(&mh->handlers->server_push->func_name);
     561             :                                 mh->handlers->server_push->fci_cache = empty_fcall_info_cache;
     562             :                         }
     563             : 
     564             :                         ZVAL_COPY(&mh->handlers->server_push->func_name, zvalue);
     565             :                         mh->handlers->server_push->method = PHP_CURL_USER;
     566             :                         if (!Z_ISUNDEF(mh->handlers->server_push->func_name)) {
     567             :                                 zval_ptr_dtor(&mh->handlers->server_push->func_name);
     568             :                                 mh->handlers->server_push->fci_cache = empty_fcall_info_cache;
     569             : 
     570             :                         }
     571             :                         error = curl_multi_setopt(mh->multi, option, _php_server_push_callback);
     572             :                         if (error != CURLM_OK) {
     573             :                                 return 0;
     574             :                         }
     575             :                         error = curl_multi_setopt(mh->multi, CURLMOPT_PUSHDATA, mh);
     576             :                         break;
     577             : #endif
     578             :                 default:
     579           2 :                         php_error_docref(NULL, E_WARNING, "Invalid curl multi configuration option");
     580           2 :                         error = CURLM_UNKNOWN_OPTION;
     581             :                         break;
     582             :         }
     583             : 
     584           3 :         SAVE_CURLM_ERROR(mh, error);
     585           3 :         if (error != CURLM_OK) {
     586           2 :                 return 1;
     587             :         } else {
     588           1 :                 return 0;
     589             :         }
     590             : }
     591             : /* }}} */
     592             : 
     593             : /* {{{ proto int curl_multi_setopt(resource mh, int option, mixed value)
     594             :        Set an option for the curl multi handle */
     595           3 : PHP_FUNCTION(curl_multi_setopt)
     596             : {
     597             :         zval       *z_mh, *zvalue;
     598             :         zend_long        options;
     599             :         php_curlm *mh;
     600             : 
     601           3 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlz", &z_mh, &options, &zvalue) == FAILURE) {
     602           0 :                 return;
     603             :         }
     604             : 
     605           3 :         if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
     606           0 :                 RETURN_FALSE;
     607             :         }
     608             : 
     609           3 :         if (!_php_curl_multi_setopt(mh, options, zvalue, return_value)) {
     610           1 :                 RETURN_TRUE;
     611             :         } else {
     612           2 :                 RETURN_FALSE;
     613             :         }
     614             : }
     615             : /* }}} */
     616             : #endif
     617             : 
     618             : #endif
     619             : 
     620             : /*
     621             :  * Local variables:
     622             :  * tab-width: 4
     623             :  * c-basic-offset: 4
     624             :  * End:
     625             :  * vim600: noet sw=4 ts=4 fdm=marker
     626             :  * vim<600: noet sw=4 ts=4
     627             :  */

Generated by: LCOV version 1.10

Generated at Tue, 26 Jul 2016 17:07:33 +0000 (2 days ago)

Copyright © 2005-2016 The PHP Group
All rights reserved.