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: 29 38 76.3 %
Date: 2015-03-01 Functions: 4 5 80.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 7                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1997-2015 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             : /* {{{ proto void curl_share_init()
      36             :    Initialize a share curl handle */
      37           1 : PHP_FUNCTION(curl_share_init)
      38             : {
      39             :         php_curlsh *sh;
      40             : 
      41           1 :         if (zend_parse_parameters_none() == FAILURE) {
      42           0 :                 return;
      43             :         }
      44             : 
      45           1 :         sh = ecalloc(1, sizeof(php_curlsh));
      46             : 
      47           1 :         sh->share = curl_share_init();
      48             : 
      49           1 :         RETURN_RES(zend_register_resource(sh, le_curl_share_handle));
      50             : }
      51             : /* }}} */
      52             : 
      53             : /* {{{ proto void curl_share_close(resource sh)
      54             :    Close a set of cURL handles */
      55           0 : PHP_FUNCTION(curl_share_close)
      56             : {
      57             :         zval *z_sh;
      58             :         php_curlsh *sh;
      59             : 
      60           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_sh) == FAILURE) {
      61           0 :                 return;
      62             :         }
      63             : 
      64           0 :         if ((sh = (php_curlsh *)zend_fetch_resource(Z_RES_P(z_sh), le_curl_share_handle_name, le_curl_share_handle)) == NULL) {
      65           0 :                 RETURN_FALSE;
      66             :         }
      67             : 
      68           0 :         zend_list_close(Z_RES_P(z_sh));
      69             : }
      70             : /* }}} */
      71             : 
      72           3 : static int _php_curl_share_setopt(php_curlsh *sh, zend_long option, zval *zvalue, zval *return_value) /* {{{ */
      73             : {
      74           3 :         CURLSHcode error = CURLSHE_OK;
      75             : 
      76           3 :         switch (option) {
      77             :                 case CURLSHOPT_SHARE:
      78             :                 case CURLSHOPT_UNSHARE:
      79           2 :                         convert_to_long_ex(zvalue);
      80           2 :                         error = curl_share_setopt(sh->share, option, Z_LVAL_P(zvalue));
      81           2 :                         break;
      82             : 
      83             :                 default:
      84           1 :                         php_error_docref(NULL, E_WARNING, "Invalid curl share configuration option");
      85           1 :                         error = CURLSHE_BAD_OPTION;
      86             :                         break;
      87             :         }
      88             : 
      89           3 :         if (error != CURLSHE_OK) {
      90           1 :                 return 1;
      91             :         } else {
      92           2 :                 return 0;
      93             :         }
      94             : }
      95             : /* }}} */
      96             : 
      97             : /* {{{ proto bool curl_share_setopt(resource sh, int option, mixed value)
      98             :       Set an option for a cURL transfer */
      99           3 : PHP_FUNCTION(curl_share_setopt)
     100             : {
     101             :         zval       *zid, *zvalue;
     102             :         zend_long        options;
     103             :         php_curlsh *sh;
     104             : 
     105           3 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlz", &zid, &options, &zvalue) == FAILURE) {
     106           0 :                 return;
     107             :         }
     108             : 
     109           3 :         if ((sh = (php_curlsh *)zend_fetch_resource(Z_RES_P(zid), le_curl_share_handle_name, le_curl_share_handle)) == NULL) {
     110           0 :                 RETURN_FALSE;
     111             :         }
     112             : 
     113           3 :         if (!_php_curl_share_setopt(sh, options, zvalue, return_value)) {
     114           2 :                 RETURN_TRUE;
     115             :         } else {
     116           1 :                 RETURN_FALSE;
     117             :         }
     118             : }
     119             : /* }}} */
     120             : 
     121           1 : void _php_curl_share_close(zend_resource *rsrc) /* {{{ */
     122             : {
     123           1 :         php_curlsh *sh = (php_curlsh *)rsrc->ptr;
     124           1 :         if (sh) {
     125           1 :                 curl_share_cleanup(sh->share);
     126           1 :                 efree(sh);
     127           1 :                 rsrc->ptr = NULL;
     128             :         }
     129           1 : }
     130             : /* }}} */
     131             : 
     132             : #endif
     133             : 
     134             : /*
     135             :  * Local variables:
     136             :  * tab-width: 4
     137             :  * c-basic-offset: 4
     138             :  * End:
     139             :  * vim600: noet sw=4 ts=4 fdm=marker
     140             :  * vim<600: noet sw=4 ts=4
     141             :  */

Generated by: LCOV version 1.10

Generated at Sun, 01 Mar 2015 23:22:23 +0000 (4 hours ago)

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