[prev in list] [next in list] [prev in thread] [next in thread]
List: pecl-cvs
Subject: [PECL-CVS] com =?UTF-8?Q?pecl/search=5Fengine/solr=3A=20Solr=20Extract=20Request=20?= =?UTF-8?Q?=28p
From: Omar Shaban <omars () php ! net>
Date: 2016-09-24 9:00:48
Message-ID: php-mail-5fe393e91dba7b2ba2331b749fded07b361189357 () git ! php ! net
[Download RAW message or body]
Commit: c10e08d8aa9c6df6a126b414dac2dc83f94d12b6
Author: Omar Shaban <omars@php.net> Sat, 24 Sep 2016 11:00:48 +0200
Parents: 72c2b7ad23891c0386c6529fa719f98dcf8a699c
Branches: feature/update-stream-request-php5
Link: http://git.php.net/?p=pecl/search_engine/solr.git;a=commitdiff;h=c10e08d8aa9c6df6a126b414dac2dc83f94d12b6
Log:
Solr Extract Request (php5)
Changed paths:
M src/php5/php_solr.c
M src/php5/php_solr.h
M src/php5/php_solr_client.c
A src/php5/php_solr_extract.c
M src/php5/solr_constants.h
M src/php5/solr_functions_client.c
M src/php5/solr_functions_helpers.c
M src/php5/solr_functions_params.c
M src/php5/solr_macros.h
M src/php5/solr_types.h
["diff_c10e08d8aa9c6df6a126b414dac2dc83f94d12b6.txt" (text/plain)]
diff --git a/src/php5/php_solr.c b/src/php5/php_solr.c
index 6efc4de..94ca20e 100644
--- a/src/php5/php_solr.c
+++ b/src/php5/php_solr.c
@@ -1217,7 +1217,7 @@ PHP_MINIT_FUNCTION(solr)
solr_ce_SolrExtractRequest->create_object = solr_extract_create_object_handler;
zend_declare_property_long(solr_ce_SolrExtractRequest, SOLR_INDEX_PROPERTY_NAME, \
sizeof(SOLR_INDEX_PROPERTY_NAME)-1, 0L, ZEND_ACC_PRIVATE TSRMLS_CC);
- zend_declare_property_null(solr_ce_SolrExtractRequest, "params", \
sizeof("params")-1, ZEND_ACC_PRIVATE); \
+ zend_declare_property_null(solr_ce_SolrExtractRequest, "params", \
sizeof("params")-1, ZEND_ACC_PRIVATE TSRMLS_CC); \
solr_extract_register_class_constants(solr_ce_SolrExtractRequest TSRMLS_CC);
/* Register the SolrCollapseFunction class */
diff --git a/src/php5/php_solr.h b/src/php5/php_solr.h
index cbcc5d6..190803f 100644
--- a/src/php5/php_solr.h
+++ b/src/php5/php_solr.h
@@ -215,6 +215,16 @@ PHP_METHOD(SolrDocument, getInputDocument);
PHP_METHOD(SolrDocument, hasChildDocuments);
PHP_METHOD(SolrDocument, getChildDocuments);
PHP_METHOD(SolrDocument, getChildDocumentsCount);
+/* }}} */
+
+/* {{{ SolrExtractRequest methods */
+PHP_METHOD(SolrExtractRequest, __construct);
+PHP_METHOD(SolrExtractRequest, createFromFile);
+PHP_METHOD(SolrExtractRequest, createFromStream);
+PHP_METHOD(SolrExtractRequest, __destruct);
+PHP_METHOD(SolrExtractRequest, __clone);
+PHP_METHOD(SolrExtractRequest, __sleep);
+PHP_METHOD(SolrExtractRequest, __wakeup);
/* }}} */
@@ -267,6 +277,7 @@ PHP_METHOD(SolrClient, addDocuments);
PHP_METHOD(SolrClient, setServlet);
PHP_METHOD(SolrClient, setResponseWriter);
PHP_METHOD(SolrClient, request);
+PHP_METHOD(SolrClient, sendUpdateStream);
PHP_METHOD(SolrClient, ping);
PHP_METHOD(SolrClient, system);
PHP_METHOD(SolrClient, threads);
@@ -617,6 +628,7 @@ int solr_curl_debug_callback(CURL *curl_handle, curl_infotype \
infotype, solr_cha PHP_SOLR_API int solr_init_options(solr_client_options_t *options \
TSRMLS_DC); PHP_SOLR_API int solr_init_handle(solr_curl_t *sch, \
solr_client_options_t *options TSRMLS_DC); PHP_SOLR_API int \
solr_make_request(solr_client_t *client, solr_request_type_t request_type TSRMLS_DC); \
+PHP_SOLR_API int solr_make_update_stream_request(solr_client_t *client, \
solr_ustream_t* stream_data, solr_string_t *request_params TSRMLS_DC); PHP_SOLR_API \
void solr_free_handle(solr_curl_t *sch); PHP_SOLR_API void \
solr_free_option(solr_client_options_t *options);
@@ -624,6 +636,7 @@ PHP_SOLR_API void solr_free_option(solr_client_options_t \
*options);
PHP_SOLR_API void solr_extension_register_constants(int type, int module_number \
TSRMLS_DC); PHP_SOLR_API void \
solr_document_register_class_constants(zend_class_entry *ce TSRMLS_DC); +PHP_SOLR_API \
void solr_extract_register_class_constants(zend_class_entry *ce TSRMLS_DC); \
PHP_SOLR_API void solr_client_register_class_constants(zend_class_entry *ce \
TSRMLS_DC); PHP_SOLR_API void solr_query_register_class_constants(zend_class_entry \
*ce TSRMLS_DC); PHP_SOLR_API void \
solr_collapse_function_register_class_constants(zend_class_entry *ce TSRMLS_DC); @@ \
-638,8 +651,21 @@ PHP_SOLR_API void solr_throw_solr_server_exception(solr_client_t \
*client,const c /* {{{ zval reference count post increment and decrement functions \
++ and -- */ PHP_SOLR_API void solr_zval_add_ref(zval **p);
PHP_SOLR_API void solr_zval_minus_ref(zval **p);
+
+zend_object_value solr_extract_create_object_handler(zend_class_entry *ce \
TSRMLS_DC); +static void solr_extract_free_object_handler(solr_ustream_t *intern \
TSRMLS_DC); /* }}} */
+PHP_SOLR_API void solr_destroy_ustream_ex(solr_ustream_t *stream);
+PHP_SOLR_API void solr_destroy_ustream_zv(zval *obj TSRMLS_DC);
+PHP_SOLR_API int solr_fetch_ustream_entry(zval *objptr, solr_ustream_t \
**stream_entry TSRMLS_DC); +
+#ifdef PHP_7
+ #define solr_destroy_ustream solr_destroy_ustream_zv
+#else
+ #define solr_destroy_ustream solr_destroy_ustream_ex
+#endif
+
/* {{{ zend_hash_free functions */
PHP_SOLR_API void solr_destroy_field_list(solr_field_list_t **field_entry_ptr);
PHP_SOLR_API void solr_destroy_document(void *document);
diff --git a/src/php5/php_solr_client.c b/src/php5/php_solr_client.c
index 68d8456..b8be3c4 100644
--- a/src/php5/php_solr_client.c
+++ b/src/php5/php_solr_client.c
@@ -34,6 +34,7 @@ static void solr_client_init_urls(solr_client_t *solr_client)
/* Release all previously allocated URL values, if any */
solr_string_free(&(options->update_url));
+ solr_string_free(&(options->extract_url));
solr_string_free(&(options->search_url));
solr_string_free(&(options->thread_url));
solr_string_free(&(options->ping_url));
@@ -61,6 +62,7 @@ static void solr_client_init_urls(solr_client_t *solr_client)
/* Copying over the prefixes */
solr_string_append_solr_string(&(options->update_url), &url_prefix);
+ solr_string_append_solr_string(&(options->extract_url), &url_prefix);
solr_string_append_solr_string(&(options->search_url), &url_prefix);
solr_string_append_solr_string(&(options->thread_url), &url_prefix);
solr_string_append_solr_string(&(options->ping_url), &url_prefix);
@@ -70,6 +72,7 @@ static void solr_client_init_urls(solr_client_t *solr_client)
/* Making http://hostname:host_port/path/servlet/ */
solr_string_append_solr_string(&(options->update_url), &(options->update_servlet));
+ solr_string_append_solr_string(&(options->extract_url), \
&(options->extract_servlet)); solr_string_append_solr_string(&(options->search_url), \
&(options->search_servlet)); solr_string_append_solr_string(&(options->thread_url), \
&(options->thread_servlet)); solr_string_append_solr_string(&(options->ping_url), \
&(options->ping_servlet)); @@ -78,6 +81,7 @@ static void \
solr_client_init_urls(solr_client_t *solr_client) \
solr_string_append_solr_string(&(options->get_url), &(options->get_servlet));
solr_string_append_const(&(options->update_url), "/?version=2.2&indent=on&wt=");
+ solr_string_append_const(&(options->extract_url), "/?version=2.2&indent=on&wt=");
solr_string_append_const(&(options->search_url), "/?version=2.2&indent=on&wt=");
solr_string_append_const(&(options->thread_url), "/?version=2.2&indent=on&wt=");
solr_string_append_const(&(options->ping_url), "/?version=2.2&indent=on&wt=");
@@ -86,6 +90,7 @@ static void solr_client_init_urls(solr_client_t *solr_client)
solr_string_append_const(&(options->get_url), "/?version=2.2&indent=on&wt=");
solr_string_append_solr_string(&(options->update_url), \
&(options->response_writer)); \
+ solr_string_append_solr_string(&(options->extract_url), \
&(options->response_writer)); solr_string_append_solr_string(&(options->search_url), \
&(options->response_writer)); solr_string_append_solr_string(&(options->thread_url), \
&(options->response_writer)); solr_string_append_solr_string(&(options->ping_url), \
&(options->response_writer)); @@ -98,18 +103,11 @@ static void \
solr_client_init_urls(solr_client_t *solr_client) /* }}} */
/* {{{ static int solr_http_build_query(solr_string_t *buffer, zval *params_objptr, \
const solr_char_t *delimiter, int delimiter_length TSRMLS_DC) */
-static int solr_http_build_query(solr_string_t *buffer, zval *params_objptr, const \
solr_char_t *delimiter, int delimiter_length TSRMLS_DC) +static int \
solr_http_build_query(solr_string_t *buffer, solr_params_t *solr_params, const \
solr_char_t *delimiter, int delimiter_length TSRMLS_DC) {
- solr_params_t *solr_params = NULL;
register zend_bool duplicate = 0;
HashTable *params = NULL;
- if (solr_fetch_params_entry(params_objptr, &solr_params TSRMLS_CC) == FAILURE) {
-
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Unable to retrieve solr_params_t");
-
- return FAILURE;
- }
params = solr_params->params;
@@ -217,6 +215,7 @@ PHP_METHOD(SolrClient, __construct)
solr_string_append_const(&(client_options->response_writer), \
SOLR_XML_RESPONSE_WRITER);
solr_string_append_const(&(client_options->update_servlet), \
SOLR_DEFAULT_UPDATE_SERVLET); \
+ solr_string_append_const(&(client_options->extract_servlet), \
SOLR_DEFAULT_EXTRACT_SERVLET); \
solr_string_append_const(&(client_options->search_servlet), \
SOLR_DEFAULT_SEARCH_SERVLET); \
solr_string_append_const(&(client_options->thread_servlet), \
SOLR_DEFAULT_THREADS_SERVLET); \
solr_string_append_const(&(client_options->ping_servlet), \
SOLR_DEFAULT_PING_SERVLET); @@ -634,7 +633,7 @@ PHP_METHOD(SolrClient, query)
/* Remove wt if any */
zend_hash_del(solr_params->params, "wt", sizeof("wt")-1);
- if (solr_http_build_query(buffer, solr_params_obj, delimiter, delimiter_length \
TSRMLS_CC) == FAILURE) + if (solr_http_build_query(buffer, solr_params, delimiter, \
delimiter_length TSRMLS_CC) == FAILURE) {
solr_throw_exception_ex(solr_ce_SolrException, SOLR_ERROR_1003 TSRMLS_CC, \
SOLR_FILE_LINE_FUNC, "Error building HTTP query from parameters");
@@ -1002,6 +1001,64 @@ PHP_METHOD(SolrClient, request)
}
/* }}} */
+/* {{{ proto SolrUpdateResponse SolrClient::sendUpdateStream(SolrExtractRequest \
request) + sends an update stream request. */
+PHP_METHOD(SolrClient, sendUpdateStream)
+{
+ zval *request_zv = NULL, *params_zv = NULL;
+ solr_ustream_t *stream = NULL;
+ solr_client_t *client = NULL;
+ solr_string_t *qs_buffer; /* query string buffer */
+ solr_char_t *delimiter = NULL;
+ size_t delimiter_length = 0L;
+ solr_params_t *params = NULL;
+ zend_bool success = 1;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &request_zv) == \
FAILURE) { + return;
+ }
+
+ if (solr_fetch_client_entry(getThis(), &client TSRMLS_CC) == FAILURE) {
+ return;
+ }
+
+ stream = zend_object_store_get_object(request_zv TSRMLS_CC);
+
+ params_zv = zend_read_property(solr_ce_SolrModifiableParams, request_zv, \
"params", sizeof("params"), 0 TSRMLS_CC); +
+ if (params_zv && IS_NULL != Z_TYPE_P(params_zv)) {
+ solr_fetch_params_entry(params_zv, ¶ms TSRMLS_CC);
+ }
+
+ /* Always reset the URLs before making any request */
+ solr_client_init_urls(client);
+
+ qs_buffer = &(client->handle.request_body.buffer);
+
+ /* Get rid of all the data from the previous request */
+ solr_string_free(qs_buffer);
+
+ delimiter = client->options.qs_delimiter.str;
+
+ delimiter_length = client->options.qs_delimiter.len;
+
+ if (solr_http_build_query(qs_buffer, params, delimiter, delimiter_length \
TSRMLS_CC) == FAILURE){ + solr_throw_exception_ex(solr_ce_SolrException, \
SOLR_ERROR_1003 TSRMLS_CC, SOLR_FILE_LINE_FUNC, SOLR_ERROR_1003_MSG); + \
return; + }
+
+ if (solr_make_update_stream_request(client, stream, qs_buffer TSRMLS_CC) == \
FAILURE) { + success = 0;
+ /* if there was an error with the http request solr_make_request throws an \
exception by itself + * if it wasn't a curl connection error, throw exception \
(omars) + */
+ HANDLE_SOLR_SERVER_ERROR(client,"extract");
+ }
+ object_init_ex(return_value, solr_ce_SolrUpdateResponse);
+ solr_set_response_object_properties(solr_ce_SolrUpdateResponse, return_value, \
client, &(client->options.extract_url), success TSRMLS_CC); +}
+/* }}} */
+
/* {{{ proto SolrUpdateResponse SolrClient::deleteById(string id)
Allows the user to delete a document by id */
PHP_METHOD(SolrClient, deleteById)
diff --git a/src/php5/php_solr_extract.c b/src/php5/php_solr_extract.c
new file mode 100644
index 0000000..f19b6e9
--- /dev/null
+++ b/src/php5/php_solr_extract.c
@@ -0,0 +1,154 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 7 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2016 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.01 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_01.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. |
+ +----------------------------------------------------------------------+
+ | Author: Omar Shaban <omars@php.net> |
+ +----------------------------------------------------------------------+
+*/
+
+#include "php_solr.h"
+
+extern zend_class_entry *solr_ce_SolrExtractRequest;
+extern zend_object_handlers solr_extract_request_object_handlers;
+extern zend_class_entry *solr_ce_SolrIllegalArgumentException;
+extern zend_class_entry *solr_ce_SolrIllegalOperationException;
+extern HashTable *ustreams;
+
+#define SOLR_EXTRACT_OBJ_CTOR() { \
+ do { \
+ zend_string *params_property_name = zend_string_init("params", \
sizeof("params"), 1); \ + object_init_ex(return_value, \
solr_ce_SolrExtractRequest); \ + stream_entry = (solr_ustream_t \
*)zend_object_store_get_object(return_value TSRMLS_CC); \ + \
zend_update_property(solr_ce_SolrExtractRequest, return_value, \
params_property_name->val, params_property_name->len, params TSRMLS_CC); \ + } \
while(0); \ +}
+
+/* {{{ solr_extract_obj_handlers */
+static void solr_extract_free_object_handler(solr_ustream_t *intern TSRMLS_DC)
+{
+ solr_string_free(&(intern->content_info->filename));
+ solr_string_free(&(intern->content_info->stream_info.binary_content));
+ solr_string_free(&(intern->content_info->stream_info.mime_type));
+
+ efree(intern->content_info);
+ zend_object_std_dtor(&intern->std TSRMLS_CC);
+ efree(intern);
+}
+
+zend_object_value solr_extract_create_object_handler(zend_class_entry *ce TSRMLS_DC)
+{
+ zend_object_value retval;
+
+ solr_ustream_t *intern = emalloc(sizeof(solr_ustream_t));
+ memset(intern, 0, sizeof(solr_ustream_t));
+
+ zend_object_std_init(&intern->std, ce TSRMLS_CC);
+ object_properties_init(&intern->std, ce);
+
+ intern->content_info = emalloc(sizeof(solr_cuv_t));
+
+ solr_string_init(&(intern->content_info->stream_info.mime_type));
+ solr_string_init(&(intern->content_info->stream_info.binary_content));
+
+ retval.handle = zend_objects_store_put(
+ intern,
+ (zend_objects_store_dtor_t) zend_objects_destroy_object,
+ (zend_objects_free_object_storage_t) solr_extract_free_object_handler,
+ NULL TSRMLS_CC
+ );
+
+ retval.handlers = &solr_extract_request_object_handlers;
+
+ return retval;
+}
+/* }}} */
+
+PHP_METHOD(SolrExtractRequest, __construct)
+{
+}
+
+PHP_METHOD(SolrExtractRequest, __destruct)
+{
+}
+
+/* {{{ proto SolrExtractRequest::createFromFile(string filename, \
SolrModifiableParams params) + Create request from file */
+PHP_METHOD(SolrExtractRequest, createFromFile)
+{
+ char *filename;
+ COMPAT_ARG_SIZE_T filename_length = 0;
+ solr_ustream_t *stream_entry = NULL;
+ zval *params = NULL;
+ zend_error_handling error_handling;
+
+ zend_replace_error_handling(EH_THROW, solr_ce_SolrIllegalArgumentException, \
&error_handling TSRMLS_CC); +
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &filename, \
&filename_length, ¶ms) == FAILURE) { + \
zend_restore_error_handling(&error_handling TSRMLS_CC); + return;
+ }
+
+ SOLR_EXTRACT_OBJ_CTOR();
+
+ stream_entry->content_type = SOLR_EXTRACT_CONTENT_FILE;
+
+ solr_string_set_ex(&(stream_entry->content_info->filename), filename, \
filename_length); +}
+
+/* {{{ proto SolrExtractRequest::createFromStream(string content, string \
contentType, SolrModifiableParams params) + Create request from binary stream */
+PHP_METHOD(SolrExtractRequest, createFromStream)
+{
+ char *content, *content_type;
+ COMPAT_ARG_SIZE_T content_length = 0, content_type_length = 0;
+ solr_ustream_t *stream_entry = NULL;
+ zval *params = NULL;
+ zend_error_handling error_handling;
+ solr_cuv_binary_t stream_info;
+
+ zend_replace_error_handling(EH_THROW, solr_ce_SolrIllegalArgumentException, \
&error_handling TSRMLS_CC); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, \
"ssz", &content, &content_length, &content_type, &content_type_length, ¶ms) == \
FAILURE) { + zend_restore_error_handling(&error_handling TSRMLS_CC);
+ return;
+ }
+
+ SOLR_EXTRACT_OBJ_CTOR();
+ stream_entry->content_type = SOLR_EXTRACT_CONTENT_STREAM;
+ solr_string_set_ex(&(stream_entry->content_info->stream_info.mime_type), \
content_type, content_type_length); + \
solr_string_set_ex(&(stream_entry->content_info->stream_info.binary_content), \
content, content_length); +}
+/* }}} */
+
+/* {{{ proto SolrExtractRequest::__clone(void)
+ Should not be called directly. Cloning is not supported. */
+PHP_METHOD(SolrExtractRequest, __clone)
+{
+ solr_throw_exception_ex(solr_ce_SolrIllegalOperationException, SOLR_ERROR_4001 \
TSRMLS_CC, SOLR_FILE_LINE_FUNC, "Cloning of SolrExtractRequest objects is currently \
not supported"); +}
+/* }}} */
+
+/* {{{ proto SolrExtractRequest::__sleep(void)
+ Should not be called directly. Serialization is not supported. */
+PHP_METHOD(SolrExtractRequest, __sleep)
+{
+ solr_throw_exception_ex(solr_ce_SolrIllegalOperationException, SOLR_ERROR_4001 \
TSRMLS_CC, SOLR_FILE_LINE_FUNC, "SolrExtractRequest objects cannot be serialized or \
unserialized"); +}
+/* }}} */
+
+/* {{{ proto SolrExtractRequest::__wakeup(void)
+ Should not be called directly. Deserialization is not supported. */
+PHP_METHOD(SolrExtractRequest, __wakeup)
+{
+ solr_throw_exception_ex(solr_ce_SolrIllegalOperationException, SOLR_ERROR_4001 \
TSRMLS_CC, SOLR_FILE_LINE_FUNC, "SolrExtractRequest objects cannot be serialized or \
unserialized"); +}
+/* }}} */
diff --git a/src/php5/solr_constants.h b/src/php5/solr_constants.h
index 5321474..f9fe6ab 100644
--- a/src/php5/solr_constants.h
+++ b/src/php5/solr_constants.h
@@ -29,6 +29,7 @@
/* {{{ Constants for the SolrClient with*/
#define SOLR_DEFAULT_UPDATE_SERVLET "update"
+#define SOLR_DEFAULT_EXTRACT_SERVLET "update/extract"
#define SOLR_DEFAULT_SEARCH_SERVLET "select"
#define SOLR_DEFAULT_THREADS_SERVLET "admin/threads"
#define SOLR_DEFAULT_PING_SERVLET "admin/ping"
@@ -55,6 +56,7 @@
#define PHP_SOLR_DOCUMENT_CLASSNAME "SolrDocument"
#define PHP_SOLR_DOCUMENT_FIELD_CLASSNAME "SolrDocumentField"
#define PHP_SOLR_INPUT_DOCUMENT_CLASSNAME "SolrInputDocument"
+#define PHP_SOLR_EXTRACTREQUEST_CLASSNAME "SolrExtractRequest"
#define PHP_SOLR_CLIENT_CLASSNAME "SolrClient"
#define PHP_SOLR_PARAMS_CLASSNAME "SolrParams"
#define PHP_SOLR_QUERY_CLASSNAME "SolrQuery"
diff --git a/src/php5/solr_functions_client.c b/src/php5/solr_functions_client.c
index 0784eee..4d5b468 100644
--- a/src/php5/solr_functions_client.c
+++ b/src/php5/solr_functions_client.c
@@ -317,6 +317,126 @@ int solr_curl_debug_callback(CURL *curl_handle, curl_infotype \
infotype, solr_cha }
/* }}} */
+PHP_SOLR_API void solr_curl_request_reset(solr_curl_t *sch, solr_client_options_t \
*options TSRMLS_DC) { + /* Reset the buffers */
+ solr_string_free(&sch->request_header.buffer);
+ solr_string_free(&sch->request_body_debug.buffer);
+ solr_string_free(&sch->response_body.buffer);
+ solr_string_free(&sch->response_header.buffer);
+ solr_string_free(&sch->debug_data_buffer);
+
+ curl_easy_reset(sch->curl_handle);
+
+ solr_set_initial_curl_handle_options(&(sch), options TSRMLS_CC);
+
+ /* Reset the CURL options if the handle is reused */
+ curl_easy_setopt(sch->curl_handle, CURLOPT_HEADER, 0L);
+ curl_easy_setopt(sch->curl_handle, CURLOPT_POST, 0L);
+ curl_easy_setopt(sch->curl_handle, CURLOPT_HTTPGET, 0L);
+ curl_easy_setopt(sch->curl_handle, CURLOPT_NOBODY, 0L);
+
+ curl_easy_setopt(sch->curl_handle, CURLOPT_POSTFIELDSIZE, 0L);
+ curl_easy_setopt(sch->curl_handle, CURLOPT_POSTFIELDS, NULL);
+ curl_easy_setopt(sch->curl_handle, CURLOPT_URL, NULL);
+ curl_easy_setopt(sch->curl_handle, CURLOPT_HTTPHEADER, NULL);
+}
+
+PHP_SOLR_API solr_http_header_list_t *solr_curl_init_header_list()
+{
+ solr_http_header_list_t *header_list = NULL;
+ header_list = curl_slist_append(header_list, "Accept-Charset: utf-8");
+ header_list = curl_slist_append(header_list, "Keep-Alive: 300");
+ header_list = curl_slist_append(header_list, "Connection: keep-alive");
+ /* Disable the Expect: 100-continue header. Jetty gets confused with this header \
*/ + header_list = curl_slist_append(header_list, "Expect:");
+ return header_list;
+}
+
+PHP_SOLR_API int solr_is_request_successful(CURLcode info_status, solr_curl_t *sch \
TSRMLS_DC) +{
+ int return_status = SUCCESS;
+
+ if (info_status != CURLE_OK) {
+ solr_throw_exception_ex(
+ solr_ce_SolrClientException,
+ SOLR_ERROR_1004 TSRMLS_CC,
+ SOLR_FILE_LINE_FUNC,
+ "HTTP Transfer status could not be retrieved successfully"
+ );
+ return_status = FAILURE;
+ }
+
+ if (sch->result_code != CURLE_OK)
+ {
+ solr_throw_exception_ex(
+ solr_ce_SolrClientException,
+ SOLR_ERROR_1004 TSRMLS_CC,
+ SOLR_FILE_LINE_FUNC,
+ "Solr HTTP Error %d: '%s' ",
+ sch->result_code,
+ curl_easy_strerror(sch->result_code)
+ );
+ return_status = FAILURE;
+ }
+
+ if (sch->response_header.response_code != 200L)
+ {
+ return_status = FAILURE;
+ }
+ return return_status;
+}
+
+PHP_SOLR_API int solr_make_update_stream_request(solr_client_t *client, \
solr_ustream_t* stream_data, solr_string_t *request_params TSRMLS_DC) +{
+ solr_curl_t *sch = &(client->handle);
+ solr_client_options_t *options = &(client->options);
+ int return_status = SUCCESS;
+ CURLcode info_status = CURLE_OK;
+ struct curl_httppost *formpost = NULL, *lastptr = NULL;
+ int is_binary = stream_data->content_type == SOLR_EXTRACT_CONTENT_STREAM;
+ solr_string_t content_type_header;
+
+ solr_http_header_list_t *header_list = solr_curl_init_header_list();
+ solr_curl_request_reset(sch, options TSRMLS_CC);
+
+ solr_string_appendc(&(options->extract_url), '&');
+ solr_string_append_solr_string(&(options->extract_url), request_params);
+
+ curl_easy_setopt(sch->curl_handle, CURLOPT_URL, options->extract_url.str);
+
+ if (is_binary) {
+ solr_string_init(&content_type_header);
+ solr_string_appends(&content_type_header, "Content-Type: ", \
sizeof("Content-Type: ")-1); + \
solr_string_append_solr_string(&content_type_header, \
&(stream_data->content_info->stream_info.mime_type)); +
+ header_list = curl_slist_append(header_list, content_type_header.str);
+ curl_easy_setopt(sch->curl_handle, CURLOPT_POSTFIELDS, \
stream_data->content_info->stream_info.binary_content.str); + \
curl_easy_setopt(sch->curl_handle, CURLOPT_POSTFIELDSIZE, \
stream_data->content_info->stream_info.binary_content.len); + \
solr_string_free_ex(&content_type_header); + } else{
+ curl_formadd(&formpost, &lastptr,
+ CURLFORM_COPYNAME, "PHPSOLRCLIENT",
+ CURLFORM_FILE, (const char *) \
stream_data->content_info->filename.str, + CURLFORM_END
+ );
+ curl_easy_setopt(sch->curl_handle, CURLOPT_HTTPPOST, formpost);
+ }
+
+ curl_easy_setopt(sch->curl_handle, CURLOPT_HTTPHEADER, header_list);
+ sch->result_code = curl_easy_perform(sch->curl_handle);
+
+ info_status = curl_easy_getinfo(sch->curl_handle, CURLINFO_RESPONSE_CODE, \
&(sch->response_header.response_code)); + return_status = \
solr_is_request_successful(info_status, sch TSRMLS_CC); +
+ curl_slist_free_all(header_list);
+
+ if (!is_binary) {
+ curl_formfree(formpost);
+ }
+
+ return return_status;
+}
+
/* {{{ PHP_SOLR_API int solr_make_request(solr_client_t *client, solr_request_type_t \
request_type TSRMLS_DC) */ PHP_SOLR_API int solr_make_request(solr_client_t *client, \
solr_request_type_t request_type TSRMLS_DC) {
@@ -326,34 +446,8 @@ PHP_SOLR_API int solr_make_request(solr_client_t *client, \
solr_request_type_t re int return_status = SUCCESS;
CURLcode info_status = CURLE_OK;
- header_list = curl_slist_append(header_list, "Accept-Charset: utf-8");
- header_list = curl_slist_append(header_list, "Keep-Alive: 300");
- header_list = curl_slist_append(header_list, "Connection: keep-alive");
-
- /* Disable the Expect: 100-continue header. Jetty gets confused with this header */
- header_list = curl_slist_append(header_list, "Expect:");
-
- /* Reset the buffers */
- solr_string_free(&sch->request_header.buffer);
- solr_string_free(&sch->request_body_debug.buffer);
- solr_string_free(&sch->response_body.buffer);
- solr_string_free(&sch->response_header.buffer);
- solr_string_free(&sch->debug_data_buffer);
-
- curl_easy_reset(sch->curl_handle);
-
- solr_set_initial_curl_handle_options(&(sch), options TSRMLS_CC);
-
- /* Reset the CURL options if the handle is reused */
- curl_easy_setopt(sch->curl_handle, CURLOPT_HEADER, 0L);
- curl_easy_setopt(sch->curl_handle, CURLOPT_POST, 0L);
- curl_easy_setopt(sch->curl_handle, CURLOPT_HTTPGET, 0L);
- curl_easy_setopt(sch->curl_handle, CURLOPT_NOBODY, 0L);
-
- curl_easy_setopt(sch->curl_handle, CURLOPT_POSTFIELDSIZE, 0L);
- curl_easy_setopt(sch->curl_handle, CURLOPT_POSTFIELDS, NULL);
- curl_easy_setopt(sch->curl_handle, CURLOPT_URL, NULL);
- curl_easy_setopt(sch->curl_handle, CURLOPT_HTTPHEADER, NULL);
+ solr_curl_request_reset(sch, options TSRMLS_CC);
+ header_list = solr_curl_init_header_list();
switch(request_type)
{
@@ -442,26 +536,7 @@ PHP_SOLR_API int solr_make_request(solr_client_t *client, \
solr_request_type_t re
info_status = curl_easy_getinfo(sch->curl_handle, CURLINFO_RESPONSE_CODE, \
&(sch->response_header.response_code));
- if (info_status != CURLE_OK)
- {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "HTTP Transfer status could not be \
retrieved successfully");
-
- return_status = FAILURE;
- }
-
- if (sch->result_code != CURLE_OK)
- {
- /* commented by: Omar Shaban <omars@php.net> */
- /* php_error_docref(NULL TSRMLS_CC, E_WARNING, "Solr HTTP Error : '%s' ", \
curl_easy_strerror(sch->result_code)); */
-
- solr_throw_exception_ex(solr_ce_SolrClientException, SOLR_ERROR_1004 TSRMLS_CC, \
SOLR_FILE_LINE_FUNC, "Solr HTTP Error %d: '%s' ",sch->result_code, \
curl_easy_strerror(sch->result_code));
- return_status = FAILURE;
- }
-
- if (sch->response_header.response_code != 200L)
- {
- return_status = FAILURE;
- }
+ return_status = solr_is_request_successful(info_status, sch TSRMLS_CC);
curl_slist_free_all(header_list);
@@ -513,6 +588,8 @@ PHP_SOLR_API void solr_free_options(solr_client_options_t \
*options) solr_string_free(&((options)->terms_url));
solr_string_free(&((options)->system_url));
solr_string_free(&((options)->get_url));
+ solr_string_free(&((options)->extract_url));
+
solr_string_free(&((options)->update_servlet));
solr_string_free(&((options)->search_servlet));
@@ -521,6 +598,7 @@ PHP_SOLR_API void solr_free_options(solr_client_options_t \
*options) solr_string_free(&((options)->terms_servlet));
solr_string_free(&((options)->system_servlet));
solr_string_free(&((options)->get_servlet));
+ solr_string_free(&((options)->extract_servlet));
}
/* }}} */
diff --git a/src/php5/solr_functions_helpers.c b/src/php5/solr_functions_helpers.c
index 5987974..a0be2a9 100644
--- a/src/php5/solr_functions_helpers.c
+++ b/src/php5/solr_functions_helpers.c
@@ -147,6 +147,31 @@ PHP_SOLR_API void \
solr_query_register_class_constants(zend_class_entry *ce TSRML }
/* }}} */
+
+PHP_SOLR_API void solr_extract_register_class_constants(zend_class_entry *ce \
TSRMLS_DC) +{
+ zend_declare_class_constant_string(ce, "CAPTURE_ELEMENTS", \
sizeof("CAPTURE_ELEMENTS")-1, "capture" TSRMLS_CC); + \
zend_declare_class_constant_string(ce, "CAPTURE_ATTRIBUTES", \
sizeof("CAPTURE_ATTRIBUTES")-1, "captureAttr" TSRMLS_CC); + \
zend_declare_class_constant_string(ce, "COMMIT_WITHIN", sizeof("COMMIT_WITHIN")-1, \
"commitWithin" TSRMLS_CC); + zend_declare_class_constant_string(ce, \
"DATE_FORMATS", sizeof("DATE_FORMATS")-1, "date.formats" TSRMLS_CC); + \
zend_declare_class_constant_string(ce, "DEFAULT_FIELD", sizeof("DEFAULT_FIELD")-1, \
"defaultField" TSRMLS_CC); + zend_declare_class_constant_string(ce, \
"EXTRACT_ONLY", sizeof("EXTRACT_ONLY")-1, "extractOnly" TSRMLS_CC); + \
zend_declare_class_constant_string(ce, "EXTRACT_FORMAT", \
sizeof("EXTRACT_FORMAT")-1,"extractFormat" TSRMLS_CC); + \
zend_declare_class_constant_string(ce, "IGNORE_TIKA_EXCEPTION", \
sizeof("IGNORE_TIKA_EXCEPTION")-1, "ignoreTikaException" TSRMLS_CC); + \
zend_declare_class_constant_string(ce, "LITERALS_OVERRIDE", \
sizeof("LITERALS_OVERRIDE")-1, "literalsOverride" TSRMLS_CC); + \
zend_declare_class_constant_string(ce, "LOWERNAMES", sizeof("LOWERNAMES")-1, \
"lowernames" TSRMLS_CC); + zend_declare_class_constant_string(ce, \
"MULTIPART_UPLOAD_LIMIT", sizeof("MULTIPART_UPLOAD_LIMIT")-1, \
"multipartUploadLimitInKB" TSRMLS_CC); + zend_declare_class_constant_string(ce, \
"PASSWORD_MAP_FILE", sizeof("PASSWORD_MAP_FILE")-1, "passwordsFile" TSRMLS_CC); + \
zend_declare_class_constant_string(ce, "RESOURCE_NAME", sizeof("RESOURCE_NAME")-1, \
"resource.name" TSRMLS_CC); + zend_declare_class_constant_string(ce, \
"RESOURCE_PASSWORD", sizeof("RESOURCE_PASSWORD")-1, "resource.password" TSRMLS_CC); + \
zend_declare_class_constant_string(ce, "TIKE_CONFIG", sizeof("TIKE_CONFIG")-1, \
"tika.config" TSRMLS_CC); + zend_declare_class_constant_string(ce, \
"UNKNOWN_FIELD_PREFIX", sizeof("UNKNOWN_FIELD_PREFIX")-1, "uprefix" TSRMLS_CC); + \
zend_declare_class_constant_string(ce, "XPATH_EXPRESSION", \
sizeof("XPATH_EXPRESSION")-1, "xpath" TSRMLS_CC); + \
zend_declare_class_constant_string(ce, "FIELD_MAPPING_PREFIX", \
sizeof("FIELD_MAPPING_PREFIX")-1, "fmap." TSRMLS_CC); + \
zend_declare_class_constant_string(ce, "FIELD_BOOST_PREFIX", \
sizeof("FIELD_BOOST_PREFIX")-1, "boost." TSRMLS_CC); + \
zend_declare_class_constant_string(ce, "LITERALS_PREFIX", \
sizeof("LITERALS_PREFIX")-1, "literal." TSRMLS_CC); +}
+
/** ************************************************************************ **/
/** FUNCTIONS FOR REFERENCE COUNT MANAGEMENT **/
/** ************************************************************************ **/
@@ -1579,6 +1604,36 @@ PHP_SOLR_API void solr_solrfunc_to_string(solr_function_t \
*function, solr_string /* todo handle localParams argument */
}
+PHP_SOLR_API void solr_destroy_ustream_ex(solr_ustream_t *stream)
+{
+ if (stream->content_info->filename.len > 0) {
+ solr_string_free(&stream->content_info->filename);
+ }
+ pefree(stream->content_info, 0);
+ pefree(stream, 0);
+}
+
+PHP_SOLR_API void solr_destroy_ustream_zv(zval *obj TSRMLS_DC)
+{
+ solr_ustream_t *entry = zend_object_store_get_object(obj TSRMLS_CC);
+ solr_destroy_ustream_ex(entry);
+}
+
+PHP_SOLR_API int solr_fetch_ustream_entry(zval *objptr, solr_ustream_t \
**stream_entry TSRMLS_DC) +{
+ zval rv, *index_zv;
+ ulong index = 0;
+ index_zv = zend_read_property(Z_OBJCE_P(objptr), objptr, \
SOLR_INDEX_PROPERTY_NAME, sizeof(SOLR_INDEX_PROPERTY_NAME)-1, 1 TSRMLS_CC); +
+ index = Z_LVAL_P(index_zv);
+ if ((*stream_entry = zend_hash_index_find_ptr(SOLR_GLOBAL(ustreams), index)) == \
NULL) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Update Stream \
Index %ld. HashTable index does not exist.", index); + php_error_docref(NULL \
TSRMLS_CC, E_WARNING, SOLR_ERROR_1008_MSG, SOLR_FILE_LINE_FUNC); + return \
FAILURE; + }
+ return SUCCESS;
+}
+
/*
* Local variables:
* tab-width: 4
diff --git a/src/php5/solr_functions_params.c b/src/php5/solr_functions_params.c
index 9f0798d..d544c98 100644
--- a/src/php5/solr_functions_params.c
+++ b/src/php5/solr_functions_params.c
@@ -22,6 +22,7 @@
#include "php_solr.h"
+
/* {{{ PHP_SOLR_API void solr_destroy_params(void *solr_params) */
PHP_SOLR_API void solr_destroy_params(void *solr_params)
{
diff --git a/src/php5/solr_macros.h b/src/php5/solr_macros.h
index 6f78cc6..9ec34fa 100644
--- a/src/php5/solr_macros.h
+++ b/src/php5/solr_macros.h
@@ -41,6 +41,9 @@
/* Retrieve a unique hash index for this SolrFunction instance. Unique for this \
thread */ #define SOLR_UNIQUE_FUNCTION_INDEX() \
solr_hashtable_get_new_index(SOLR_GLOBAL(functions) TSRMLS_CC)
+/* Retrieve a unique hash index for this update stream instances. Unique for this \
thread */ +#define SOLR_UNIQUE_USTREAM_INDEX() \
solr_hashtable_get_new_index(SOLR_GLOBAL(ustreams) TSRMLS_CC) +
/* Iterates through the HashTable pointer */
#define SOLR_HASHTABLE_FOR_LOOP(HashTablePtr) \
if (HashTablePtr) for ( zend_hash_internal_pointer_reset((HashTablePtr)); \
diff --git a/src/php5/solr_types.h b/src/php5/solr_types.h
index 55a75f8..78abd48 100644
--- a/src/php5/solr_types.h
+++ b/src/php5/solr_types.h
@@ -62,6 +62,7 @@ typedef enum {
SOLR_REQUEST_TERMS = 5, /** 5 **/
SOLR_REQUEST_SYSTEM = 6, /** 6 **/
SOLR_REQUEST_GET = 7,
+ SOLR_REQUEST_EXTRACT = 8,
SOLR_REQUEST_END
} solr_request_type_t;
@@ -76,6 +77,7 @@ typedef enum {
SOLR_SERVLET_TYPE_TERMS = 16,
SOLR_SERVLET_TYPE_SYSTEM = 32,
SOLR_SERVLET_TYPE_GET = 64,
+ SOLR_SERVLET_TYPE_EXTRACT = 128,
SOLR_SERVLET_TYPE_END
} solr_servlet_type_t;
@@ -228,6 +230,8 @@ typedef struct {
solr_string_t update_url; /* URL used for updates */
+ solr_string_t extract_url; /* URL used for file indexing using extract \
*/ +
solr_string_t search_url; /* URL used for queries */
solr_string_t thread_url; /* URL used for thread monitoring */
@@ -242,6 +246,8 @@ typedef struct {
solr_string_t update_servlet; /* The update servlet */
+ solr_string_t extract_servlet; /* The update servlet appended with extract \
Req. handler */ +
solr_string_t search_servlet; /* The search servlet */
solr_string_t thread_servlet; /* The thread servlet */
@@ -432,7 +438,28 @@ typedef struct {
HashTable *params; /* The HashTable<solr_string_t> for storing function key-val \
parameters */
} solr_function_t;
+/* }}} */
+
+/* {{{ content stream/extract types */
+
+#define SOLR_EXTRACT_CONTENT_FILE 0
+#define SOLR_EXTRACT_CONTENT_STREAM 1
+typedef struct {
+ solr_string_t binary_content; /* actual contents */
+ solr_string_t mime_type; /* mime type */
+} solr_cuv_binary_t;
+
+typedef union {
+ solr_string_t filename;
+ solr_cuv_binary_t stream_info;
+} solr_cuv_t;
+
+typedef struct {
+ solr_cuv_t *content_info; /* stores the content data whether filename or \
stream_info */ + int content_type; /* stores the content type from the \
constants above */ + zend_object std;
+} solr_ustream_t;
/* }}} */
/* }}} */
@@ -456,6 +483,8 @@ ZEND_BEGIN_MODULE_GLOBALS(solr)
HashTable *functions; /* HashTable for storing solr_function_t */
+ HashTable *ustreams; /* HashTable for storing solr_ustream_t */
+
ZEND_END_MODULE_GLOBALS(solr)
/* }}} */
--
PECL CVS Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic