]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch '0.9.x' of git@gitorious.org:statusnet/mainline into 0.9.x
authorEvan Prodromou <evan@status.net>
Wed, 16 Sep 2009 02:19:19 +0000 (22:19 -0400)
committerEvan Prodromou <evan@status.net>
Wed, 16 Sep 2009 02:19:19 +0000 (22:19 -0400)
classes/Config.php [changed mode: 0755->0644]
classes/Deleted_notice.php [changed mode: 0755->0644]
classes/statusnet.ini [changed mode: 0755->0644]
lib/common.php
lib/curlclient.php [new file with mode: 0644]
lib/httpclient.php [new file with mode: 0644]
plugins/OpenID/OpenIDPlugin.php

old mode 100755 (executable)
new mode 100644 (file)
index 5bec13f..92f237d
@@ -17,7 +17,9 @@
  * along with this program.     If not, see <http://www.gnu.org/licenses/>.
  */
 
-if (!defined('LACONICA')) { exit(1); }
+if (!defined('STATUSNET')) {
+    exit(1);
+}
 
 /**
  * Table Definition for config
old mode 100755 (executable)
new mode 100644 (file)
index 474d0b6..64dc85d
@@ -17,7 +17,9 @@
  * along with this program.     If not, see <http://www.gnu.org/licenses/>.
  */
 
-if (!defined('LACONICA')) { exit(1); }
+if (!defined('STATUSNET')) {
+    exit(1);
+}
 
 /**
  * Table Definition for notice
old mode 100755 (executable)
new mode 100644 (file)
index 3b21b548cf9ef81ca0cb689b6bfd879e08117a90..194eb568f7d1a0ff2b7525599fd196443ee0bd78 100644 (file)
@@ -284,6 +284,8 @@ $config =
         array('contentlimit' => null),
         'message' =>
         array('contentlimit' => null),
+        'http' =>
+        array('client' => 'curl'), // XXX: should this be the default?
         );
 
 $config['db'] = &PEAR::getStaticProperty('DB_DataObject','options');
diff --git a/lib/curlclient.php b/lib/curlclient.php
new file mode 100644 (file)
index 0000000..c43bfb5
--- /dev/null
@@ -0,0 +1,179 @@
+n<?php
+/**
+ * Laconica, the distributed open-source microblogging tool
+ *
+ * Utility class for wrapping Curl
+ *
+ * PHP version 5
+ *
+ * LICENCE: This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category  HTTP
+ * @package   Laconica
+ * @author    Evan Prodromou <evan@status.net>
+ * @copyright 2009 StatusNet, Inc.
+ * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link      http://laconi.ca/
+ */
+
+if (!defined('STATUSNET')) {
+    exit(1);
+}
+
+define(CURLCLIENT_VERSION, "0.1");
+
+/**
+ * Wrapper for Curl
+ *
+ * Makes Curl HTTP client calls within our HTTPClient framework
+ *
+ * @category HTTP
+ * @package  Laconica
+ * @author   Evan Prodromou <evan@status.net>
+ * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link     http://laconi.ca/
+ */
+
+class CurlClient extends HTTPClient
+{
+    function __construct()
+    {
+    }
+
+    function head($url, $headers=null)
+    {
+        $ch = curl_init($url);
+
+        $this->setup($ch);
+
+        curl_setopt_array($ch,
+                          array(CURLOPT_NOBODY => true));
+
+        if (!is_null($headers)) {
+            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
+        }
+
+        $result = curl_exec($ch);
+
+        curl_close($ch);
+
+        return $this->parseResults($result);
+    }
+
+    function get($url, $headers=null)
+    {
+        $ch = curl_init($url);
+
+        $this->setup($ch);
+
+        if (!is_null($headers)) {
+            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
+        }
+
+        $result = curl_exec($ch);
+
+        curl_close($ch);
+
+        return $this->parseResults($result);
+    }
+
+    function post($url, $headers=null, $body=null)
+    {
+        $ch = curl_init($url);
+
+        $this->setup($ch);
+
+        curl_setopt($ch, CURLOPT_POST, true);
+
+        if (!is_null($body)) {
+            curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
+        }
+
+        if (!is_null($headers)) {
+            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
+        }
+
+        $result = curl_exec($ch);
+
+        curl_close($ch);
+
+        return $this->parseResults($result);
+    }
+
+    function setup($ch)
+    {
+        curl_setopt_array($ch,
+                          array(CURLOPT_USERAGENT => $this->userAgent(),
+                                CURLOPT_HEADER => true,
+                                CURLOPT_RETURNTRANSFER => true));
+    }
+
+    function userAgent()
+    {
+        $version = curl_version();
+        return parent::userAgent() . " CurlClient/".CURLCLIENT_VERSION . " cURL/" . $version['version'];
+    }
+
+    function parseResults($results)
+    {
+        $resp = new HTTPResponse();
+
+        $lines = explode("\r\n", $results);
+
+        if (preg_match("#^HTTP/1.[01] (\d\d\d) .+$#", $lines[0], $match)) {
+            $resp->code = $match[1];
+        } else {
+            throw Exception("Bad format: initial line is not HTTP status line");
+        }
+
+        $lastk = null;
+
+        for ($i = 1; $i < count($lines); $i++) {
+            $l =& $lines[$i];
+            if (mb_strlen($l) == 0) {
+                $resp->body = implode("\r\n", array_slice($lines, $i + 1));
+                break;
+            }
+            if (preg_match("#^(\S+):\s+(.*)$#", $l, $match)) {
+                $k = $match[1];
+                $v = $match[2];
+
+                if (array_key_exists($k, $resp->headers)) {
+                    if (is_array($resp->headers[$k])) {
+                        $resp->headers[$k][] = $v;
+                    } else {
+                        $resp->headers[$k] = array($resp->headers[$k], $v);
+                    }
+                } else {
+                    $resp->headers[$k] = $v;
+                }
+                $lastk = $k;
+            } else if (preg_match("#^\s+(.*)$#", $l, $match)) {
+                // continuation line
+                if (is_null($lastk)) {
+                    throw Exception("Bad format: initial whitespace in headers");
+                }
+                $h =& $resp->headers[$lastk];
+                if (is_array($h)) {
+                    $n = count($h);
+                    $h[$n-1] .= $match[1];
+                } else {
+                    $h .= $match[1];
+                }
+            }
+        }
+
+        return $resp;
+    }
+}
diff --git a/lib/httpclient.php b/lib/httpclient.php
new file mode 100644 (file)
index 0000000..9b0bb6f
--- /dev/null
@@ -0,0 +1,122 @@
+<?php
+/**
+ * Laconica, the distributed open-source microblogging tool
+ *
+ * Utility for doing HTTP-related things
+ *
+ * PHP version 5
+ *
+ * LICENCE: This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category  Action
+ * @package   Laconica
+ * @author    Evan Prodromou <evan@controlyourself.ca>
+ * @copyright 2009 Control Yourself, Inc.
+ * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link      http://laconi.ca/
+ */
+
+if (!defined('STATUSNET')) {
+    exit(1);
+}
+
+/**
+ * Useful structure for HTTP responses
+ *
+ * We make HTTP calls in several places, and we have several different
+ * ways of doing them. This class hides the specifics of what underlying
+ * library (curl or PHP-HTTP or whatever) that's used.
+ *
+ * @category HTTP
+ * @package  Laconica
+ * @author   Evan Prodromou <evan@controlyourself.ca>
+ * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link     http://laconi.ca/
+ */
+
+class HTTPResponse
+{
+    public $code = null;
+    public $headers = null;
+    public $body = null;
+}
+
+/**
+ * Utility class for doing HTTP client stuff
+ *
+ * We make HTTP calls in several places, and we have several different
+ * ways of doing them. This class hides the specifics of what underlying
+ * library (curl or PHP-HTTP or whatever) that's used.
+ *
+ * @category HTTP
+ * @package  Laconica
+ * @author   Evan Prodromou <evan@controlyourself.ca>
+ * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link     http://laconi.ca/
+ */
+
+class HTTPClient
+{
+    static $_client = null;
+
+    static function start()
+    {
+        if (!is_null(self::$_client)) {
+            return self::$_client;
+        }
+
+        $type = common_config('http', 'client');
+
+        switch ($type) {
+         case 'curl':
+            self::$_client = new CurlClient();
+            break;
+         default:
+            throw new Exception("Unknown HTTP client type '$type'");
+            break;
+        }
+
+        return self::$_client;
+    }
+
+    function head($url, $headers)
+    {
+        throw new Exception("HEAD method unimplemented");
+    }
+
+    function get($url, $headers)
+    {
+        throw new Exception("GET method unimplemented");
+    }
+
+    function post($url, $headers, $body)
+    {
+        throw new Exception("POST method unimplemented");
+    }
+
+    function put($url, $headers, $body)
+    {
+        throw new Exception("PUT method unimplemented");
+    }
+
+    function delete($url, $headers)
+    {
+        throw new Exception("DELETE method unimplemented");
+    }
+
+    function userAgent()
+    {
+        return "StatusNet/".STATUSNET_VERSION." (".STATUSNET_CODENAME.")";
+    }
+}
index eb450fc5e5e29f73f840649df04419dbf7dd72ec..91bddf381f4f989ee41362eb83fdba083feea173 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * Laconica, the distributed open-source microblogging tool
+ * StatusNet, the distributed open-source microblogging tool
  *
  * PHP version 5
  *
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  * @category  Plugin
- * @package   Laconica
- * @author    Evan Prodromou <evan@controlyourself.ca>
- * @copyright 2009 Control Yourself, Inc.
+ * @package   StatusNet
+ * @author    Evan Prodromou <evan@status.net>
+ * @copyright 2009 StatusNet, Inc.
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link      http://laconi.ca/
+ * @link      http://status.net/
  */
 
-if (!defined('LACONICA')) {
+if (!defined('STATUSNET')) {
     exit(1);
 }
 
@@ -36,10 +36,10 @@ if (!defined('LACONICA')) {
  * and identity system.
  *
  * @category Plugin
- * @package  Laconica
- * @author   Evan Prodromou <evan@controlyourself.ca>
+ * @package  StatusNet
+ * @author   Evan Prodromou <evan@status.net>
  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link     http://laconi.ca/
+ * @link     http://status.net/
  * @link     http://openid.net/
  */