cvs commit
| From: | steinm | Date: | Tue, 06 Jul 1999 14:29:18 +0000 |
| Subject: | cvs commit | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-8130@lists.php.net to get a copy of this message | ||
From: steinm
Date: Tue Jul 6 14:29:18 1999
Modified files:
php3/functions/hg_comm.c
php3/functions/hg_comm.h
php3/functions/hw.c
Log message:
- extended hw_getobject() to take arrays of object ids and a query string
Index: php3/functions/hg_comm.c
diff -u php3/functions/hg_comm.c:1.24 php3/functions/hg_comm.c:1.25
--- php3/functions/hg_comm.c:1.24 Tue Jun 29 10:39:33 1999
+++ php3/functions/hg_comm.c Tue Jul 6 14:29:18 1999
@@ -23,7 +23,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: hg_comm.c,v 1.24 1999/06/29 14:39:33 steinm Exp $ */
+/* $Id: hg_comm.c,v 1.25 1999/07/06 18:29:18 steinm Exp $ */
/* #define HW_DEBUG */
@@ -1423,7 +1423,6 @@
build_msg_header(&msg, length, msgid++, GETOBJECT_MESSAGE);
if ( (msg.buf = (char *)emalloc(length-HEADER_LENGTH)) == NULL ) {
-/* perror("send_command"); */
lowerror = LE_MALLOC;
return(-1);
}
@@ -3446,6 +3445,100 @@
*userdata = (char *) retmsg->buf;
efree(retmsg);
+ return(0);
+}
+
+int send_objectbyidquery(int sockfd, hw_objectID *IDs, int *count, char *query, char ***objrecs)
+{
+ hg_msg msg, *retmsg;
+ int length, error;
+ char *tmp, *str;
+ int *ptr, i, *ptr1;
+ int *offsets, *childIDs;
+ char **childrec;
+
+ length = HEADER_LENGTH + sizeof(int) + sizeof(int) + *count * sizeof(hw_objectID);
+ if(query)
+ length = length + strlen(query) + 1;
+
+ build_msg_header(&msg, length, msgid++, OBJECTBYIDQUERY_MESSAGE);
+
+ if ( (msg.buf = (char *)emalloc(length-HEADER_LENGTH)) == NULL ) {
+ lowerror = LE_MALLOC;
+ return(-1);
+ }
+
+ tmp = build_msg_int(msg.buf, 1);
+ tmp = build_msg_int(tmp, *count);
+ for(i=0; i<*count; i++)
+ tmp = build_msg_int(tmp, IDs[i]);
+ if(query)
+ tmp = build_msg_str(tmp, query);
+
+ if ( send_hg_msg(sockfd, &msg, length) == -1 ) {
+ efree(msg.buf);
+ return(-1);
+ }
+ efree(msg.buf);
+ retmsg = recv_hg_msg(sockfd);
+ if ( retmsg == NULL )
+ return(-1);
+
+ ptr = (int *) retmsg->buf;
+ if(ptr == NULL) {
+ if(retmsg) efree(retmsg);
+ return -1;
+ }
+ if(*ptr++ != 0) {
+ error = *((int *) retmsg->buf);
+ efree(retmsg->buf);
+ efree(retmsg);
+ return error;
+ }
+
+ *count = *ptr++;
+ if(NULL != (childIDs = emalloc(*count * sizeof(hw_objectID)))) {
+ ptr1 = childIDs;
+ for(i=0; i<*count; ptr++, i++)
+ ptr1[i] = *ptr;
+ if(NULL != (offsets = emalloc(*count * sizeof(int)))) {
+ ptr1 = offsets;
+ for(i=0; i<*count; ptr++, i++)
+ ptr1[i] = *ptr;
+ } else {
+ efree(retmsg->buf);
+ efree(retmsg);
+ efree(childIDs);
+ lowerror = LE_MALLOC;
+ return(-1);
+ }
+ } else {
+ efree(retmsg->buf);
+ efree(retmsg);
+ lowerror = LE_MALLOC;
+ return(-1);
+ }
+
+ str = (char *)ptr;
+ if(NULL == (childrec = (char **) emalloc(*count * sizeof(hw_objrec *)))) {
+ efree(offsets);
+ efree(childIDs);
+ efree(retmsg->buf);
+ efree(retmsg);
+ lowerror = LE_MALLOC;
+ return(-1);
+ } else {
+ for(i=0; i<*count; i++) {
+ childrec[i] = estrdup(str);
+ str += offsets[i];
+ }
+ *objrecs = childrec;
+ }
+
+ efree(retmsg->buf);
+ efree(retmsg);
+ efree(childIDs);
+ efree(offsets);
return(0);
}
Index: php3/functions/hg_comm.h
diff -u php3/functions/hg_comm.h:1.8 php3/functions/hg_comm.h:1.9
--- php3/functions/hg_comm.h:1.8 Thu Jun 10 05:25:01 1999
+++ php3/functions/hg_comm.h Tue Jul 6 14:29:18 1999
@@ -23,7 +23,7 @@
*/
-/* $Id: hg_comm.h,v 1.8 1999/06/10 09:25:01 steinm Exp $ */
+/* $Id: hg_comm.h,v 1.9 1999/07/06 18:29:18 steinm Exp $ */
#ifndef _HG_COMM_H
#define _HG_COMM_H
@@ -53,6 +53,7 @@
#define GETANCHORS_MESSAGE 8
#define GETOBJBYQUERY_MESSAGE 9
#define GETOBJBYQUERYCOLL_MESSAGE 10
+#define OBJECTBYIDQUERY_MESSAGE 11
#define GETTEXT_MESSAGE 12
#define INSDOC_MESSAGE 14
#define INSCOLL_MESSAGE 17
@@ -182,6 +183,7 @@
extern int send_getchilddoccollobj(int sockfd, hw_objectID objectID, hw_objrec ***childrec, int
*count);
extern int send_getanchors(int sockfd, hw_objectID objectID, hw_objectID **anchorIDs, int *count);
extern int send_getanchorsobj(int sockfd, hw_objectID objectID, char ***childrec, int *count);
+extern int send_objectbyidquery(int sockfd, hw_objectID *IDs, int *count, char *query, char
***objrecs);
extern int send_getobjbyquery(int sockfd, char *query, int maxhits, hw_objectID **childIDs, int
*count);
extern int send_getobjbyqueryobj(int sockfd, char *query, int maxhits, char ***childrec, int
*count);
extern int send_getobjbyquerycoll(int sockfd, hw_objectID collID, char *query, int maxhits,
hw_objectID **childIDs, int *count);
Index: php3/functions/hw.c
diff -u php3/functions/hw.c:1.42 php3/functions/hw.c:1.43
--- php3/functions/hw.c:1.42 Mon Jul 5 16:17:35 1999
+++ php3/functions/hw.c Tue Jul 6 14:29:18 1999
@@ -23,7 +23,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: hw.c,v 1.42 1999/07/05 20:17:35 steinm Exp $ */
+/* $Id: hw.c,v 1.43 1999/07/06 18:29:18 steinm Exp $ */
#if COMPILE_DL
#include "dl/phpdl.h"
@@ -1142,18 +1142,31 @@
/* {{{ proto string hw_getobject(int link, int objid)
Returns object record */
PHP_FUNCTION(hw_getobject) {
- pval *arg1, *arg2;
- int link, id, type;
+ pval *argv[3];
+ int argc, link, id, type, multi;
hw_connection *ptr;
HW_TLS_VARS;
- if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
+ argc = ARG_COUNT(ht);
+ if(argc < 2 || argc > 3)
+ WRONG_PARAM_COUNT;
+ if (getParametersArray(ht, argc, argv) == FAILURE)
WRONG_PARAM_COUNT;
+
+ convert_to_long(argv[0]);
+ if(argv[1]->type == IS_ARRAY) {
+ multi = 1;
+ convert_to_array(argv[1]);
+ } else {
+ multi = 0;
+ convert_to_long(argv[1]);
}
- convert_to_long(arg1);
- convert_to_long(arg2);
- link=arg1->value.lval;
- id=arg2->value.lval;
+
+ if(argc == 3) {
+ convert_to_string(argv[2]);
+ }
+
+ link=argv[0]->value.lval;
ptr = php3_list_find(link,&type);
if(!ptr || (type!=php3_hw_module.le_socketp && type!=php3_hw_module.le_psocketp)) {
php3_error(E_WARNING,"Unable to find file identifier %d",id);
@@ -1161,16 +1174,52 @@
}
set_swap(ptr->swap_on);
- {
- char *object = NULL;
- if (0 != (ptr->lasterror = send_getobject(ptr->socket, id, &object)))
- RETURN_FALSE;
+ if(multi) {
+ char **objects = NULL;
+ int count, *ids, i;
+ HashTable *lht;
+ pval *keydata;
- RETURN_STRING(object, 0);
- /*
- make_return_array_from_objrec(&return_value, object);
- efree(object);
- */
+ lht = argv[1]->value.ht;
+ if(0 == (count = _php3_hash_num_elements(lht)))
+ RETURN_FALSE;
+ ids = emalloc(count * sizeof(hw_objectID));
+
+ _php3_hash_internal_pointer_reset(lht);
+ for(i=0; i<count; i++) {
+ _php3_hash_get_current_data(lht, (void **) &keydata);
+ switch(keydata->type) {
+ case IS_LONG:
+ ids[i] = keydata->value.lval;
+ break;
+ default:
+ ids[i] = keydata->value.lval;
+ }
+ _php3_hash_move_forward(lht);
+ }
+
+ if (0 != (ptr->lasterror = send_objectbyidquery(ptr->socket, ids, &count,
argv[2]->value.str.val, &objects))) {
+ efree(ids);
+ RETURN_FALSE;
+ }
+ efree(ids);
+ if (array_init(return_value) == FAILURE) {
+ efree(objects);
+ RETURN_FALSE;
+ }
+
+ for(i=0; i<count; i++) {
+ add_index_string(return_value, i, objects[i], 0);
+ }
+ efree(objects);
+
+ } else {
+ char *object = NULL;
+ id=argv[1]->value.lval;
+ if (0 != (ptr->lasterror = send_getobject(ptr->socket, id, &object)))
+ RETURN_FALSE;
+
+ RETURN_STRING(object, 0);
}
}
/* }}} */