IF_RETVAL_USED {
getObject(http_message_object, obj);
-
- if (!HTTP_MSG_TYPE(RESPONSE, obj->message)) {
- http_error(HE_NOTICE, HTTP_E_MESSAGE_TYPE, "HttpMessage is not of type HTTP_MSG_RESPONSE");
- RETURN_FALSE;
- }
-
+ HTTP_CHECK_MESSAGE_TYPE_RESPONSE(obj->message, RETURN_FALSE);
RETURN_LONG(obj->message->http.info.response.code);
}
}
long code;
getObject(http_message_object, obj);
- if (!HTTP_MSG_TYPE(RESPONSE, obj->message)) {
- http_error(HE_WARNING, HTTP_E_MESSAGE_TYPE, "HttpMessage is not of type HTTP_MSG_RESPONSE");
- RETURN_FALSE;
- }
+ HTTP_CHECK_MESSAGE_TYPE_RESPONSE(obj->message, RETURN_FALSE);
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &code)) {
RETURN_FALSE;
IF_RETVAL_USED {
getObject(http_message_object, obj);
-
- if (!HTTP_MSG_TYPE(REQUEST, obj->message)) {
- http_error(HE_NOTICE, HTTP_E_MESSAGE_TYPE, "HttpMessage is not of type HTTP_MSG_REQUEST");
- RETURN_FALSE;
- }
-
+ HTTP_CHECK_MESSAGE_TYPE_REQUEST(obj->message, RETURN_FALSE);
RETURN_STRING(obj->message->http.info.request.method, 1);
}
}
int method_len;
getObject(http_message_object, obj);
- if (!HTTP_MSG_TYPE(REQUEST, obj->message)) {
- http_error(HE_WARNING, HTTP_E_MESSAGE_TYPE, "HttpMessage is not of type HTTP_MSG_REQUEST");
- RETURN_FALSE;
- }
+ HTTP_CHECK_MESSAGE_TYPE_REQUEST(obj->message, RETURN_FALSE);
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &method, &method_len)) {
RETURN_FALSE;
IF_RETVAL_USED {
getObject(http_message_object, obj);
-
- if (!HTTP_MSG_TYPE(REQUEST, obj->message)) {
- http_error(HE_WARNING, HTTP_E_MESSAGE_TYPE, "HttpMessage is not of type HTTP_MSG_REQUEST");
- RETURN_FALSE;
- }
-
+ HTTP_CHECK_MESSAGE_TYPE_REQUEST(obj->message, RETURN_FALSE);
RETURN_STRING(obj->message->http.info.request.URI, 1);
}
}
int URIlen;
getObject(http_message_object, obj);
- if (!HTTP_MSG_TYPE(REQUEST, obj->message)) {
- http_error(HE_WARNING, HTTP_E_MESSAGE_TYPE, "HttpMessage is not of type HTTP_MSG_REQUEST");
- RETURN_FALSE;
- }
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &URI, &URIlen)) {
RETURN_FALSE;
}
+ HTTP_CHECK_MESSAGE_TYPE_REQUEST(obj->message, RETURN_FALSE);
if (URIlen < 1) {
http_error(HE_WARNING, HTTP_E_INVALID_PARAM, "Cannot set HttpMessage::requestUri to an empty string");
RETURN_FALSE;
PHP_HTTP_API STATUS _http_request_ex(CURL *ch, http_request_method meth, char *url, http_request_body *body, HashTable *options, HashTable *info, phpstr *response TSRMLS_DC)
{
STATUS status;
- zend_bool clean_curl;
+ zend_bool clean_curl = !ch;
- if ((clean_curl = (!ch))) {
- if (!(ch = curl_easy_init())) {
- http_error(HE_WARNING, HTTP_E_REQUEST, "Could not initialize curl.");
- return FAILURE;
- }
- }
+ HTTP_CHECK_CURL_INIT(ch, curl_easy_init(), return FAILURE);
status = ((SUCCESS == http_request_init(ch, meth, url, body, options)) &&
(SUCCESS == http_request_exec(ch, info, response, NULL))) ? SUCCESS : FAILURE;
if (!body) {
return FAILURE;
}
- if ((!obj->ch) && (!(obj->ch = curl_easy_init()))) {
- http_error(HE_WARNING, HTTP_E_REQUEST, "Could not initilaize curl");
- return FAILURE;
- }
+ HTTP_CHECK_CURL_INIT(obj->ch, curl_easy_init(), return FAILURE);
URL = convert_to_type_ex(IS_STRING, GET_PROP(obj, url));
// HTTP_URI_MAXLEN+1 long char *
RETURN_FALSE;
}
- if (!strchr(ctype, '/')) {
- http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Content-Type '%s' doesn't seem to contain a primary and a secondary part", ctype);
- RETURN_FALSE;
- }
-
+ HTTP_CHECK_CONTENT_TYPE(ctype, RETURN_FALSE);
UPD_STRL(obj, contentType, ctype, ct_len);
RETURN_TRUE;
}
}
if (type_len) {
- if (!strchr(type, '/')) {
- http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Content-Type '%s' doesn't seem to contain a primary and a secondary part", type);
- RETURN_FALSE;
- }
+ HTTP_CHECK_CONTENT_TYPE(type, RETURN_FALSE);
} else {
type = "application/x-octetstream";
type_len = sizeof("application/x-octetstream") - 1;
pool->ch = NULL;
}
+ HTTP_CHECK_CURL_INIT(pool->ch, curl_multi_init(), ;);
if (!pool->ch) {
- if (!(pool->ch = curl_multi_init())) {
- http_error(HE_WARNING, HTTP_E_REQUEST, "Could not initialize curl");
- if (free_pool) {
- efree(pool);
- }
- return NULL;
+ if (free_pool) {
+ efree(pool);
}
+ return NULL;
}
pool->unfinished = 0;
RETURN_FALSE;
}
- if (!strchr(ctype, '/')) {
- http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Content type '%s' doesn't seem to contain a primary and a secondary part", ctype);
- RETURN_FALSE;
- }
-
+ HTTP_CHECK_CONTENT_TYPE(ctype, RETURN_FALSE);
RETURN_SUCCESS(UPD_STATIC_STRL(contentType, ctype, ctype_len));
}
/* }}} */
/* {{{ STATUS http_send_content_type(char *, size_t) */
PHP_HTTP_API STATUS _http_send_content_type(const char *content_type, size_t ct_len TSRMLS_DC)
{
- if (!strchr(content_type, '/')) {
- http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Content-Type '%s' doesn't seem to consist of a primary and a secondary part", content_type);
- return FAILURE;
- }
+ HTTP_CHECK_CONTENT_TYPE(content_type, return FAILURE);
/* remember for multiple ranges */
STR_FREE(HTTP_G(send).content_type);
#define http_error_ex _http_error_ex
extern void _http_error_ex(long type TSRMLS_DC, long code, const char *format, ...);
+#define HTTP_CHECK_CURL_INIT(ch, init, action) \
+ if ((!(ch)) && (!((ch) = init))) { \
+ http_error(HE_WARNING, HTTP_E_REQUEST, "Could not initialize curl"); \
+ action; \
+ }
+#define HTTP_CHECK_CONTENT_TYPE(ct, action) \
+ if (!strchr((ct), '/')) { \
+ http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, \
+ "Content type \"%s\" does not seem to contain a primary and a secondary part", (ct)); \
+ action; \
+ }
+#define HTTP_CHECK_MESSAGE_TYPE_RESPONSE(msg, action) \
+ if (!HTTP_MSG_TYPE(RESPONSE, (msg))) { \
+ http_error(HE_NOTICE, HTTP_E_MESSAGE_TYPE, "HttpMessage is not of type HTTP_MSG_RESPONSE"); \
+ action; \
+ }
+#define HTTP_CHECK_MESSAGE_TYPE_REQUEST(msg, action) \
+ if (!HTTP_MSG_TYPE(REQUEST, (msg))) { \
+ http_error(HE_NOTICE, HTTP_E_MESSAGE_TYPE, "HttpMessage is not of type HTTP_MSG_REQUEST"); \
+ action; \
+ }
+
+
#define http_log(f, i, m) _http_log_ex((f), (i), (m) TSRMLS_CC)
extern void http_log_ex(char *file, const char *ident, const char *message TSRMLS_DC);