From fa02a091072e74a2468cfc34f9e38ce1c9ea5196 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 23 Jun 2016 20:05:57 -0700 Subject: SuperCurl to provide a re-usable curl options stack and just change options that are different from one call to the next --- Zotlabs/Lib/SuperCurl.php | 112 +++++++++++++++++++++++++++++++++++++++ Zotlabs/Storage/CalDAVClient.php | 1 - 2 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 Zotlabs/Lib/SuperCurl.php (limited to 'Zotlabs') diff --git a/Zotlabs/Lib/SuperCurl.php b/Zotlabs/Lib/SuperCurl.php new file mode 100644 index 000000000..40ca1addb --- /dev/null +++ b/Zotlabs/Lib/SuperCurl.php @@ -0,0 +1,112 @@ +request_data = $s; + $this->filepos = 0; + } + + public function curl_read($ch,$fh,$size) { + + if($this->filepos < 0) { + unset($fh); + return ''; + } + + $s = substr($this->request_data,$this->filepos,$size); + + if(strlen($s) < $size) + $this->filepos = (-1); + else + $this->filepos = $this->filepos + $size; + + return $s; + } + + + public function __construct($opts = array()) { + $this->set($opts); + } + + private function set($opts = array()) { + if($opts) { + foreach($opts as $k => $v) { + switch($k) { + case 'http_auth': + $this->auth = $v; + break; + case 'custom': + $this->request_method = $v; + break; + case 'url': + $this->url = $v; + break; + case 'data': + $this->set_data($v); + if($v) { + $this->upload = true; + } + else { + $this->upload = false; + } + break; + case 'headers': + $this->headers = $v; + break; + default: + $this->curlopts[$k] = $v; + break; + } + } + } + } + + function exec() { + $opts = $this->curlopts; + if($this->auth) + $opts['http_auth'] = $this->auth; + if($this->custom) + $opts['custom'] = $this->custom; + if($this->headers) + $opts['headers'] = $this->headers; + if($this->upload) { + $opts['upload'] = true; + $opts['infile'] = $this->filehandle; + $opts['infilesize'] = strlen($this->request_data); + $opts['readfunc'] = [ $this, 'curl_read' ] ; + } + + $recurse = 0; + return z_fetch_url($this->url,true,$recurse,(($opts) ? $opts : null)); + + } + + +} diff --git a/Zotlabs/Storage/CalDAVClient.php b/Zotlabs/Storage/CalDAVClient.php index 76c59c569..c1a8db932 100644 --- a/Zotlabs/Storage/CalDAVClient.php +++ b/Zotlabs/Storage/CalDAVClient.php @@ -45,7 +45,6 @@ class CalDAVClient { } private function set_data($s) { - logger('set data called'); $this->request_data = $s; $this->filepos = 0; } -- cgit v1.2.3