]> granicus.if.org Git - php/commitdiff
- Added stored API to mnoGoSearch module. Now you can check
authorSergey Kartashoff <gluke@php.net>
Sat, 1 Dec 2001 20:09:15 +0000 (20:09 +0000)
committerSergey Kartashoff <gluke@php.net>
Sat, 1 Dec 2001 20:09:15 +0000 (20:09 +0000)
  if URL is places at the stored database ot not. Example updated.

ext/mnogosearch/index.php
ext/mnogosearch/php_mnogo.c
ext/mnogosearch/php_mnogo.h

index 0d8f3df9f683f3509588e241d59a77ae229ea61e..5b60ebe85d146ae94e36833cf74140fad8fb97ac 100644 (file)
@@ -69,6 +69,9 @@ $de=urldecode($de);
 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 @@ if(($errno=Udm_Errno($udm_agent))>0){
         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 @@ if(($errno=Udm_Errno($udm_agent))>0){
                 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 fb0ffc7b5559e30a1397d807bf64c83427da481d..b4fb67c923ee6d966714c96a6336dbb127a0f98e 100644 (file)
@@ -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 @@ function_entry mnogosearch_functions[] = {
 
 #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 @@ DLEXPORT PHP_MINIT_FUNCTION(mnogosearch)
        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 @@ DLEXPORT PHP_MINFO_FUNCTION(mnogosearch)
        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 @@ DLEXPORT PHP_FUNCTION(udm_set_agent_param)
                        
                        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 @@ DLEXPORT PHP_FUNCTION(udm_crc32)
        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 c5da3be4992cb8e764552fbfc3f1c10a6e967314..b63bb14cdb73c3253d3a2fc68355a04a300d8279 100644 (file)
@@ -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 @@ DLEXPORT PHP_FUNCTION(udm_check_charset);
 
 #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);