root/ext/curl/share.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. PHP_FUNCTION
  2. PHP_FUNCTION
  3. _php_curl_share_setopt
  4. PHP_FUNCTION
  5. _php_curl_share_close

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

/* [<][>][^][v][top][bottom][index][help] */