summaryrefslogtreecommitdiff
path: root/ext/mnogosearch
diff options
context:
space:
mode:
authorSergey Kartashoff <gluke@php.net>2004-05-08 11:50:40 +0000
committerSergey Kartashoff <gluke@php.net>2004-05-08 11:50:40 +0000
commit26fea0bd809a06b505d9af69e606ded18e565692 (patch)
tree20380a13126ab85c16048d4392f04106d8710882 /ext/mnogosearch
parent96132bf4fedad3b1075799f7e9ab7ad20a5bdd27 (diff)
downloadphp-git-26fea0bd809a06b505d9af69e606ded18e565692.tar.gz
- mnoGoSearch extension was updated to support CachedCopies of
mnogosearch-3.2.16 or later. Udm_Get_Agent_Param and Udm_Store_Doc_Cgi functions were added. MnoGoSearch-3.2.3 stored API was removed.
Diffstat (limited to 'ext/mnogosearch')
-rw-r--r--ext/mnogosearch/php_mnogo.c297
-rw-r--r--ext/mnogosearch/php_mnogo.h19
2 files changed, 153 insertions, 163 deletions
diff --git a/ext/mnogosearch/php_mnogo.c b/ext/mnogosearch/php_mnogo.c
index 81a8aa310d..82355eb7ba 100644
--- a/ext/mnogosearch/php_mnogo.c
+++ b/ext/mnogosearch/php_mnogo.c
@@ -3,9 +3,9 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 4 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2003 The PHP Group |
+----------------------------------------------------------------------+
| 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 |
@@ -77,7 +77,7 @@
#define UDM_PARAM_HLBEG 19
#define UDM_PARAM_HLEND 20
#define UDM_PARAM_SYNONYM 21
-#define UDM_PARAM_SEARCHD 22
+#define UDM_PARAM_SEARCHD 22 /* unused */
#define UDM_PARAM_QSTRING 23
#define UDM_PARAM_REMOTE_ADDR 24
#define UDM_PARAM_QUERY 25
@@ -156,11 +156,6 @@ function_entry mnogosearch_functions[] = {
#if UDM_VERSION_ID >= 30200
PHP_FE(udm_check_charset, NULL)
-#if UDM_VERSION_ID == 30203
- PHP_FE(udm_open_stored, NULL)
- PHP_FE(udm_check_stored,NULL)
- PHP_FE(udm_close_stored,NULL)
-#endif
#if UDM_VERSION_ID >= 30203
PHP_FE(udm_crc32, NULL)
#endif
@@ -168,12 +163,16 @@ function_entry mnogosearch_functions[] = {
PHP_FE(udm_parse_query_string, NULL)
PHP_FE(udm_make_excerpt, NULL)
PHP_FE(udm_set_agent_param_ex, NULL)
+ PHP_FE(udm_get_agent_param_ex, NULL)
PHP_FE(udm_get_res_field_ex, NULL)
#endif
#if UDM_VERSION_ID >= 30211
PHP_FE(udm_hash32, NULL)
PHP_FE(udm_alloc_agent_array, NULL)
#endif
+#if UDM_VERSION_ID >= 30216
+ PHP_FE(udm_store_doc_cgi, NULL)
+#endif
#endif
PHP_FE(udm_alloc_agent, NULL)
@@ -317,7 +316,6 @@ DLEXPORT PHP_MINIT_FUNCTION(mnogosearch)
REGISTER_LONG_CONSTANT("UDM_PARAM_HLEND", UDM_PARAM_HLEND,CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("UDM_PARAM_SYNONYM", UDM_PARAM_SYNONYM,CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("UDM_PARAM_SEARCHD", UDM_PARAM_SEARCHD,CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("UDM_PARAM_STORED", UDM_PARAM_STORED,CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("UDM_PARAM_GROUPBYSITE", UDM_PARAM_GROUPBYSITE,CONST_CS | CONST_PERSISTENT);
@@ -908,18 +906,6 @@ DLEXPORT PHP_FUNCTION(udm_set_agent_param)
#endif
break;
- case UDM_PARAM_SEARCHD:
-#if UDM_VERSION_ID <= 30203
- UdmSDCLientListAdd(&(Agent->Conf->sdcl),val);
- {
- size_t i;
- for(i=0;i<Agent->Conf->sdcl.nclients;i++){
- UdmSDCLientListAdd(&Agent->sdcl,Agent->Conf->sdcl.Clients[i].addr);
- }
- }
-#endif
- break;
-
case UDM_PARAM_QSTRING:
#if UDM_VERSION_ID >= 30204
UdmVarListReplaceStr(&Agent->Conf->Vars,"QUERY_STRING",val);
@@ -1472,6 +1458,7 @@ DLEXPORT PHP_FUNCTION(udm_clear_search_limits)
if ((!strcasecmp("ul",Agent->Conf->Vars.Var[i].name))||
(!strcasecmp("cat",Agent->Conf->Vars.Var[i].name))||
(!strcasecmp("t",Agent->Conf->Vars.Var[i].name))||
+ (!strcasecmp("type",Agent->Conf->Vars.Var[i].name))||
(!strcasecmp("lang",Agent->Conf->Vars.Var[i].name))) {
UDM_FREE(Agent->Conf->Vars.Var[i].name);
UDM_FREE(Agent->Conf->Vars.Var[i].val);
@@ -1553,136 +1540,6 @@ DLEXPORT PHP_FUNCTION(udm_crc32)
/* }}} */
#endif
-#if UDM_VERSION_ID == 30203
-
-static ssize_t UdmRecvAll(int s, void *buf, size_t len, int flags) {
- size_t received = 0, r;
- char *b = buf;
- while ( (received < len) && ((r = recv(s, &b[received], len - received, flags)) >= 0 ) ) {
- received += r;
- }
- return received;
-}
-
-
-/* {{{ proto int udm_open_stored(int agent, string storedaddr)
- Open connection to stored */
-DLEXPORT PHP_FUNCTION(udm_open_stored)
-{
- pval ** yyagent, ** yyaddr;
-
- int s;
- char * addr;
- const char *hello = "F\0";
-
- UDM_AGENT * Agent;
- int id=-1;
-
- switch(ZEND_NUM_ARGS()){
- case 2: {
- if (zend_get_parameters_ex(2, &yyagent, &yyaddr)==FAILURE) {
- RETURN_FALSE;
- }
- }
- break;
- default:
- WRONG_PARAM_COUNT;
- break;
- }
- ZEND_FETCH_RESOURCE(Agent, UDM_AGENT *, yyagent, id, "mnoGoSearch-Agent", le_link);
-
- convert_to_string_ex(yyaddr);
- addr = Z_STRVAL_PP(yyaddr);
-
- UdmReplaceStrVar(Agent->Conf->vars,"StoredAddr",addr,UDM_VARSRC_GLOBAL);
- Agent->Conf->stored_addr = strdup(UdmFindStrVar(Agent->Conf->vars, "StoredAddr", "localhost"));
-
- s = UdmStoreOpen(Agent->Conf);
-
- if (s >= 0) {
- send(s, hello, 1, 0);
- RETURN_LONG(s);
- } else RETURN_FALSE;
-}
-/* }}} */
-
-/* {{{ proto int udm_close_stored(int agent, int link)
- Open connection to stored */
-DLEXPORT PHP_FUNCTION(udm_close_stored)
-{
- pval ** yylink, ** yyagent;
-
- int s;
- unsigned int rec_id = 0;
-
- UDM_AGENT * Agent;
- int id=-1;
-
- switch(ZEND_NUM_ARGS()){
- case 2: {
- if (zend_get_parameters_ex(2, &yyagent, &yylink)==FAILURE) {
- RETURN_FALSE;
- }
- }
- break;
- default:
- WRONG_PARAM_COUNT;
- break;
- }
- ZEND_FETCH_RESOURCE(Agent, UDM_AGENT *, yyagent, id, "mnoGoSearch-Agent", le_link);
-
- convert_to_long_ex(yylink);
- s = Z_LVAL_PP(yylink);
-
-
- send(s, &rec_id, sizeof(rec_id), 0);
- closesocket(s);
-
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto int udm_check_stored(int agent, int link, string doc_id)
- Open connection to stored */
-DLEXPORT PHP_FUNCTION(udm_check_stored)
-{
- pval ** yyid, ** yylink, ** yyagent;
-
- int s;
- unsigned int rec_id = 0;
- int store_found;
-
- UDM_AGENT * Agent;
- int id=-1;
-
- switch(ZEND_NUM_ARGS()){
- case 3: {
- if (zend_get_parameters_ex(3, &yyagent, &yylink, &yyid)==FAILURE) {
- RETURN_FALSE;
- }
- }
- break;
- default:
- WRONG_PARAM_COUNT;
- break;
- }
- ZEND_FETCH_RESOURCE(Agent, UDM_AGENT *, yyagent, id, "mnoGoSearch-Agent", le_link);
-
- convert_to_long_ex(yylink);
- s = Z_LVAL_PP(yylink);
-
- convert_to_string_ex(yyid);
-
- rec_id=strtoul(Z_STRVAL_PP(yyid),NULL,10);
-
- send(s, &rec_id, sizeof(rec_id), 0);
- if (UdmRecvAll(s, &store_found, sizeof(store_found), MSG_WAITALL) < 0) {
- RETURN_LONG(store_found);
- } else RETURN_FALSE;
-}
-/* }}} */
-#endif
-
#if UDM_VERSION_ID >= 30204
/* {{{ proto int udm_parse_query_string(int agent, string str)
Parses query string, initialises variables and search limits taken from it */
@@ -1838,6 +1695,36 @@ DLEXPORT PHP_FUNCTION(udm_set_agent_param_ex)
RETURN_TRUE;
}
+/* {{{ proto string udm_get_agent_param_ex(int agent, string field)
+ Fetch mnoGoSearch environment parameters */
+DLEXPORT PHP_FUNCTION(udm_get_agent_param_ex)
+{
+ pval **yyagent, **yyfield_name;
+
+ UDM_AGENT * Agent;
+ int row;
+ char *field;
+
+ switch(ZEND_NUM_ARGS()){
+ case 2: {
+ if (zend_get_parameters_ex(2, &yyagent,&yyfield_name)==FAILURE){
+ RETURN_FALSE;
+ }
+ convert_to_string_ex(yyfield_name);
+ field = Z_STRVAL_PP(yyfield_name);
+ }
+ break;
+ default:
+ WRONG_PARAM_COUNT;
+ break;
+ }
+
+ ZEND_FETCH_RESOURCE(Agent, UDM_AGENT *, yyagent, -1, "mnoGoSearch-agent", le_link);
+
+ RETURN_STRING((char *)UdmVarListFindStr(&Agent->Conf->Vars,field,""),1);
+}
+/* }}} */
+
/* {{{ proto string udm_get_res_field_ex(int res, int row, string field)
Fetch mnoGoSearch result field */
DLEXPORT PHP_FUNCTION(udm_get_res_field_ex)
@@ -1881,6 +1768,110 @@ DLEXPORT PHP_FUNCTION(udm_get_res_field_ex)
/* }}} */
#endif
+#if UDM_VERSION_ID >= 30216
+/* {{{ proto int udm_store_doc_cgi(int agent)
+ Get CachedCopy of document and return TRUE if cached copy found */
+DLEXPORT PHP_FUNCTION(udm_store_doc_cgi)
+{
+ pval ** yyagent;
+ UDM_AGENT * Agent;
+ int id=-1;
+
+ const char *htok;
+ char *last = NULL;
+ UDM_DOCUMENT *Doc;
+ UDM_RESULT *Res;
+ UDM_HTMLTOK tag;
+ char *HDoc=NULL;
+ char *HEnd=NULL;
+ char ch;
+ const char *content_type, *charset;
+ UDM_CHARSET *cs;
+
+ switch(ZEND_NUM_ARGS()){
+ case 1: {
+ if (zend_get_parameters_ex(1, &yyagent)==FAILURE) {
+ RETURN_FALSE;
+ }
+ }
+ break;
+ default:
+ WRONG_PARAM_COUNT;
+ break;
+ }
+ ZEND_FETCH_RESOURCE(Agent, UDM_AGENT *, yyagent, id, "mnoGoSearch-Agent", le_link);
+
+ Doc=UdmDocInit(NULL);
+ Res=UdmResultInit(NULL);
+
+ UdmPrepare(Agent,Res);
+ UdmVarListReplaceStr(&Doc->Sections, "URL", UdmVarListFindStr(&Agent->Conf->Vars, "URL", "0"));
+ UdmURLAction(Agent, Doc, UDM_URL_ACTION_GET_CACHED_COPY);
+ UdmVarListReplaceLst(&Agent->Conf->Vars, &Doc->Sections, NULL, "*");
+
+ charset = UdmVarListFindStr(&Agent->Conf->Vars,"Charset","iso-8859-1");
+ cs = UdmGetCharSet(charset);
+
+ /* UnStore Doc, Highlight and Display */
+
+ content_type = UdmVarListFindStr(&Agent->Conf->Vars, "Content-Type", "text/html");
+
+ if(!Doc->Buf.content) {
+ UdmResultFree(Res);
+ UdmDocFree(Doc);
+ UDM_FREE(HDoc);
+
+ RETURN_FALSE;
+ }
+
+ HEnd=HDoc = (char*)UdmMalloc(UDM_MAXDOCSIZE + 32);
+ *HEnd='\0';
+
+ if (strncasecmp(content_type, "text/plain", 10) == 0) {
+ sprintf(HEnd, "<pre>\n");
+ HEnd += strlen(HEnd);
+ }
+
+ UdmHTMLTOKInit(&tag);
+ for(htok = UdmHTMLToken(Doc->Buf.content, (const char **)&last, &tag) ; htok ;) {
+ switch(tag.type) {
+ case UDM_HTML_COM:
+ case UDM_HTML_TAG:
+ memcpy(HEnd,htok,(size_t)(last-htok));
+ HEnd+=last-htok;
+ HEnd[0]='\0';
+ UdmHTMLParseTag(&tag,Doc);
+ break;
+ case UDM_HTML_TXT:
+ ch = *last; *last = '\0';
+ if (tag.title || tag.script) {
+ sprintf(HEnd, "%s", UdmHlConvert(NULL, htok, cs, cs));
+ } else {
+ sprintf(HEnd, "%s", UdmHlConvert(&Res->WWList, htok, cs, cs));
+ }
+ HEnd=UDM_STREND(HEnd);
+ *last = ch;
+ break;
+ }
+ htok = UdmHTMLToken(NULL, (const char **)&last, &tag);
+ }
+
+ if (strncasecmp(content_type, "text/plain", 10) == 0) {
+ sprintf(HEnd, "</pre>\n");
+ HEnd += strlen(HEnd);
+ }
+
+ UdmVarListAddStr(&Agent->Conf->Vars, "document", HDoc);
+
+ UdmResultFree(Res);
+ UdmDocFree(Doc);
+ UDM_FREE(HDoc);
+
+ RETURN_TRUE;
+}
+/* }}} */
+#endif
+
#if UDM_VERSION_ID >= 30211
/* {{{ proto int udm_alloc_agent_array(array dbaddr)
Allocate mnoGoSearch session */
@@ -2152,7 +2143,7 @@ DLEXPORT PHP_FUNCTION(udm_get_res_field)
#endif
break;
- case UDM_FIELD_CATEGORY:
+ case UDM_FIELD_CATEGORY:
#if UDM_VERSION_ID >= 30204
RETURN_STRING((char *)UdmVarListFindStr(&(Res->Doc[row].Sections),"Category",""),1);
#else
@@ -2161,7 +2152,7 @@ DLEXPORT PHP_FUNCTION(udm_get_res_field)
break;
#if UDM_VERSION_ID >= 30203
- case UDM_FIELD_LANG:
+ case UDM_FIELD_LANG:
#if UDM_VERSION_ID >= 30204
RETURN_STRING((char *)UdmVarListFindStr(&(Res->Doc[row].Sections),"Content-Language",""),1);
#else
diff --git a/ext/mnogosearch/php_mnogo.h b/ext/mnogosearch/php_mnogo.h
index 260498b1ba..f2a2ec5eb2 100644
--- a/ext/mnogosearch/php_mnogo.h
+++ b/ext/mnogosearch/php_mnogo.h
@@ -3,14 +3,14 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 4 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2003 The PHP Group |
+----------------------------------------------------------------------+
- | This source file is subject to version 3.0 of the PHP license, |
+ | This source file is subject to version 2.02 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_0.txt. |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.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. |
@@ -57,11 +57,6 @@ DLEXPORT PHP_MINFO_FUNCTION(mnogosearch);
DLEXPORT PHP_FUNCTION(udm_api_version);
#if UDM_VERSION_ID >= 30200
DLEXPORT PHP_FUNCTION(udm_check_charset);
-#if UDM_VERSION_ID == 30203
-DLEXPORT PHP_FUNCTION(udm_open_stored);
-DLEXPORT PHP_FUNCTION(udm_check_stored);
-DLEXPORT PHP_FUNCTION(udm_close_stored);
-#endif
#if UDM_VERSION_ID >= 30203
DLEXPORT PHP_FUNCTION(udm_crc32);
#endif
@@ -69,12 +64,16 @@ DLEXPORT PHP_FUNCTION(udm_crc32);
DLEXPORT PHP_FUNCTION(udm_parse_query_string);
DLEXPORT PHP_FUNCTION(udm_make_excerpt);
DLEXPORT PHP_FUNCTION(udm_set_agent_param_ex);
+DLEXPORT PHP_FUNCTION(udm_get_agent_param_ex);
DLEXPORT PHP_FUNCTION(udm_get_res_field_ex);
#endif
#if UDM_VERSION_ID >= 30211
DLEXPORT PHP_FUNCTION(udm_hash32);
DLEXPORT PHP_FUNCTION(udm_alloc_agent_array);
#endif
+#if UDM_VERSION_ID >= 30216
+DLEXPORT PHP_FUNCTION(udm_store_doc_cgi);
+#endif
#endif
DLEXPORT PHP_FUNCTION(udm_alloc_agent);