diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 18:00:34 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 18:00:34 +0000 |
commit | 3f619478f796eddbba6e39502fe941b285dd97b1 (patch) | |
tree | e2c7b5777f728320e5b5542b6213fd3591ba51e2 /storage/mroonga/vendor/groonga/bindings | |
parent | Initial commit. (diff) | |
download | mariadb-3f619478f796eddbba6e39502fe941b285dd97b1.tar.xz mariadb-3f619478f796eddbba6e39502fe941b285dd97b1.zip |
Adding upstream version 1:10.11.6.upstream/1%10.11.6upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'storage/mroonga/vendor/groonga/bindings')
8 files changed, 945 insertions, 0 deletions
diff --git a/storage/mroonga/vendor/groonga/bindings/php/config.m4 b/storage/mroonga/vendor/groonga/bindings/php/config.m4 new file mode 100644 index 00000000..c656c9d4 --- /dev/null +++ b/storage/mroonga/vendor/groonga/bindings/php/config.m4 @@ -0,0 +1,66 @@ + +PHP_ARG_WITH(groonga, whether groonga is available,[ --with-groonga[=DIR] With groonga support]) + + +if test "$PHP_GROONGA" != "no"; then + + + if test -r "$PHP_GROONGA/include/groonga.h"; then + PHP_GROONGA_DIR="$PHP_GROONGA" + PHP_ADD_INCLUDE($PHP_GROONGA_DIR/include) + elif test -r "$PHP_GROONGA/include/groonga/groonga.h"; then + PHP_GROONGA_DIR="$PHP_GROONGA" + PHP_ADD_INCLUDE($PHP_GROONGA_DIR/include/groonga) + else + AC_MSG_CHECKING(for groonga in default path) + for i in /usr /usr/local; do + if test -r "$i/include/groonga/groonga.h"; then + PHP_GROONGA_DIR=$i + AC_MSG_RESULT(found in $i) + break + fi + done + if test "x" = "x$PHP_GROONGA_DIR"; then + AC_MSG_ERROR(not found) + fi + PHP_ADD_INCLUDE($PHP_GROONGA_DIR/include) + fi + + export OLD_CPPFLAGS="$CPPFLAGS" + export CPPFLAGS="$CPPFLAGS $INCLUDES -DHAVE_GROONGA" + AC_CHECK_HEADER([groonga.h], [], AC_MSG_ERROR('groonga.h' header not found)) + PHP_SUBST(GROONGA_SHARED_LIBADD) + + + PHP_CHECK_LIBRARY(groonga, grn_init, + [ + PHP_ADD_LIBRARY_WITH_PATH(groonga, $PHP_GROONGA_DIR/lib, GROONGA_SHARED_LIBADD) + ],[ + AC_MSG_ERROR([wrong groonga lib version or lib not found]) + ],[ + -L$PHP_GROONGA_DIR/lib + ]) + export CPPFLAGS="$OLD_CPPFLAGS" + + export OLD_CPPFLAGS="$CPPFLAGS" + export CPPFLAGS="$CPPFLAGS $INCLUDES -DHAVE_GROONGA" + + AC_MSG_CHECKING(PHP version) + AC_TRY_COMPILE([#include <php_version.h>], [ +#if PHP_VERSION_ID < 40000 +#error this extension requires at least PHP version 4.0.0 +#endif +], +[AC_MSG_RESULT(ok)], +[AC_MSG_ERROR([need at least PHP 4.0.0])]) + + export CPPFLAGS="$OLD_CPPFLAGS" + + + PHP_SUBST(GROONGA_SHARED_LIBADD) + AC_DEFINE(HAVE_GROONGA, 1, [ ]) + + PHP_NEW_EXTENSION(groonga, groonga.c , $ext_shared) + +fi + diff --git a/storage/mroonga/vendor/groonga/bindings/php/config.w32 b/storage/mroonga/vendor/groonga/bindings/php/config.w32 new file mode 100644 index 00000000..d0fab53b --- /dev/null +++ b/storage/mroonga/vendor/groonga/bindings/php/config.w32 @@ -0,0 +1,6 @@ +ARG_WITH('groonga', 'Groonga', 'no'); + +if (PHP_GROONGA == "yes") { + EXTENSION("groonga", "groonga.c"); + AC_DEFINE("HAVE_GROONGA", 1, "groonga support"); +} diff --git a/storage/mroonga/vendor/groonga/bindings/php/groonga.c b/storage/mroonga/vendor/groonga/bindings/php/groonga.c new file mode 100644 index 00000000..a04bb9cd --- /dev/null +++ b/storage/mroonga/vendor/groonga/bindings/php/groonga.c @@ -0,0 +1,221 @@ + +#include "php_groonga.h" + +#if HAVE_GROONGA + +int le_grn_ctx; +void grn_ctx_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) +{ + grn_ctx *ctx = (grn_ctx *)(rsrc->ptr); + grn_ctx_close(ctx); +} + +zend_function_entry groonga_functions[] = { + PHP_FE(grn_ctx_init , grn_ctx_init_arg_info) + PHP_FE(grn_ctx_close , grn_ctx_close_arg_info) + PHP_FE(grn_ctx_connect , grn_ctx_connect_arg_info) + PHP_FE(grn_ctx_send , grn_ctx_send_arg_info) + PHP_FE(grn_ctx_recv , grn_ctx_recv_arg_info) + { NULL, NULL, NULL } +}; + + +zend_module_entry groonga_module_entry = { + STANDARD_MODULE_HEADER, + "groonga", + groonga_functions, + PHP_MINIT(groonga), + PHP_MSHUTDOWN(groonga), + PHP_RINIT(groonga), + PHP_RSHUTDOWN(groonga), + PHP_MINFO(groonga), + "0.1", + STANDARD_MODULE_PROPERTIES +}; + +#ifdef COMPILE_DL_GROONGA +ZEND_GET_MODULE(groonga) +#endif + + +PHP_MINIT_FUNCTION(groonga) +{ + REGISTER_LONG_CONSTANT("GRN_CTX_USE_QL", GRN_CTX_USE_QL, CONST_PERSISTENT | CONST_CS); + REGISTER_LONG_CONSTANT("GRN_CTX_BATCH_MODE", GRN_CTX_BATCH_MODE, CONST_PERSISTENT | CONST_CS); + REGISTER_LONG_CONSTANT("GRN_ENC_DEFAULT", GRN_ENC_DEFAULT, CONST_PERSISTENT | CONST_CS); + REGISTER_LONG_CONSTANT("GRN_ENC_NONE", GRN_ENC_NONE, CONST_PERSISTENT | CONST_CS); + REGISTER_LONG_CONSTANT("GRN_ENC_EUC_JP", GRN_ENC_EUC_JP, CONST_PERSISTENT | CONST_CS); + REGISTER_LONG_CONSTANT("GRN_ENC_UTF8", GRN_ENC_UTF8, CONST_PERSISTENT | CONST_CS); + REGISTER_LONG_CONSTANT("GRN_ENC_SJIS", GRN_ENC_SJIS, CONST_PERSISTENT | CONST_CS); + REGISTER_LONG_CONSTANT("GRN_ENC_LATIN1", GRN_ENC_LATIN1, CONST_PERSISTENT | CONST_CS); + REGISTER_LONG_CONSTANT("GRN_ENC_KOI8R", GRN_ENC_KOI8R, CONST_PERSISTENT | CONST_CS); + REGISTER_LONG_CONSTANT("GRN_CTX_MORE", GRN_CTX_MORE, CONST_PERSISTENT | CONST_CS); + REGISTER_LONG_CONSTANT("GRN_CTX_TAIL", GRN_CTX_TAIL, CONST_PERSISTENT | CONST_CS); + REGISTER_LONG_CONSTANT("GRN_CTX_HEAD", GRN_CTX_HEAD, CONST_PERSISTENT | CONST_CS); + REGISTER_LONG_CONSTANT("GRN_CTX_QUIET", GRN_CTX_QUIET, CONST_PERSISTENT | CONST_CS); + REGISTER_LONG_CONSTANT("GRN_CTX_QUIT", GRN_CTX_QUIT, CONST_PERSISTENT | CONST_CS); + REGISTER_LONG_CONSTANT("GRN_CTX_FIN", GRN_CTX_FIN, CONST_PERSISTENT | CONST_CS); + le_grn_ctx = zend_register_list_destructors_ex( + grn_ctx_dtor, NULL, "grn_ctx", module_number); + + grn_init(); + + return SUCCESS; +} + + +PHP_MSHUTDOWN_FUNCTION(groonga) +{ + grn_fin(); + return SUCCESS; +} + + +PHP_RINIT_FUNCTION(groonga) +{ + return SUCCESS; +} + + +PHP_RSHUTDOWN_FUNCTION(groonga) +{ + return SUCCESS; +} + + +PHP_MINFO_FUNCTION(groonga) +{ + php_info_print_box_start(0); + php_printf("<p>Groonga</p>\n"); + php_printf("<p>Version 0.2 (ctx)</p>\n"); + php_printf("<p><b>Authors:</b></p>\n"); + php_printf("<p>yu <yu@irx.jp> (lead)</p>\n"); + php_info_print_box_end(); +} + + +PHP_FUNCTION(grn_ctx_init) +{ + grn_ctx *ctx = (grn_ctx *) malloc(sizeof(grn_ctx)); + long res_id = -1; + long flags = 0; + grn_rc rc; + + if (ctx == NULL) { + RETURN_FALSE; // unable to allocate memory for ctx + } + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flags) == FAILURE) { + return; + } + + if ((rc = grn_ctx_init(ctx, flags)) != GRN_SUCCESS) { + RETURN_FALSE; + } + + res_id = ZEND_REGISTER_RESOURCE(return_value, ctx, le_grn_ctx); + RETURN_RESOURCE(res_id); +} + + +PHP_FUNCTION(grn_ctx_close) +{ + zval *res = NULL; + int res_id = -1; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) { + return; + } + + zend_list_delete(Z_LVAL_P(res)); // call grn_ctx_dtor + RETURN_TRUE; +} + + +PHP_FUNCTION(grn_ctx_connect) +{ + zval *res = NULL; + int res_id = -1; + + grn_rc rc; + grn_ctx *ctx; + char *host = "localhost"; + int host_len = 0; + long port = 10041; + long flags = 0; + + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|ll", &res, &host, &host_len, &port, &flags) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(ctx, grn_ctx *, &res, res_id, "grn_ctx", le_grn_ctx); + + if ((rc = grn_ctx_connect(ctx, host, port, flags)) != GRN_SUCCESS) { + RETURN_FALSE; + } + + RETURN_TRUE; +} + + +PHP_FUNCTION(grn_ctx_send) +{ + zval *res = NULL; + int res_id = -1; + + grn_ctx *ctx; + char *query = NULL; + unsigned int query_len, qid; + long flags = 0; + + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|l", &res, &query, &query_len, &flags) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(ctx, grn_ctx *, &res, res_id, "grn_ctx", le_grn_ctx); + qid = grn_ctx_send(ctx, query, query_len, flags); + if (ctx->rc != GRN_SUCCESS) { + RETURN_FALSE; + } + + RETURN_LONG(qid) + +} + + +PHP_FUNCTION(grn_ctx_recv) +{ + zval *res,*ret = NULL; + int res_id = -1; + grn_ctx *ctx; + + char *str; + int flags; + unsigned int str_len, qid; + + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(ctx, grn_ctx *, &res, res_id, "grn_ctx", le_grn_ctx); + + qid = grn_ctx_recv(ctx, &str, &str_len, &flags); + + if (ctx->rc != GRN_SUCCESS) { + RETURN_FALSE; + } + + MAKE_STD_ZVAL(ret); + array_init(ret); + array_init(return_value); + + add_next_index_long(ret, flags); + add_next_index_stringl(ret, str, str_len, 1); + + add_index_zval(return_value, qid, ret); +} + +#endif /* HAVE_GROONGA */ diff --git a/storage/mroonga/vendor/groonga/bindings/php/groonga.dsp b/storage/mroonga/vendor/groonga/bindings/php/groonga.dsp new file mode 100644 index 00000000..dd7c91ce --- /dev/null +++ b/storage/mroonga/vendor/groonga/bindings/php/groonga.dsp @@ -0,0 +1,112 @@ +# Microsoft Developer Studio Project File - Name="groonga" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=groonga - Win32 Debug_TS +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "groonga.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "groonga.mak" CFG="groonga - Win32 Debug_TS" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "groonga - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "groonga - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "groonga - Win32 Release_TS" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release_TS" +# PROP BASE Intermediate_Dir "Release_TS" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release_TS" +# PROP Intermediate_Dir "Release_TS" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "GROONGA_EXPORTS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\.." /I "..\..\Zend" /I "..\..\TSRM" /I "..\..\main" /D "WIN32" /D "PHP_EXPORTS" /D "COMPILE_DL_GROONGA" /D ZTS=1 /D HAVE_GROONGA=1 /D ZEND_DEBUG=0 /D "NDEBUG" /D "_WINDOWS" /D "ZEND_WIN32" /D "PHP_WIN32" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x407 /d "NDEBUG" +# ADD RSC /l 0x407 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 php4ts.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS\php_groonga.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline" + +!ELSEIF "$(CFG)" == "groonga - Win32 Debug_TS" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug_TS" +# PROP BASE Intermediate_Dir "Debug_TS" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug_TS" +# PROP Intermediate_Dir "Debug_TS" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "GROONGA_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\Zend" /I "..\..\TSRM" /I "..\..\main" /D ZEND_DEBUG=1 /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "PHP_EXPORTS" /D "COMPILE_DL_GROONGA" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_GROONGA=1 /YX /FD /GZ /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x407 /d "_DEBUG" +# ADD RSC /l 0x407 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 php4ts_debug.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"..\..\Debug_TS\php_groonga.dll" /pdbtype:sept /libpath:"..\..\Debug_TS" + +!ENDIF + +# Begin Target + +# Name "groonga - Win32 Release_TS" +# Name "groonga - Win32 Debug_TS" + +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" + +# Begin Source File + +SOURCE=./groonga.c +# End Source File + +# End Group + +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" + +# Begin Source File + +SOURCE=.\php_groonga.h +# End Source File +# End Group +# End Target +# End Project diff --git a/storage/mroonga/vendor/groonga/bindings/php/php_groonga.h b/storage/mroonga/vendor/groonga/bindings/php/php_groonga.h new file mode 100644 index 00000000..3af4427f --- /dev/null +++ b/storage/mroonga/vendor/groonga/bindings/php/php_groonga.h @@ -0,0 +1,125 @@ +/* + +----------------------------------------------------------------------+ + | unknown license: | + +----------------------------------------------------------------------+ + | Authors: yu <yu@irx.jp> | + +----------------------------------------------------------------------+ +*/ + +#ifndef PHP_GROONGA_H +#define PHP_GROONGA_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <php.h> + +#ifdef HAVE_GROONGA + +#include <php_ini.h> +#include <SAPI.h> +#include <ext/standard/info.h> +#include <Zend/zend_extensions.h> +#ifdef __cplusplus +} // extern "C" +#endif +#include <groonga.h> +#ifdef __cplusplus +extern "C" { +#endif + +extern zend_module_entry groonga_module_entry; +#define phpext_groonga_ptr &groonga_module_entry + +#ifdef PHP_WIN32 +#define PHP_GROONGA_API __declspec(dllexport) +#else +#define PHP_GROONGA_API +#endif + +PHP_MINIT_FUNCTION(groonga); +PHP_MSHUTDOWN_FUNCTION(groonga); +PHP_RINIT_FUNCTION(groonga); +PHP_RSHUTDOWN_FUNCTION(groonga); +PHP_MINFO_FUNCTION(groonga); + +#ifdef ZTS +#include "TSRM.h" +#endif + +#define FREE_RESOURCE(resource) zend_list_delete(Z_LVAL_P(resource)) + +#define PROP_GET_LONG(name) Z_LVAL_P(zend_read_property(_this_ce, _this_zval, #name, strlen(#name), 1 TSRMLS_CC)) +#define PROP_SET_LONG(name, l) zend_update_property_long(_this_ce, _this_zval, #name, strlen(#name), l TSRMLS_CC) + +#define PROP_GET_DOUBLE(name) Z_DVAL_P(zend_read_property(_this_ce, _this_zval, #name, strlen(#name), 1 TSRMLS_CC)) +#define PROP_SET_DOUBLE(name, d) zend_update_property_double(_this_ce, _this_zval, #name, strlen(#name), d TSRMLS_CC) + +#define PROP_GET_STRING(name) Z_STRVAL_P(zend_read_property(_this_ce, _this_zval, #name, strlen(#name), 1 TSRMLS_CC)) +#define PROP_GET_STRLEN(name) Z_STRLEN_P(zend_read_property(_this_ce, _this_zval, #name, strlen(#name), 1 TSRMLS_CC)) +#define PROP_SET_STRING(name, s) zend_update_property_string(_this_ce, _this_zval, #name, strlen(#name), s TSRMLS_CC) +#define PROP_SET_STRINGL(name, s, l) zend_update_property_stringl(_this_ce, _this_zval, #name, strlen(#name), s, l TSRMLS_CC) + + +PHP_FUNCTION(grn_ctx_init); +#if (PHP_MAJOR_VERSION >= 5) +ZEND_BEGIN_ARG_INFO_EX(grn_ctx_init_arg_info, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) + ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO() +#else /* PHP 4.x */ +#define grn_ctx_init_arg_info NULL +#endif + +PHP_FUNCTION(grn_ctx_close); +#if (PHP_MAJOR_VERSION >= 5) +ZEND_BEGIN_ARG_INFO_EX(grn_ctx_close_arg_info, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) + ZEND_ARG_INFO(0, res) +ZEND_END_ARG_INFO() +#else /* PHP 4.x */ +#define grn_ctx_close_arg_info NULL +#endif + +PHP_FUNCTION(grn_ctx_connect); +#if (PHP_MAJOR_VERSION >= 5) +ZEND_BEGIN_ARG_INFO_EX(grn_ctx_connect_arg_info, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 4) + ZEND_ARG_INFO(0, res) + ZEND_ARG_INFO(0, host) + ZEND_ARG_INFO(0, port) + ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO() +#else /* PHP 4.x */ +#define grn_ctx_connect_arg_info NULL +#endif + +PHP_FUNCTION(grn_ctx_send); +#if (PHP_MAJOR_VERSION >= 5) +ZEND_BEGIN_ARG_INFO_EX(grn_ctx_send_arg_info, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 3) + ZEND_ARG_INFO(0, res) + ZEND_ARG_INFO(0, query) + ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO() +#else /* PHP 4.x */ +#define grn_ctx_send_arg_info NULL +#endif + +PHP_FUNCTION(grn_ctx_recv); +#if (PHP_MAJOR_VERSION >= 5) +ZEND_BEGIN_ARG_INFO_EX(grn_ctx_recv_arg_info, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) + ZEND_ARG_INFO(0, res) +ZEND_END_ARG_INFO() +#else /* PHP 4.x */ +#define grn_ctx_recv_arg_info NULL +#endif + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif /* PHP_HAVE_GROONGA */ + +#endif /* PHP_GROONGA_H */ diff --git a/storage/mroonga/vendor/groonga/bindings/php/tests/001.phpt b/storage/mroonga/vendor/groonga/bindings/php/tests/001.phpt new file mode 100644 index 00000000..d215b3ea --- /dev/null +++ b/storage/mroonga/vendor/groonga/bindings/php/tests/001.phpt @@ -0,0 +1,29 @@ +--TEST-- +groonga connection +--DESCRIPTION-- +required: variables_order includes "E" +--SKIPIF-- +<?php +if (!extension_loaded("groonga")) print "skip"; +if (!getenv('GROONGA_TEST_HOST')) print "skip"; +?> +--FILE-- +<?php +$host = getenv('GROONGA_TEST_HOST'); +$port = getenv('GROONGA_TEST_PORT') ? getenv('GROONGA_TEST_PORT') : 10041; + +$grn = grn_ctx_init(); +grn_ctx_connect($grn, $host, $port) or die("cannot connect groong server ({$host}:{$port})"); +grn_ctx_send($grn, 'table_list'); +var_dump(grn_ctx_recv($grn)); +grn_ctx_close($grn); +--EXPECTF-- +array(1) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + string(%d) "%s" + } +} diff --git a/storage/mroonga/vendor/groonga/bindings/python/ql/groongaql.c b/storage/mroonga/vendor/groonga/bindings/python/ql/groongaql.c new file mode 100644 index 00000000..27a35ab9 --- /dev/null +++ b/storage/mroonga/vendor/groonga/bindings/python/ql/groongaql.c @@ -0,0 +1,364 @@ +/* Copyright(C) 2007 Brazil + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA +*/ +#include <Python.h> +#include <groonga.h> + +/* TODO: use exception */ + +typedef struct { + PyObject_HEAD + grn_ctx ctx; + int closed; +} groongaql_ContextObject; + +static PyTypeObject groongaql_ContextType; + +/* Object methods */ + +static PyObject * +groongaql_ContextObject_new(PyTypeObject *type, PyObject *args, PyObject *keywds) +{ + grn_rc rc; + int flags; + grn_encoding encoding; + groongaql_ContextObject *self; + + static char *kwlist[] = {"flags", "encoding", NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, keywds, "ii", kwlist, + &flags, &encoding)) { + return NULL; + } + if (!(self = (groongaql_ContextObject *)type->tp_alloc(type, 0))) { + return NULL; + } + Py_BEGIN_ALLOW_THREADS + rc = grn_ctx_init(&self->ctx, flags); + GRN_CTX_SET_ENCODING(&self->ctx, encoding); + Py_END_ALLOW_THREADS + if (rc) { + self->ob_type->tp_free(self); + return NULL; + } + self->closed = 0; + return (PyObject *)self; +} + +static void +groongaql_ContextObject_dealloc(groongaql_ContextObject *self) +{ + if (!self->closed) { + Py_BEGIN_ALLOW_THREADS + grn_ctx_fin(&self->ctx); + Py_END_ALLOW_THREADS + } + self->ob_type->tp_free(self); +} + +/* Class methods */ + +/* instance methods */ + +static PyObject * +groongaql_ContextClass_ql_connect(groongaql_ContextObject *self, PyObject *args, PyObject *keywds) +{ + grn_rc rc; + int port, flags; + const char *host; + static char *kwlist[] = {"host", "port", "flags", NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, keywds, "sii", kwlist, + &host, &port, &flags)) { + return NULL; + } + if (self->closed) { return NULL; } + Py_BEGIN_ALLOW_THREADS + rc = grn_ctx_connect(&self->ctx, host, port, flags); + Py_END_ALLOW_THREADS + return Py_BuildValue("i", rc); +} + +static PyObject * +groongaql_Context_ql_send(groongaql_ContextObject *self, PyObject *args, PyObject *keywds) +{ + grn_rc rc; + char *str; + int str_len, flags; + static char *kwlist[] = {"str", "flags", NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, keywds, "s#i", kwlist, + &str, + &str_len, + &flags)) { + return NULL; + } + if (self->closed) { return NULL; } + Py_BEGIN_ALLOW_THREADS + rc = grn_ctx_send(&self->ctx, str, str_len, flags); + Py_END_ALLOW_THREADS + return Py_BuildValue("i", rc); +} + +static PyObject * +groongaql_Context_ql_recv(groongaql_ContextObject *self) +{ + grn_rc rc; + int flags; + char *str; + unsigned int str_len; + + if (self->closed) { return NULL; } + Py_BEGIN_ALLOW_THREADS + rc = grn_ctx_recv(&self->ctx, &str, &str_len, &flags); + Py_END_ALLOW_THREADS + return Py_BuildValue("(is#i)", rc, str, str_len, flags); +} + +static PyObject * +groongaql_Context_fin(groongaql_ContextObject *self) +{ + grn_rc rc; + + if (self->closed) { return NULL; } + Py_BEGIN_ALLOW_THREADS + rc = grn_ctx_fin(&self->ctx); + Py_END_ALLOW_THREADS + if (!rc) { + self->closed = 1; + } + return Py_BuildValue("i", rc); +} + +static PyObject * +groongaql_Context_ql_info_get(groongaql_ContextObject *self) +{ + grn_rc rc; + grn_ctx_info info; + + if (self->closed) { return NULL; } + rc = grn_ctx_info_get(&self->ctx, &info); + /* TODO: handling unsigned int properlly */ + /* TODO: get outbuf */ + return Py_BuildValue("{s:i,s:i,s:i}", + "rc", rc, + "com_status", info.com_status, + /* "outbuf", info.outbuf, */ + "stat", info.stat + ); +} + +/* methods of classes */ + +static PyMethodDef groongaql_Context_methods[] = { + {"ql_connect", (PyCFunction)groongaql_ContextClass_ql_connect, + METH_VARARGS | METH_KEYWORDS, + "Create a remote groonga context."}, + {"ql_send", (PyCFunction)groongaql_Context_ql_send, + METH_VARARGS | METH_KEYWORDS, + "Send message to context."}, + {"ql_recv", (PyCFunction)groongaql_Context_ql_recv, + METH_NOARGS, + "Receive message from context."}, + {"fin", (PyCFunction)groongaql_Context_fin, + METH_NOARGS, + "Release groonga context."}, + {"ql_info_get", (PyCFunction)groongaql_Context_ql_info_get, + METH_NOARGS, + "Get QL context information."}, + {NULL, NULL, 0, NULL} +}; + +static PyMethodDef module_methods[] = { + {NULL, NULL, 0, NULL} +}; + +/* type objects */ + +static PyTypeObject groongaql_ContextType = { + PyObject_HEAD_INIT(NULL) + 0, /* ob_size */ + "groongaql.Context", /* tp_name */ + sizeof(groongaql_ContextObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)groongaql_ContextObject_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_compare */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT, /* tp_flags */ + "groonga Context objects", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + groongaql_Context_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + groongaql_ContextObject_new, /* tp_new */ +}; + +/* consts */ + +typedef struct _ConstPair { + const char *name; + int value; +} ConstPair; + +static ConstPair consts[] = { + /* grn_rc */ + {"SUCCESS", GRN_SUCCESS}, + {"END_OF_DATA", GRN_END_OF_DATA}, + {"UNKNOWN_ERROR", GRN_UNKNOWN_ERROR}, + {"OPERATION_NOT_PERMITTED", GRN_OPERATION_NOT_PERMITTED}, + {"NO_SUCH_FILE_OR_DIRECTORY", GRN_NO_SUCH_FILE_OR_DIRECTORY}, + {"NO_SUCH_PROCESS", GRN_NO_SUCH_PROCESS}, + {"INTERRUPTED_FUNCTION_CALL", GRN_INTERRUPTED_FUNCTION_CALL}, + {"INPUT_OUTPUT_ERROR", GRN_INPUT_OUTPUT_ERROR}, + {"NO_SUCH_DEVICE_OR_ADDRESS", GRN_NO_SUCH_DEVICE_OR_ADDRESS}, + {"ARG_LIST_TOO_LONG", GRN_ARG_LIST_TOO_LONG}, + {"EXEC_FORMAT_ERROR", GRN_EXEC_FORMAT_ERROR}, + {"BAD_FILE_DESCRIPTOR", GRN_BAD_FILE_DESCRIPTOR}, + {"NO_CHILD_PROCESSES", GRN_NO_CHILD_PROCESSES}, + {"RESOURCE_TEMPORARILY_UNAVAILABLE", GRN_RESOURCE_TEMPORARILY_UNAVAILABLE}, + {"NOT_ENOUGH_SPACE", GRN_NOT_ENOUGH_SPACE}, + {"PERMISSION_DENIED", GRN_PERMISSION_DENIED}, + {"BAD_ADDRESS", GRN_BAD_ADDRESS}, + {"RESOURCE_BUSY", GRN_RESOURCE_BUSY}, + {"FILE_EXISTS", GRN_FILE_EXISTS}, + {"IMPROPER_LINK", GRN_IMPROPER_LINK}, + {"NO_SUCH_DEVICE", GRN_NO_SUCH_DEVICE}, + {"NOT_A_DIRECTORY", GRN_NOT_A_DIRECTORY}, + {"IS_A_DIRECTORY", GRN_IS_A_DIRECTORY}, + {"INVALID_ARGUMENT", GRN_INVALID_ARGUMENT}, + {"TOO_MANY_OPEN_FILES_IN_SYSTEM", GRN_TOO_MANY_OPEN_FILES_IN_SYSTEM}, + {"TOO_MANY_OPEN_FILES", GRN_TOO_MANY_OPEN_FILES}, + {"INAPPROPRIATE_I_O_CONTROL_OPERATION", GRN_INAPPROPRIATE_I_O_CONTROL_OPERATION}, + {"FILE_TOO_LARGE", GRN_FILE_TOO_LARGE}, + {"NO_SPACE_LEFT_ON_DEVICE", GRN_NO_SPACE_LEFT_ON_DEVICE}, + {"INVALID_SEEK", GRN_INVALID_SEEK}, + {"READ_ONLY_FILE_SYSTEM", GRN_READ_ONLY_FILE_SYSTEM}, + {"TOO_MANY_LINKS", GRN_TOO_MANY_LINKS}, + {"BROKEN_PIPE", GRN_BROKEN_PIPE}, + {"DOMAIN_ERROR", GRN_DOMAIN_ERROR}, + {"RESULT_TOO_LARGE", GRN_RESULT_TOO_LARGE}, + {"RESOURCE_DEADLOCK_AVOIDED", GRN_RESOURCE_DEADLOCK_AVOIDED}, + {"NO_MEMORY_AVAILABLE", GRN_NO_MEMORY_AVAILABLE}, + {"FILENAME_TOO_LONG", GRN_FILENAME_TOO_LONG}, + {"NO_LOCKS_AVAILABLE", GRN_NO_LOCKS_AVAILABLE}, + {"FUNCTION_NOT_IMPLEMENTED", GRN_FUNCTION_NOT_IMPLEMENTED}, + {"DIRECTORY_NOT_EMPTY", GRN_DIRECTORY_NOT_EMPTY}, + {"ILLEGAL_BYTE_SEQUENCE", GRN_ILLEGAL_BYTE_SEQUENCE}, + {"SOCKET_NOT_INITIALIZED", GRN_SOCKET_NOT_INITIALIZED}, + {"OPERATION_WOULD_BLOCK", GRN_OPERATION_WOULD_BLOCK}, + {"ADDRESS_IS_NOT_AVAILABLE", GRN_ADDRESS_IS_NOT_AVAILABLE}, + {"NETWORK_IS_DOWN", GRN_NETWORK_IS_DOWN}, + {"NO_BUFFER", GRN_NO_BUFFER}, + {"SOCKET_IS_ALREADY_CONNECTED", GRN_SOCKET_IS_ALREADY_CONNECTED}, + {"SOCKET_IS_NOT_CONNECTED", GRN_SOCKET_IS_NOT_CONNECTED}, + {"SOCKET_IS_ALREADY_SHUTDOWNED", GRN_SOCKET_IS_ALREADY_SHUTDOWNED}, + {"OPERATION_TIMEOUT", GRN_OPERATION_TIMEOUT}, + {"CONNECTION_REFUSED", GRN_CONNECTION_REFUSED}, + {"RANGE_ERROR", GRN_RANGE_ERROR}, + {"TOKENIZER_ERROR", GRN_TOKENIZER_ERROR}, + {"FILE_CORRUPT", GRN_FILE_CORRUPT}, + {"INVALID_FORMAT", GRN_INVALID_FORMAT}, + {"OBJECT_CORRUPT", GRN_OBJECT_CORRUPT}, + {"TOO_MANY_SYMBOLIC_LINKS", GRN_TOO_MANY_SYMBOLIC_LINKS}, + {"NOT_SOCKET", GRN_NOT_SOCKET}, + {"OPERATION_NOT_SUPPORTED", GRN_OPERATION_NOT_SUPPORTED}, + {"ADDRESS_IS_IN_USE", GRN_ADDRESS_IS_IN_USE}, + {"ZLIB_ERROR", GRN_ZLIB_ERROR}, + {"LZO_ERROR", GRN_LZO_ERROR}, + /* grn_encoding */ + {"ENC_DEFAULT", GRN_ENC_DEFAULT}, + {"ENC_NONE", GRN_ENC_NONE}, + {"ENC_EUC_JP", GRN_ENC_EUC_JP}, + {"ENC_UTF8", GRN_ENC_UTF8}, + {"ENC_SJIS", GRN_ENC_SJIS}, + {"ENC_LATIN1", GRN_ENC_LATIN1}, + {"ENC_KOI8R", GRN_ENC_KOI8R}, + /* grn_ctx flags */ + {"CTX_USE_QL", GRN_CTX_USE_QL}, + {"CTX_BATCH_MODE", GRN_CTX_BATCH_MODE}, + {"CTX_MORE", GRN_CTX_MORE}, + {"CTX_TAIL", GRN_CTX_TAIL}, + {"CTX_HEAD", GRN_CTX_HEAD}, + {"CTX_QUIET", GRN_CTX_QUIET}, + {"CTX_QUIT", GRN_CTX_QUIT}, + {"CTX_FIN", GRN_CTX_FIN}, + /* end */ + {NULL, 0} +}; + +#ifndef PyMODINIT_FUNC +#define PyMODINIT_FUNC void +#endif +PyMODINIT_FUNC +initgroongaql(void) +{ + unsigned int i; + PyObject *m, *dict; + + if (!(m = Py_InitModule3("groongaql", module_methods, + "groonga ql module."))) { + goto exit; + } + grn_init(); + + /* register classes */ + + if (PyType_Ready(&groongaql_ContextType) < 0) { goto exit; } + Py_INCREF(&groongaql_ContextType); + PyModule_AddObject(m, "Context", (PyObject *)&groongaql_ContextType); + + /* register consts */ + + if (!(dict = PyModule_GetDict(m))) { goto exit; } + + for (i = 0; consts[i].name; i++) { + PyObject *v; + if (!(v = PyInt_FromLong(consts[i].value))) { + goto exit; + } + PyDict_SetItemString(dict, consts[i].name, v); + Py_DECREF(v); + } + if (Py_AtExit((void (*)(void))grn_fin)) { goto exit; } +exit: + if (PyErr_Occurred()) { + PyErr_SetString(PyExc_ImportError, "groongaql: init failed"); + } +} diff --git a/storage/mroonga/vendor/groonga/bindings/python/ql/setup.py b/storage/mroonga/vendor/groonga/bindings/python/ql/setup.py new file mode 100755 index 00000000..3b800554 --- /dev/null +++ b/storage/mroonga/vendor/groonga/bindings/python/ql/setup.py @@ -0,0 +1,22 @@ +#!/usr/bin/python +from distutils.core import setup, Extension + +#cflags = ['-Wall', '-fPIC', '-g', '-O0'] +cflags = ['-Wall', '-fPIC', '-O3'] + +ext = Extension('groongaql', + libraries = ['groonga'], + sources = ['groongaql.c'], + extra_compile_args = cflags) + +setup(name = 'groongaql', + version = '1.0', + description = 'python GQTP', + long_description = ''' + This is a GQTP Python API package. + ''', + license='GNU LESSER GENERAL PUBLIC LICENSE', + author = 'Brazil', + author_email = 'groonga at razil.jp', + ext_modules = [ext] + ) |