share.c 3.5 KB

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