⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hw.c

📁 php-4.4.7学习linux时下载的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
		name = ptr;		while((*ptr != '\0') && (*ptr != ' '))			ptr++;		*ptr = '\0';		add_assoc_string(user_arr, "system", name, 1);		ptr++;		while((*ptr != '\0') && (*ptr == ' '))			ptr++;		name = ptr;		while((*ptr != '\0') && (*ptr != ' '))			ptr++;		*ptr = '\0';		add_assoc_string(user_arr, "onSinceDate", name, 1);		ptr++;		while((*ptr != '\0') && (*ptr == ' '))			ptr++;		name = ptr;		while((*ptr != '\0') && (*ptr != ' '))			ptr++;		*ptr = '\0';		add_assoc_string(user_arr, "onSinceTime", name, 1);		ptr++;		while((*ptr != '\0') && (*ptr == ' '))			ptr++;		name = ptr;		while((*ptr != '\0') && (*ptr != ' '))			ptr++;		*ptr = '\0';		add_assoc_string(user_arr, "TotalTime", name, 1);		/* Add the user array */		zend_hash_index_update(Z_ARRVAL_P(return_value), i++, &user_arr, sizeof(pval), NULL);		attrname = php_strtok_r(NULL, "\n", &strtok_buf);	}	efree(temp);	efree(object);}/* }}} *//* {{{ proto string hw_dummy(int link, int id, int msgid)   Hyperwave dummy function */PHP_FUNCTION(hw_dummy){	pval **arg1, **arg2, **arg3;	int link, id, type, msg_id;	hw_connection *ptr;	if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE) {		WRONG_PARAM_COUNT;	}	convert_to_long_ex(arg1);	convert_to_long_ex(arg2);	convert_to_long_ex(arg3);	link=Z_LVAL_PP(arg1);	id=Z_LVAL_PP(arg2);	msg_id=Z_LVAL_PP(arg3);	ptr = zend_list_find(link, &type);	if(!ptr || (type!=le_socketp && type!=le_psocketp)) {		php_error(E_WARNING, "%s(): Unable to find file identifier %d", get_active_function_name(TSRMLS_C), id);		RETURN_FALSE;	}	set_swap(ptr->swap_on);	{	char *object = NULL;	if (0 != (ptr->lasterror = send_dummy(ptr->socket, id, msg_id, &object)))		RETURN_FALSE;php_printf("%s", object);	Z_STRVAL_P(return_value) = object;	Z_STRLEN_P(return_value) = strlen(object);	Z_TYPE_P(return_value) = IS_STRING;	}}/* }}} *//* {{{ proto string hw_getobject(int link, int objid [, string query])   Returns object record  */PHP_FUNCTION(hw_getobject){	pval **argv[3];	int argc, link, id, type, multi;	char *query;	hw_connection *ptr;	argc = ZEND_NUM_ARGS();	if(argc < 2 || argc > 3)		WRONG_PARAM_COUNT;	if (zend_get_parameters_array_ex(argc, argv) == FAILURE)		WRONG_PARAM_COUNT;	convert_to_long_ex(argv[0]);	if(Z_TYPE_PP(argv[1]) == IS_ARRAY) {		multi = 1;		convert_to_array_ex(argv[1]);	} else {		multi = 0;		convert_to_long_ex(argv[1]);	}	if(argc == 3) {		convert_to_string_ex(argv[2]);		query = Z_STRVAL_PP(argv[2]);	} else		query = NULL;	link=Z_LVAL_PP(argv[0]);	ptr = zend_list_find(link, &type);	if(!ptr || (type!=le_socketp && type!=le_psocketp)) {		php_error(E_WARNING, "%s(): Unable to find file identifier %d", get_active_function_name(TSRMLS_C), link);		RETURN_FALSE;	}	set_swap(ptr->swap_on);	if(multi) {		char **objects = NULL;		int count, *ids, i;		HashTable *lht;		zval **keydata;		lht = Z_ARRVAL_PP(argv[1]);		if(0 == (count = zend_hash_num_elements(lht))) {			RETURN_FALSE;		}		ids = emalloc(count * sizeof(hw_objectID));		zend_hash_internal_pointer_reset(lht);		for(i=0; i<count; i++) {			zend_hash_get_current_data(lht, (void **) &keydata);			switch(Z_TYPE_PP(keydata)) {				case IS_LONG:					ids[i] = Z_LVAL_PP(keydata);					break;				default:					ids[i] = Z_LVAL_PP(keydata);			}			zend_hash_move_forward(lht);		}		if (0 != (ptr->lasterror = send_objectbyidquery(ptr->socket, ids, &count, query, &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=Z_LVAL_PP(argv[1]);		if (0 != (ptr->lasterror = send_getobject(ptr->socket, id, &object)))			RETURN_FALSE;		RETURN_STRING(object, 0);	}}/* }}} *//* {{{ proto int hw_insertobject(int link, string objrec, string parms)   Inserts an object */PHP_FUNCTION(hw_insertobject){	pval *arg1, *arg2, *arg3;	int link, type;	char *objrec, *parms;	hw_connection *ptr;	if (ZEND_NUM_ARGS() != 3 || getParameters(ht, 3, &arg1, &arg2, &arg3) == FAILURE) {		WRONG_PARAM_COUNT;	}	convert_to_long(arg1);	convert_to_string(arg2);	convert_to_string(arg3);	link=Z_LVAL_P(arg1);	objrec=Z_STRVAL_P(arg2);	parms=Z_STRVAL_P(arg3);	ptr = zend_list_find(link, &type);	if(!ptr || (type!=le_socketp && type!=le_psocketp)) {		php_error(E_WARNING, "%s(): Unable to find file identifier %d", get_active_function_name(TSRMLS_C), link);		RETURN_FALSE;	}	set_swap(ptr->swap_on);	{	int objid;	if (0 != (ptr->lasterror = send_insertobject(ptr->socket, objrec, parms, &objid)))		RETURN_FALSE;	RETURN_LONG(objid);	}}/* }}} *//* {{{ proto string hw_getandlock(int link, int objid)   Returns object record and locks object */PHP_FUNCTION(hw_getandlock){	pval *arg1, *arg2;	int link, id, type;	hw_connection *ptr;	if (ZEND_NUM_ARGS() != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) {		WRONG_PARAM_COUNT;	}	convert_to_long(arg1);	convert_to_long(arg2);	link=Z_LVAL_P(arg1);	id=Z_LVAL_P(arg2);	ptr = zend_list_find(link, &type);	if(!ptr || (type!=le_socketp && type!=le_psocketp)) {		php_error(E_WARNING, "%s(): Unable to find file identifier %d", get_active_function_name(TSRMLS_C), id);		RETURN_FALSE;	}	set_swap(ptr->swap_on);	{	char *object = NULL;	if (0 != (ptr->lasterror = send_getandlock(ptr->socket, id, &object)))		RETURN_FALSE;	RETURN_STRING(object, 0);	}}/* }}} *//* {{{ proto void hw_unlock(int link, int objid)   Unlocks object */PHP_FUNCTION(hw_unlock){	pval *arg1, *arg2;	int link, id, type;	hw_connection *ptr;	if (ZEND_NUM_ARGS() != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) {		WRONG_PARAM_COUNT;	}	convert_to_long(arg1);	convert_to_long(arg2);	link=Z_LVAL_P(arg1);	id=Z_LVAL_P(arg2);	ptr = zend_list_find(link, &type);	if(!ptr || (type!=le_socketp && type!=le_psocketp)) {		php_error(E_WARNING, "%s(): Unable to find file identifier %d", get_active_function_name(TSRMLS_C), id);		RETURN_FALSE;	}	set_swap(ptr->swap_on);	if (0 != (ptr->lasterror = send_unlock(ptr->socket, id)))		RETURN_FALSE;	RETURN_TRUE;}/* }}} *//* {{{ proto void hw_deleteobject(int link, int objid)   Deletes object */PHP_FUNCTION(hw_deleteobject){	pval *arg1, *arg2;	int link, id, type;	hw_connection *ptr;	if (ZEND_NUM_ARGS() != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) {		WRONG_PARAM_COUNT;	}	convert_to_long(arg1);	convert_to_long(arg2);	link=Z_LVAL_P(arg1);	id=Z_LVAL_P(arg2);	ptr = zend_list_find(link, &type);	if(!ptr || (type!=le_socketp && type!=le_psocketp)) {		php_error(E_WARNING, "%s(): Unable to find file identifier %d", get_active_function_name(TSRMLS_C), id);		RETURN_FALSE;	}	set_swap(ptr->swap_on);	if (0 != (ptr->lasterror = send_deleteobject(ptr->socket, id)))		RETURN_FALSE;	RETURN_TRUE;}/* }}} *//* {{{ proto void hw_changeobject(int link, int objid, array attributes)   Changes attributes of an object (obsolete) */#define BUFFERLEN 200PHP_FUNCTION(hw_changeobject){	pval *arg1, *arg2, *arg3;	int link, id, type, i;	hw_connection *ptr;	char *modification, *oldobjrec, buf[BUFFERLEN];	HashTable *newobjarr;	if (ZEND_NUM_ARGS() != 3 || getParameters(ht, 3, &arg1, &arg2, &arg3) == FAILURE) {		WRONG_PARAM_COUNT;	}	convert_to_long(arg1); /* Connection */	convert_to_long(arg2); /* object ID */	convert_to_array(arg3); /* Array with new attributes */	link=Z_LVAL_P(arg1);	id=Z_LVAL_P(arg2);	newobjarr=Z_ARRVAL_P(arg3);	ptr = zend_list_find(link, &type);	if(!ptr || (type!=le_socketp && type!=le_psocketp)) {		php_error(E_WARNING, "%s(): Unable to find file identifier %d", get_active_function_name(TSRMLS_C), id);		RETURN_FALSE;	}	/* get the old object record */	if(0 != (ptr->lasterror = send_getandlock(ptr->socket, id, &oldobjrec)))		RETURN_FALSE;	zend_hash_internal_pointer_reset(newobjarr);	modification = strdup("");	for(i=0; i<zend_hash_num_elements(newobjarr); i++) {		char *key, *str, *str1, newattribute[BUFFERLEN];		pval *data, **dataptr;		int j, noinsert=1;		ulong ind;		zend_hash_get_current_key(newobjarr, &key, &ind, 0);		zend_hash_get_current_data(newobjarr, (void *) &dataptr);		data = *dataptr;		switch(Z_TYPE_P(data)) {			case IS_STRING:				if(strlen(Z_STRVAL_P(data)) == 0)					snprintf(newattribute, BUFFERLEN, "rem %s", key);				else					snprintf(newattribute, BUFFERLEN, "add %s=%s", key, Z_STRVAL_P(data));				noinsert = 0;				break;			default:				newattribute[0] = '\0';		}		if(!noinsert) {			modification = fnInsStr(modification, 0, "\\");			modification = fnInsStr(modification, 0, newattribute);/*			modification = fnInsStr(modification, 0, "add "); */			/* Retrieve the old attribute from object record */			if(NULL != (str = strstr(oldobjrec, key))) {				str1 = str;				j = 0;				while((str1 != NULL) && (*str1 != '\n') && (j < BUFFERLEN-1)) {					buf[j++] = *str1++;				}				buf[j] = '\0';				modification = fnInsStr(modification, 0, "\\");				modification = fnInsStr(modification, 0, buf);				modification = fnInsStr(modification, 0, "rem ");			} 		}		zend_hash_move_forward(newobjarr);	}	efree(oldobjrec);	set_swap(ptr->swap_on);	modification[strlen(modification)-1] = '\0';	if (0 != (ptr->lasterror = send_changeobject(ptr->socket, id, modification))) {		free(modification);		send_unlock(ptr->socket, id);		RETURN_FALSE;	}	free(modification);	if (0 != (ptr->lasterror = send_unlock(ptr->socket, id))) {		RETURN_FALSE;	}	RETURN_TRUE;}#undef BUFFERLEN/* }}} *//* {{{ proto void hw_modifyobject(int link, int objid, array remattributes, array addattributes [, int mode])   Modifies attributes of an object */#define BUFFERLEN 200PHP_FUNCTION(hw_modifyobject){	zval **argv[5];	int argc;	int link, id, type, i, mode;	hw_connection *ptr;	char *modification;	HashTable *remobjarr, *addobjarr;	argc = ZEND_NUM_ARGS();	if((argc > 5) || (argc < 4))		WRONG_PARAM_COUNT;	if (zend_get_parameters_array_ex(argc, argv) == FAILURE)	if(argc < 4) {		WRONG_PARAM_COUNT;	}	convert_to_long_ex(argv[0]); /* Connection */	convert_to_long_ex(argv[1]); /* object ID */	convert_to_array_ex(argv[2]); /* Array with attributes to remove */	convert_to_array_ex(argv[3]); /* Array with attributes to add */	if(argc == 5) {		convert_to_long_ex(argv[4]);		mode = Z_LVAL_PP(argv[4]);	} else		mode = 0;	link=Z_LVAL_PP(argv[0]);	id=Z_LVAL_PP(argv[1]);	remobjarr=Z_ARRVAL_PP(argv[2]);	addobjarr=Z_ARRVAL_PP(argv[3]);	ptr = zend_list_find(link, &type);	if(!ptr || (type!=le_socketp && type!=le_psocketp)) {		php_error(E_WARNING, "%s(): Unable to find file identifier %d", get_active_function_name(TSRMLS_C), id);		RETURN_FALSE;	}	modification = strdup("");	if(addobjarr != NULL) {		zend_hash_internal_pointer_reset(addobjarr);		for(i=0; i<zend_hash_num_elements(addobjarr); i++) {			char *key, addattribute[BUFFERLEN];			zval *data, **dataptr;			int noinsert=1;			ulong ind;			zend_hash_get_current_key(addobjarr, &key, &ind, 0);			zend_hash_get_current_data(addobjarr, (void *) &dataptr);			data = *dataptr;			switch(Z_TYPE_P(data)) {				case IS_STRING:					if(strlen(Z_STRVAL_P(data)) > 0) {						snprintf(addattribute, BUFFERLEN, "add %s=%s", key, Z_STRVAL_P(data));/* fprintf(stderr, "add: %s\n", addattribute); */						noinsert = 0;					}					break;				case IS_ARRAY: {					int i, len, keylen, count;					char *strarr, *ptr, *ptr1;					count = zend_hash_num_elements(Z_ARRVAL_P(data));					if(count > 0) {						strarr = make_objrec_from_array(Z_ARRVAL_P(data), ':');						len = strlen(strarr) - 1;						keylen = strlen(key);						if(NULL == (ptr = malloc(len + 1 + count*(keylen+1+4)))) {							if(modification)								free(modification);							RETURN_FALSE;						}						ptr1 = ptr;						*ptr1 = '\0';						strcpy(ptr1, "add ");						ptr1 += 4;						strcpy(ptr1, key);						ptr1 += keylen;						*ptr1++ = '=';						for(i=0; i<len; i++) {							*ptr1++ = strarr[i];							if(strarr[i] == '\n') {								ptr1[-1] = '\\';								strcpy(ptr1, "add ");								ptr1 += 4;								strcpy(ptr1, key);								ptr1 += keylen;								*ptr1++ = '=';							} /* else if(strarr[i] == '=')								ptr1[-1] = ':'; */						}						*ptr1 = '\0';						strlcpy(addattribute, ptr, sizeof(addattribute));						noinsert = 0;					}					break;				}			}			if(!noinsert) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -