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 - share.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 38 51 74.5 %
Date: 2016-08-28 Functions: 6 7 85.7 %
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: Pierrick Charron <pierrick@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             : 
      35             : #define SAVE_CURLSH_ERROR(__handle, __err) (__handle)->err.no = (int) __err;
      36             : 
      37             : /* {{{ proto void curl_share_init()
      38             :    Initialize a share curl handle */
      39           2 : PHP_FUNCTION(curl_share_init)
      40             : {
      41             :         php_curlsh *sh;
      42             : 
      43           2 :         if (zend_parse_parameters_none() == FAILURE) {
      44           0 :                 return;
      45             :         }
      46             : 
      47           2 :         sh = ecalloc(1, sizeof(php_curlsh));
      48             : 
      49           2 :         sh->share = curl_share_init();
      50             : 
      51           2 :         RETURN_RES(zend_register_resource(sh, le_curl_share_handle));
      52             : }
      53             : /* }}} */
      54             : 
      55             : /* {{{ proto void curl_share_close(resource sh)
      56             :    Close a set of cURL handles */
      57           0 : PHP_FUNCTION(curl_share_close)
      58             : {
      59             :         zval *z_sh;
      60             :         php_curlsh *sh;
      61             : 
      62           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_sh) == FAILURE) {
      63           0 :                 return;
      64             :         }
      65             : 
      66           0 :         if ((sh = (php_curlsh *)zend_fetch_resource(Z_RES_P(z_sh), le_curl_share_handle_name, le_curl_share_handle)) == NULL) {
      67           0 :                 RETURN_FALSE;
      68             :         }
      69             : 
      70           0 :         zend_list_close(Z_RES_P(z_sh));
      71             : }
      72             : /* }}} */
      73             : 
      74           4 : static int _php_curl_share_setopt(php_curlsh *sh, zend_long option, zval *zvalue, zval *return_value) /* {{{ */
      75             : {
      76           4 :         CURLSHcode error = CURLSHE_OK;
      77             : 
      78           4 :         switch (option) {
      79             :                 case CURLSHOPT_SHARE:
      80             :                 case CURLSHOPT_UNSHARE:
      81           2 :                         error = curl_share_setopt(sh->share, option, zval_get_long(zvalue));
      82           2 :                         break;
      83             : 
      84             :                 default:
      85           2 :                         php_error_docref(NULL, E_WARNING, "Invalid curl share configuration option");
      86           2 :                         error = CURLSHE_BAD_OPTION;
      87             :                         break;
      88             :         }
      89             : 
      90           4 :         SAVE_CURLSH_ERROR(sh, error);
      91           4 :         if (error != CURLSHE_OK) {
      92           2 :                 return 1;
      93             :         } else {
      94           2 :                 return 0;
      95             :         }
      96             : }
      97             : /* }}} */
      98             : 
      99             : /* {{{ proto bool curl_share_setopt(resource sh, int option, mixed value)
     100             :       Set an option for a cURL transfer */
     101           4 : PHP_FUNCTION(curl_share_setopt)
     102             : {
     103             :         zval       *zid, *zvalue;
     104             :         zend_long        options;
     105             :         php_curlsh *sh;
     106             : 
     107           4 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlz", &zid, &options, &zvalue) == FAILURE) {
     108           0 :                 return;
     109             :         }
     110             : 
     111           4 :         if ((sh = (php_curlsh *)zend_fetch_resource(Z_RES_P(zid), le_curl_share_handle_name, le_curl_share_handle)) == NULL) {
     112           0 :                 RETURN_FALSE;
     113             :         }
     114             : 
     115           4 :         if (!_php_curl_share_setopt(sh, options, zvalue, return_value)) {
     116           2 :                 RETURN_TRUE;
     117             :         } else {
     118           2 :                 RETURN_FALSE;
     119             :         }
     120             : }
     121             : /* }}} */
     122             : 
     123           2 : void _php_curl_share_close(zend_resource *rsrc) /* {{{ */
     124             : {
     125           2 :         php_curlsh *sh = (php_curlsh *)rsrc->ptr;
     126           2 :         if (sh) {
     127           2 :                 curl_share_cleanup(sh->share);
     128           2 :                 efree(sh);
     129           2 :                 rsrc->ptr = NULL;
     130             :         }
     131           2 : }
     132             : /* }}} */
     133             : 
     134             : /* {{{ proto int curl_share_errno(resource mh)
     135             :          Return an integer containing the last share curl error number */
     136           2 : PHP_FUNCTION(curl_share_errno)
     137             : {
     138             :         zval        *z_sh;
     139             :         php_curlsh  *sh;
     140             : 
     141           2 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_sh) == FAILURE) {
     142           0 :                 return;
     143             :         }
     144             : 
     145           2 :         if ((sh = (php_curlsh *)zend_fetch_resource(Z_RES_P(z_sh), le_curl_share_handle_name, le_curl_share_handle)) == NULL) {
     146           0 :                 RETURN_FALSE;
     147             :         }
     148             : 
     149           2 :         RETURN_LONG(sh->err.no);
     150             : }
     151             : /* }}} */
     152             : 
     153             : 
     154             : #if LIBCURL_VERSION_NUM >= 0x070c00 /* Available since 7.12.0 */
     155             : /* {{{ proto bool curl_share_strerror(int code)
     156             :          return string describing error code */
     157           2 : PHP_FUNCTION(curl_share_strerror)
     158             : {
     159             :         zend_long code;
     160             :         const char *str;
     161             : 
     162           2 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &code) == FAILURE) {
     163           0 :                 return;
     164             :         }
     165             : 
     166           2 :         str = curl_share_strerror(code);
     167           2 :         if (str) {
     168           4 :                 RETURN_STRING(str);
     169             :         } else {
     170           0 :                 RETURN_NULL();
     171             :         }
     172             : }
     173             : /* }}} */
     174             : #endif
     175             : 
     176             : #endif
     177             : 
     178             : /*
     179             :  * Local variables:
     180             :  * tab-width: 4
     181             :  * c-basic-offset: 4
     182             :  * End:
     183             :  * vim600: noet sw=4 ts=4 fdm=marker
     184             :  * vim<600: noet sw=4 ts=4
     185             :  */

Generated by: LCOV version 1.10

Generated at Sun, 28 Aug 2016 17:09:59 +0000 (10 hours ago)

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