cvs: php4 /ext/mnogosearch php_mnogo.c php_mnogo.h
| From: | Sergey Kartashoff | Date: | Sat, 10 May 2003 11:31:51 +0000 |
| Subject: | cvs: php4 /ext/mnogosearch php_mnogo.c php_mnogo.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-20809@lists.php.net to get a copy of this message | ||
gluke Sat May 10 07:31:51 2003 EDT
Modified files:
/php4/ext/mnogosearch php_mnogo.c php_mnogo.h
Log:
@- A new functions Udm_Alloc_Agent_Array and Udm_Hash32 have been added to
@ mnogosearch extesion for use with mnogosearch-3.2.11 or later.
- A new functions Udm_Alloc_Agent_Array and Udm_Hash32 have been added to
mnogosearch extesion for use with mnogosearch-3.2.11 or later.
Index: php4/ext/mnogosearch/php_mnogo.c
diff -u php4/ext/mnogosearch/php_mnogo.c:1.72 php4/ext/mnogosearch/php_mnogo.c:1.73
--- php4/ext/mnogosearch/php_mnogo.c:1.72 Sun Apr 13 13:52:24 2003
+++ php4/ext/mnogosearch/php_mnogo.c Sat May 10 07:31:51 2003
@@ -1,5 +1,5 @@
/* $Source: /usr/repository/php4/ext/mnogosearch/php_mnogo.c,v $ */
-/* $Id: php_mnogo.c,v 1.72 2003/04/13 17:52:24 gluke Exp $ */
+/* $Id: php_mnogo.c,v 1.73 2003/05/10 11:31:51 gluke Exp $ */
/*
+----------------------------------------------------------------------+
@@ -166,6 +166,10 @@
PHP_FE(udm_set_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
#endif
PHP_FE(udm_alloc_agent, NULL)
@@ -458,7 +462,7 @@
UdmVarListReplaceStr(&Env->Vars,"SyslogFacility","local7");
UdmSetLogLevel(Env,0);
UdmOpenLog("mnoGoSearch-php",Env,0);
-
+#if UDM_VERSION_ID <= 30210
if(!memcmp(dbaddr,"searchd:",8)){
UDM_URL Url;
UdmURLParse(&Url,dbaddr);
@@ -466,6 +470,7 @@
}
UdmVarListReplaceStr(&Env->Vars,"DBAddr",dbaddr);
+
if(UDM_OK!=UdmDBSetAddr(Env->db,dbaddr,UDM_OPEN_MODE_READ)){
sprintf(Env->errstr,"Invalid DBAddr: '%s'",dbaddr);
#if UDM_VERSION_ID <= 30207
@@ -474,7 +479,9 @@
php_error_docref(NULL TSRMLS_CC, E_WARNING,"Invalid DBAddr");
RETURN_FALSE;
}
-
+#else
+ UdmDBListAdd(&Env->dbl,dbaddr, UDM_OPEN_MODE_WRITE);
+#endif
Agent=UdmAgentInit(NULL,Env,0);
#elif UDM_VERSION_ID >= 30200
Env=UdmAllocEnv();
@@ -512,7 +519,7 @@
UdmVarListReplaceStr(&Env->Vars,"SyslogFacility","local7");
UdmSetLogLevel(Env,0);
UdmOpenLog("mnoGoSearch-php",Env,0);
-
+#if UDM_VERSION_ID <= 30210
if(!memcmp(dbaddr,"searchd:",8)){
UDM_URL Url;
UdmURLParse(&Url,dbaddr);
@@ -527,6 +534,9 @@
php_error_docref(NULL TSRMLS_CC, E_WARNING,"Invalid DBAddr");
RETURN_FALSE;
}
+#else
+ UdmDBListAdd(&Env->dbl,dbaddr, UDM_OPEN_MODE_WRITE);
+#endif
Agent=UdmAgentInit(NULL,Env,0);
#elif UDM_VERSION_ID >= 30200
Env=UdmAllocEnv();
@@ -1777,6 +1787,92 @@
/* }}} */
#endif
+#if UDM_VERSION_ID >= 30211
+/* {{{ proto int udm_alloc_agent_array(array dbaddr)
+ Allocate mnoGoSearch session */
+DLEXPORT PHP_FUNCTION(udm_alloc_agent_array)
+{
+ switch(ZEND_NUM_ARGS()){
+
+ case 1: {
+ pval **yydbaddr;
+ zval **tmp;
+ char *dbaddr;
+ UDM_ENV * Env;
+ UDM_AGENT * Agent;
+ HashPosition pos;
+
+ if(zend_get_parameters_ex(1,&yydbaddr)==FAILURE){
+ RETURN_FALSE;
+ }
+
+ if (Z_TYPE_PP(yydbaddr) != IS_ARRAY) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument DBAddr must be an
array.");
+ RETURN_FALSE;
+ }
+ convert_to_array_ex(yydbaddr);
+
+ Env=UdmEnvInit(NULL);
+ UdmVarListReplaceStr(&Env->Vars,"SyslogFacility","local7");
+ UdmSetLogLevel(Env,0);
+ UdmOpenLog("mnoGoSearch-php",Env,0);
+
+ zend_hash_internal_pointer_reset_ex(HASH_OF(*yydbaddr), &pos);
+
+ while (zend_hash_get_current_data_ex(HASH_OF(*yydbaddr), (void **)&tmp, &pos) ==
SUCCESS) {
+ convert_to_string_ex(tmp);
+ dbaddr = Z_STRVAL_PP(tmp);
+ UdmDBListAdd(&Env->dbl,dbaddr, UDM_OPEN_MODE_WRITE);
+
+ zend_hash_move_forward_ex(HASH_OF(*yydbaddr), &pos);
+ }
+
+ Agent=UdmAgentInit(NULL,Env,0);
+ ZEND_REGISTER_RESOURCE(return_value,Agent,le_link);
+ }
+ break;
+
+ default:
+ WRONG_PARAM_COUNT;
+ break;
+ }
+}
+/* }}} */
+
+/* {{{ proto int udm_hash32(int agent, string str)
+ Return Hash32 checksum of gived string */
+DLEXPORT PHP_FUNCTION(udm_hash32)
+{
+ pval ** yystr, ** yyagent;
+ char *str;
+ udmhash32_t hash32;
+ char buf[32];
+ UDM_AGENT * Agent;
+ int id=-1;
+
+ switch(ZEND_NUM_ARGS()){
+ case 2: {
+ if (zend_get_parameters_ex(2, &yyagent,&yystr)==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(yystr);
+ str = Z_STRVAL_PP(yystr);
+
+ hash32=UdmHash32((str),strlen(str));
+ snprintf(buf,sizeof(buf)-1,"%u",hash32);
+
+ RETURN_STRING(buf,1);
+}
+/* }}} */
+#endif
+
/* {{{ proto int udm_find(int agent, string query)
Perform search */
DLEXPORT PHP_FUNCTION(udm_find)
@@ -2065,7 +2161,7 @@
{
size_t wsize=(1+len*15)*sizeof(char);
char *wordinfo = (char*) malloc(wsize);
- int corder = -1, ccount = 0;
+ int corder = (size_t)-1, ccount = 0;
*wordinfo = '\0';
@@ -2262,8 +2358,12 @@
#if UDM_VERSION_ID >= 30204
bzero(&C,sizeof(C));
strncpy(C.addr,cat,sizeof(C.addr)-1);
+#if UDM_VERSION_ID <= 30210
if(!UdmCatAction(Agent,&C,UDM_CAT_ACTION_LIST,Agent->Conf->db)){
#else
+ if(UDM_OK == UdmCatAction(Agent,&C,UDM_CAT_ACTION_LIST)){
+#endif
+#else
if((c=UdmCatList(Agent,cat))){
#endif
array_init(return_value);
@@ -2277,11 +2377,9 @@
int i;
if (C.ncategories) {
for(i=0;i<C.ncategories;i++){
- snprintf(buf, UDMSTRSIZ, "%s%s",C.Category[i].link[0]?"@ ":"",
C.Category[i].name);
- add_next_index_string(return_value,
C.Category[i].link[0]?C.Category[i].link:C.Category[i].path, 1);
- add_next_index_string(return_value, buf, 1);
+ add_next_index_stringl(return_value, C.Category[i].path,strlen(C.Category[i].path),1);
+ add_next_index_stringl(return_value, C.Category[i].name,strlen(C.Category[i].name),1);
}
- free(C.Category);
} else {
RETURN_FALSE;
}
@@ -2334,8 +2432,12 @@
#if UDM_VERSION_ID >= 30204
bzero(&C,sizeof(C));
strncpy(C.addr,cat,sizeof(C.addr)-1);
+#if UDM_VERSION_ID <= 30210
if(!UdmCatAction(Agent,&C,UDM_CAT_ACTION_PATH,Agent->Conf->db)){
#else
+ if(UDM_OK == UdmCatAction(Agent,&C,UDM_CAT_ACTION_PATH)){
+#endif
+#else
if((c=UdmCatPath(Agent,cat))){
#endif
array_init(return_value);
@@ -2349,11 +2451,9 @@
int i;
if (C.ncategories) {
for(i=0;i<C.ncategories;i++){
- snprintf(buf, UDMSTRSIZ, "%s%s",C.Category[i].link[0]?"@ ":"",
C.Category[i].name);
- add_next_index_string(return_value,
C.Category[i].link[0]?C.Category[i].link:C.Category[i].path, 1);
- add_next_index_string(return_value, buf, 1);
+ add_next_index_stringl(return_value, C.Category[i].path,strlen(C.Category[i].path),1);
+ add_next_index_stringl(return_value, C.Category[i].name,strlen(C.Category[i].name),1);
}
- free(C.Category);
} else {
RETURN_FALSE;
}
@@ -2395,7 +2495,11 @@
}
ZEND_FETCH_RESOURCE(Agent, UDM_AGENT *, yyagent, id, "mnoGoSearch-Agent", le_link);
#if UDM_VERSION_ID >= 30204
+#if UDM_VERSION_ID <= 30210
if (!Agent->doccount) UdmURLAction(Agent,NULL,UDM_URL_ACTION_DOCCOUNT,Agent->Conf->db);
+#else
+ if (!Agent->doccount) UdmURLAction(Agent,NULL,UDM_URL_ACTION_DOCCOUNT);
+#endif
RETURN_LONG(Agent->doccount);
#else
RETURN_LONG(UdmGetDocCount(Agent));
Index: php4/ext/mnogosearch/php_mnogo.h
diff -u php4/ext/mnogosearch/php_mnogo.h:1.21 php4/ext/mnogosearch/php_mnogo.h:1.22
--- php4/ext/mnogosearch/php_mnogo.h:1.21 Tue Dec 31 11:06:58 2002
+++ php4/ext/mnogosearch/php_mnogo.h Sat May 10 07:31:51 2003
@@ -1,5 +1,5 @@
/* $Source: /usr/repository/php4/ext/mnogosearch/php_mnogo.h,v $ */
-/* $Id: php_mnogo.h,v 1.21 2002/12/31 16:06:58 sebastian Exp $ */
+/* $Id: php_mnogo.h,v 1.22 2003/05/10 11:31:51 gluke Exp $ */
/*
+----------------------------------------------------------------------+
@@ -70,6 +70,10 @@
DLEXPORT PHP_FUNCTION(udm_make_excerpt);
DLEXPORT PHP_FUNCTION(udm_set_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
#endif