dnl DONE
dnl ----
PHP_HTTP_SOURCES="http.c http_functions.c http_methods.c phpstr/phpstr.c \
- http_util_object.c http_message_object.c http_request_object.c http_response_object.c \
+ http_util_object.c http_message_object.c http_request_object.c \
+ http_response_object.c http_exception_object.c \
http_api.c http_auth_api.c http_cache_api.c http_curl_api.c http_date_api.c \
http_headers_api.c http_message_api.c http_send_api.c http_url_api.c"
PHP_NEW_EXTENSION([http], $PHP_HTTP_SOURCES, [$ext_shared])
if (PHP_HTTP != "no") {
EXTENSION("http",
- "http.c http_functions.c http_methods.c "+
+ "http.c http_functions.c http_methods.c http_exception_object.c "+
"http_util_object.c http_message_object.c "+
"http_request_object.c http_response_object.c "+
"http_api.c http_auth_api.c http_cache_api.c "+
# ifdef HTTP_HAVE_CURL
# include "php_http_request_object.h"
# endif
+# include "php_http_exception_object.h"
#endif
#include "phpstr/phpstr.h"
# ifdef HTTP_HAVE_CURL
http_request_object_init(INIT_FUNC_ARGS_PASSTHRU);
# endif /* HTTP_HAVE_CURL */
+ http_exception_object_init(INIT_FUNC_ARGS_PASSTHRU);
#endif /* ZEND_ENGINE_2 */
return SUCCESS;
--- /dev/null
+/*
+ +----------------------------------------------------------------------+
+ | PECL :: http |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.0 of the PHP license, that |
+ | is bundled with this package in the file LICENSE, and is available |
+ | through the world-wide-web at http://www.php.net/license/3_0.txt. |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 2004-2005 Michael Wallner <mike@php.net> |
+ +----------------------------------------------------------------------+
+*/
+
+/* $Id$ */
+
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "php.h"
+
+#include "php_http.h"
+#include "php_http_std_defs.h"
+
+#ifdef ZEND_ENGINE_2
+
+#include "php_http_exception_object.h"
+#include "zend_exceptions.h"
+
+zend_class_entry *http_exception_object_ce;
+zend_function_entry http_exception_object_fe[] = {
+ {NULL, NULL, NULL}
+};
+
+void _http_exception_object_init(INIT_FUNC_ARGS)
+{
+ HTTP_REGISTER_CLASS(HttpException, http_exception_object, zend_exception_get_default(), 0);
+}
+
+zend_class_entry *_http_exception_get_default()
+{
+ return http_exception_object_ce;
+}
+
+void _http_exception_throw_ce_ex(zend_class_entry *ce, int code TSRMLS_DC)
+{
+ static char * const errors[] = {
+ "Unkown Error"
+ };
+
+ if (!ce) {
+ ce = http_exception_get_default();
+ }
+
+ zend_throw_exception(ce, errors[code], code TSRMLS_CC);
+}
+
+#endif
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: noet sw=4 ts=4 fdm=marker
+ * vim<600: noet sw=4 ts=4
+ */
+
#include "php_http_message_object.h"
#include "php_http_response_object.h"
#include "php_http_request_object.h"
+#include "php_http_exception_object.h"
#ifdef ZEND_ENGINE_2
zend_bool do_cache = 0, do_gzip = 0;
getObject(http_response_object, obj);
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|bb", &do_cache, &do_gzip)) {
- // throw exception
- return;
+ SET_EH_THROW_HTTP();
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|bb", &do_cache, &do_gzip)) {
+ UPD_PROP(obj, long, cache, do_cache);
+ UPD_PROP(obj, long, gzip, do_gzip);
}
-
- UPD_PROP(obj, long, cache, do_cache);
- UPD_PROP(obj, long, gzip, do_gzip);
+ SET_EH_NORMAL();
}
/* }}} */
{
zval *message;
getObject(http_message_object, obj);
-
+
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/", &message)) {
return;
}
{
zval *body;
getObject(http_message_object, obj);
-
+
NO_ARGS;
body = GET_PROP(obj, body);
{
zval *headers;
getObject(http_message_object, obj);
-
+
NO_ARGS;
-
+
headers = GET_PROP(obj, headers);
array_init(return_value);
array_copy(headers, return_value);
long meth = -1;
getObject(http_request_object, obj);
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sl", &URL, &URL_len, &meth)) {
- return;
- }
-
- INIT_PARR(obj, options);
- INIT_PARR(obj, responseInfo);
- INIT_PARR(obj, responseData);
- INIT_PARR(obj, postData);
- INIT_PARR(obj, postFiles);
+ SET_EH_THROW_HTTP();
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sl", &URL, &URL_len, &meth)) {
+ INIT_PARR(obj, options);
+ INIT_PARR(obj, responseInfo);
+ INIT_PARR(obj, responseData);
+ INIT_PARR(obj, postData);
+ INIT_PARR(obj, postFiles);
- if (URL) {
- UPD_PROP(obj, string, url, URL);
- }
- if (meth > -1) {
- UPD_PROP(obj, long, method, meth);
+ if (URL) {
+ UPD_PROP(obj, string, url, URL);
+ }
+ if (meth > -1) {
+ UPD_PROP(obj, long, method, meth);
+ }
}
+ SET_EH_NORMAL();
}
/* }}} */
getObject(http_request_object, obj);
NO_ARGS;
+
+ SET_EH_THROW_HTTP();
if ((!obj->ch) && (!(obj->ch = curl_easy_init()))) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not initilaize cURL");
efree(request_uri);
/* final data handling */
- if (status != SUCCESS) {
- RETURN_FALSE;
- } else {
+ if (status == SUCCESS) {
char *body = NULL;
size_t body_len = 0;
zval *zheaders;
RETURN_TRUE;
}
- /* */
+
+ SET_EH_NORMAL();
+ RETURN_SUCCESS(status);
}
/* }}} */
/* }}} */
<file role="src">php_http_message_object.h</file>
<file role="src">php_http_request_object.h</file>
<file role="src">php_http_response_object.h</file>
+ <file role="src">php_http_exception_object.h</file>
<file role="src">http.c</file>
<file role="src">http_functions.c</file>
<file role="src">http_message_object.c</file>
<file role="src">http_request_object.c</file>
<file role="src">http_response_object.c</file>
+ <file role="src">http_exception_object.c</file>
</dir>
</filelist>
--- /dev/null
+/*
+ +----------------------------------------------------------------------+
+ | PECL :: http |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.0 of the PHP license, that |
+ | is bundled with this package in the file LICENSE, and is available |
+ | through the world-wide-web at http://www.php.net/license/3_0.txt. |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 2004-2005 Michael Wallner <mike@php.net> |
+ +----------------------------------------------------------------------+
+*/
+
+/* $Id$ */
+
+#ifndef PHP_HTTP_EXCEPTION_OBJECT_H
+#define PHP_HTTP_EXCEPTION_OBJECT_H
+#ifdef ZEND_ENGINE_2
+
+extern zend_class_entry *http_exception_object_ce;
+extern zend_function_entry http_exception_object_fe[];
+
+#define http_exception_object_init _http_exception_object_init
+extern void _http_exception_object_init(INIT_FUNC_ARGS);
+
+#define http_exception_get_default _http_exception_get_default
+extern zend_class_entry *_http_exception_get_default();
+
+#define http_exception_throw() http_exception_throw_ex(0)
+#define http_exception_throw_ex(code) http_exception_throw_ce_ex(NULL, code)
+#define http_exception_throw_ce(ce) http_exception_throw_ce_ex(ce, 0)
+#define http_exception_throw_ce_ex(ce, code) _http_exception_throw_ce_ex(ce, code TSRMLS_CC)
+extern void _http_exception_throw_ce_ex(zend_class_entry *ce, int code TSRMLS_DC);
+
+#define HTTP_E_UNKOWN 0
+
+#endif
+#endif
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: noet sw=4 ts=4 fdm=marker
+ * vim<600: noet sw=4 ts=4
+ */
+
} \
}
+# define SET_EH_THROW() SET_EH_THROW_EX(zend_exception_get_default())
+# define SET_EH_THROW_HTTP() SET_EH_THROW_EX(http_exception_get_default())
+# define SET_EH_THROW_EX(ex) php_set_error_handling(EH_THROW, ex TSRMLS_CC)
+# define SET_EH_NORMAL() php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC)
+
#endif /* ZEND_ENGINE_2 */
/* }}} */