cvs: php4 /ext/mnogosearch index.php php_mnogo.c php_mnogo.h

From: Date: Sat, 01 Dec 2001 20:09:15 +0000
Subject: cvs: php4 /ext/mnogosearch index.php php_mnogo.c php_mnogo.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-8360@lists.php.net to get a copy of this message
gluke Sat Dec 1 15:09:15 2001 EDT Modified files: /php4/ext/mnogosearch index.php php_mnogo.c php_mnogo.h Log: - Added stored API to mnoGoSearch module. Now you can check if URL is places at the stored database ot not. Example updated.

Index: php4/ext/mnogosearch/index.php diff -u php4/ext/mnogosearch/index.php:1.7 php4/ext/mnogosearch/index.php:1.8 --- php4/ext/mnogosearch/index.php:1.7 Sat Dec 1 09:12:26 2001 +++ php4/ext/mnogosearch/index.php Sat Dec 1 15:09:14 2001 @@ -2,7 +2,7 @@ /* $Source: /usr/repository/php4/ext/mnogosearch/index.php,v $ - $Id: index.php,v 1.7 2001/12/01 14:12:26 gluke Exp $ + $Id: index.php,v 1.8 2001/12/01 20:09:14 gluke Exp $ */ /* mnoGoSearch-php-lite v.1.2 @@ -69,6 +69,9 @@ if ($db=="") $db='01/01/1970'; if ($de=="") $de='31/12/2020'; +$storedaddr="localhost"; +$storedocurl='/cgi-bin/storedoc.cgi'; + if (isset($q)) { $q=urldecode($q); $have_query_flag=1; @@ -900,6 +903,12 @@ print("Search Time: $searchtime<br>Search results: <small>$wordinfo</small><HR>\n"); print("Displaying documents $first_doc-$last_doc of total <B>$found</B> found.\n"); + $stored_link=-1; + if ((Udm_Api_Version() >= 30203) && ($storedaddr != '')) { + Udm_Set_Agent_Param($udm_agent,UDM_PARAM_STOREDADDR,$storedaddr); + $stored_link=Udm_Open_Stored($udm_agent); + } + for($i=0;$i<$rows;$i++){ $ndoc=Udm_Get_Res_Field($res,$i,UDM_FIELD_ORDER); $rating=Udm_Get_Res_Field($res,$i,UDM_FIELD_RATING); @@ -937,16 +946,24 @@ print ("($contype) $lastmod, $docsize bytes</UL></DL>\n"); if (Udm_Api_Version() >= 30203) { - $storedstr="$storedocurl?rec_id=".Udm_CRC32($udm_agent,$url). - "&DM=".urlencode($lastmod). - "&DS=$docsize". - "&L=$doclang". - "&CS=$doccharset". - "&DU=".urlencode($url). - "&q=".urlencode($query_orig); - print ("<DD><a href=\"$storedstr\">Cached copy</a>\n"); + if ((($stored_link>0) && (Udm_Check_Stored($udm_agent,$stored_link,Udm_CRC32($udm_agent,$url)))) || + ($stored_link==-1)) { + $storedstr="$storedocurl?rec_id=".Udm_CRC32($udm_agent,$url). + "&DM=".urlencode($lastmod). + "&DS=$docsize". + "&L=$doclang". + "&CS=$doccharset". + "&DU=".urlencode($url). + "&q=".urlencode($query_orig); + print ("<DD><a href=\"$storedstr\">Cached copy</a>\n"); + } } } + + if ((Udm_Api_Version() >= 30203) && + ($stored_link>0)) { + Udm_Close_Stored($udm_agent, $stored_link); + } print("<HR><CENTER> $nav </CENTER>\n"); print_bottom(); Index: php4/ext/mnogosearch/php_mnogo.c diff -u php4/ext/mnogosearch/php_mnogo.c:1.44 php4/ext/mnogosearch/php_mnogo.c:1.45 --- php4/ext/mnogosearch/php_mnogo.c:1.44 Sat Dec 1 09:05:12 2001 +++ php4/ext/mnogosearch/php_mnogo.c Sat Dec 1 15:09:14 2001 @@ -1,5 +1,5 @@ /* $Source: /usr/repository/php4/ext/mnogosearch/php_mnogo.c,v $ */ -/* $Id: php_mnogo.c,v 1.44 2001/12/01 14:05:12 gluke Exp $ */ +/* $Id: php_mnogo.c,v 1.45 2001/12/01 20:09:14 gluke Exp $ */ /* +----------------------------------------------------------------------+ @@ -73,6 +73,7 @@ #define UDM_PARAM_BROWSER_CHARSET 18 #define UDM_PARAM_HLBEG 19 #define UDM_PARAM_HLEND 20 +#define UDM_PARAM_STOREDADDR 21 /* udm_add_search_limit constants */ #define UDM_LIMIT_URL 1 @@ -137,6 +138,9 @@ #if UDM_VERSION_ID >= 30203 PHP_FE(udm_crc32, NULL) + PHP_FE(udm_open_stored, NULL) + PHP_FE(udm_check_stored,NULL) + PHP_FE(udm_close_stored,NULL) #endif PHP_FE(udm_alloc_agent, NULL) @@ -266,6 +270,8 @@ REGISTER_LONG_CONSTANT("UDM_PARAM_HLBEG", UDM_PARAM_HLBEG,CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("UDM_PARAM_HLEND", UDM_PARAM_HLEND,CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("UDM_PARAM_STOREDADDR", UDM_PARAM_STOREDADDR,CONST_CS | CONST_PERSISTENT); + /* udm_add_search_limit constants */ REGISTER_LONG_CONSTANT("UDM_LIMIT_CAT", UDM_LIMIT_CAT,CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("UDM_LIMIT_URL", UDM_LIMIT_URL,CONST_CS | CONST_PERSISTENT); @@ -360,6 +366,14 @@ php_info_print_table_end(); } +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_alloc_agent(string dbaddr [, string dbmode]) Allocate mnoGoSearch session */ @@ -673,6 +687,14 @@ break; +#if UDM_VERSION_ID >= 30203 + case UDM_PARAM_STOREDADDR: + UdmReplaceStrVar(Agent->Conf->vars,"StoredAddr",val,UDM_VARSRC_GLOBAL); + Agent->Conf->stored_addr = strdup(UdmFindStrVar(Agent->Conf->vars, "StoredAddr", "localhost")); + + break; +#endif + #endif case UDM_PARAM_STOPTABLE: @@ -1093,8 +1115,117 @@ RETURN_STRING(buf,1); } /* }}} */ -#endif +/* {{{ proto int udm_open_stored(int agent) + Open connection to stored */ +DLEXPORT PHP_FUNCTION(udm_open_stored) +{ + pval ** yyagent; + + int s; + const char *hello = "F\0"; + + UDM_AGENT * Agent; + int id=-1; + + 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); + + 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 /* {{{ proto int udm_find(int agent, string query) Perform search */ Index: php4/ext/mnogosearch/php_mnogo.h diff -u php4/ext/mnogosearch/php_mnogo.h:1.12 php4/ext/mnogosearch/php_mnogo.h:1.13 --- php4/ext/mnogosearch/php_mnogo.h:1.12 Sat Dec 1 09:05:12 2001 +++ php4/ext/mnogosearch/php_mnogo.h Sat Dec 1 15:09:14 2001 @@ -1,5 +1,5 @@ /* $Source: /usr/repository/php4/ext/mnogosearch/php_mnogo.h,v $ */ -/* $Id: php_mnogo.h,v 1.12 2001/12/01 14:05:12 gluke Exp $ */ +/* $Id: php_mnogo.h,v 1.13 2001/12/01 20:09:14 gluke Exp $ */ /* +----------------------------------------------------------------------+ @@ -32,6 +32,7 @@ #if UDM_VERSION_ID >= 30203 #include <udm_crc32.h> +#include <udm_store.h> #endif extern zend_module_entry mnogosearch_module_entry; @@ -60,6 +61,9 @@ #if UDM_VERSION_ID >= 30203 DLEXPORT PHP_FUNCTION(udm_crc32); +DLEXPORT PHP_FUNCTION(udm_open_stored); +DLEXPORT PHP_FUNCTION(udm_check_stored); +DLEXPORT PHP_FUNCTION(udm_close_stored); #endif DLEXPORT PHP_FUNCTION(udm_alloc_agent);
« previous php.cvs (#8360) next »