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

📄 birdstep.c

📁 php-4.4.7学习linux时下载的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*   +----------------------------------------------------------------------+   | PHP Version 4                                                        |   +----------------------------------------------------------------------+   | Copyright (c) 1997-2007 The PHP Group                                |   +----------------------------------------------------------------------+   | This source file is subject to version 3.01 of the PHP license,      |   | that is bundled with this package in the file LICENSE, and is        |   | available through the world-wide-web at the following url:           |   | http://www.php.net/license/3_01.txt                                  |   | If you did not receive a copy of the PHP license and are unable to   |   | obtain it through the world-wide-web, please send a note to          |   | license@php.net so we can mail you a copy immediately.               |   +----------------------------------------------------------------------+   | Authors: Nikolay P. Romanyuk <mag@redcom.ru>                         |   +----------------------------------------------------------------------+ *//* $Id: birdstep.c,v 1.3.4.3.2.2 2007/01/01 09:46:45 sebastian Exp $ *//* * TODO: * birdstep_fetch_into(), * Check all on real life apps. */#ifdef HAVE_CONFIG_H#include "config.h"#endif#include "php.h"#if WIN32# include "config.w32.h"# include "win95nt.h"# ifdef PHP_EXPORTS#  define PHPAPI __declspec(dllexport) # else#  define PHPAPI __declspec(dllimport) # endif#else# include <php_config.h># define PHPAPI# define THREAD_LS#endif#ifdef HAVE_BIRDSTEP#include "php_birdstep.h"#include "ext/standard/info.h"function_entry birdstep_functions[] = {	PHP_FE(birdstep_connect,        NULL)	PHP_FE(birdstep_close,          NULL)	PHP_FE(birdstep_exec,           NULL)	PHP_FE(birdstep_fetch,          NULL)	PHP_FE(birdstep_result,         NULL)	PHP_FE(birdstep_freeresult,     NULL)	PHP_FE(birdstep_autocommit,     NULL)	PHP_FE(birdstep_off_autocommit, NULL)	PHP_FE(birdstep_commit,         NULL)	PHP_FE(birdstep_rollback,       NULL)	PHP_FE(birdstep_fieldnum,       NULL)	PHP_FE(birdstep_fieldname,      NULL)/* * Temporary Function aliases until the next major upgrade to PHP.   * These should allow users to continue to use their current scripts,  * but should in reality warn the user that this functionality is  * deprecated. */	PHP_FALIAS(velocis_connect,        birdstep_connect,        NULL)	PHP_FALIAS(velocis_close,          birdstep_close,          NULL)	PHP_FALIAS(velocis_exec,           birdstep_exec,           NULL)	PHP_FALIAS(velocis_fetch,          birdstep_fetch,          NULL)	PHP_FALIAS(velocis_result,         birdstep_result,         NULL)	PHP_FALIAS(velocis_freeresult,     birdstep_freeresult,     NULL)	PHP_FALIAS(velocis_autocommit,     birdstep_autocommit,     NULL)	PHP_FALIAS(velocis_off_autocommit, birdstep_off_autocommit, NULL)	PHP_FALIAS(velocis_commit,         birdstep_commit,         NULL)	PHP_FALIAS(velocis_rollback,       birdstep_rollback,       NULL)	PHP_FALIAS(velocis_fieldnum,       birdstep_fieldnum,       NULL)	PHP_FALIAS(velocis_fieldname,      birdstep_fieldname,      NULL)/* End temporary aliases */	{NULL, NULL, NULL}};zend_module_entry birdstep_module_entry = {	STANDARD_MODULE_HEADER,	"birdstep",	birdstep_functions,	PHP_MINIT(birdstep),	PHP_MSHUTDOWN(birdstep),	PHP_RINIT(birdstep),	NULL,	PHP_MINFO(birdstep),	NO_VERSION_YET,	STANDARD_MODULE_PROPERTIES};#ifdef COMPILE_DL_ODBCZEND_GET_MODULE(birdstep)#endifTHREAD_LS birdstep_module php_birdstep_module;THREAD_LS static HENV henv;#define PHP_GET_BIRDSTEP_RES_IDX(id) convert_to_long_ex(id); if (!(res = birdstep_find_result(list, Z_LVAL_PP(id)))) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Not result index (%d)", Z_LVAL_PP(id)); RETURN_FALSE; } #define PHP_BIRDSTEP_CHK_LNK(id) convert_to_long_ex(id); if (!(conn = birdstep_find_conn(list,Z_LVAL_PP(id)))) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Not connection index (%d)", Z_LVAL_PP(id)); RETURN_FALSE; }                                                        static void _close_birdstep_link(zend_rsrc_list_entry *rsrc TSRMLS_DC){	VConn *conn = (VConn *)rsrc->ptr;	if ( conn ) {		efree(conn);	}}static void _free_birdstep_result(zend_rsrc_list_entry *rsrc TSRMLS_DC){	Vresult *res = (Vresult *)rsrc->ptr;	if ( res && res->values ) {		register int i;		for ( i=0; i < res->numcols; i++ ) {			if ( res->values[i].value )				efree(res->values[i].value);		}		efree(res->values);	}	if ( res ) {		efree(res);	}}PHP_MINIT_FUNCTION(birdstep){	SQLAllocEnv(&henv);	if ( cfg_get_long("birdstep.max_links",&php_birdstep_module.max_links) == FAILURE ) {		php_birdstep_module.max_links = -1;	}	php_birdstep_module.num_links = 0;	php_birdstep_module.le_link   = zend_register_list_destructors_ex(_close_birdstep_link, NULL, "birdstep link", module_number);	php_birdstep_module.le_result = zend_register_list_destructors_ex(_free_birdstep_result, NULL, "birdstep result", module_number);	return SUCCESS;}PHP_RINIT_FUNCTION(birdstep){	return SUCCESS;}PHP_MINFO_FUNCTION(birdstep){	php_info_print_table_start();	php_info_print_table_row(2, "RAIMA Birdstep Support", "enabled" );	php_info_print_table_end();}PHP_MSHUTDOWN_FUNCTION(birdstep){	SQLFreeEnv(henv);	return SUCCESS;}/* Some internal functions. Connections and result manupulate */static int birdstep_add_conn(HashTable *list,VConn *conn,HDBC hdbc){	int ind;	ind = zend_list_insert(conn,php_birdstep_module.le_link);	conn->hdbc = hdbc;	conn->index = ind;	return(ind);}static VConn * birdstep_find_conn(HashTable *list,int ind){	VConn *conn;	int type;	conn = zend_list_find(ind,&type);	if ( !conn || type != php_birdstep_module.le_link ) {		return(NULL);	}	return(conn);}static void birdstep_del_conn(HashTable *list,int ind){	zend_list_delete(ind);}static int birdstep_add_result(HashTable *list,Vresult *res,VConn *conn){	int ind;	ind = zend_list_insert(res,php_birdstep_module.le_result);	res->conn = conn;	res->index = ind;	return(ind);}static Vresult * birdstep_find_result(HashTable *list,int ind){	Vresult *res;	int type;	res = zend_list_find(ind,&type);	if ( !res || type != php_birdstep_module.le_result ) {		return(NULL);	}	return(res);}static void birdstep_del_result(HashTable *list,int ind){	zend_list_delete(ind);}/* Users functions *//* {{{ proto int birdstep_connect(string server, string user, string pass) */PHP_FUNCTION(birdstep_connect){	zval **serv,**user,**pass;	char *Serv = NULL;	char *User = NULL;	char *Pass = NULL;	RETCODE stat;	HDBC hdbc;	VConn *new;	long ind;	if ( php_birdstep_module.max_links != -1 && php_birdstep_module.num_links == php_birdstep_module.max_links ) {		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Too many open connections (%d)",php_birdstep_module.num_links);		RETURN_FALSE;	}	if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &serv, &user, &pass) == FAILURE ) {		WRONG_PARAM_COUNT;	}	convert_to_string_ex(serv);	convert_to_string_ex(user);	convert_to_string_ex(pass);	Serv = Z_STRVAL_PP(serv);	User = Z_STRVAL_PP(user);	Pass = Z_STRVAL_PP(pass);	stat = SQLAllocConnect(henv,&hdbc);	if ( stat != SQL_SUCCESS ) {		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Could not allocate connection handle");		RETURN_FALSE;	}	stat = SQLConnect(hdbc,Serv,SQL_NTS,User,SQL_NTS,Pass,SQL_NTS);	if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Could not connect to server \"%s\" for %s",Serv,User);		SQLFreeConnect(hdbc);		RETURN_FALSE;	}	new = (VConn *)emalloc(sizeof(VConn));	ind = birdstep_add_conn(list,new,hdbc);	php_birdstep_module.num_links++;	RETURN_LONG(ind);}/* }}} *//* {{{ proto bool birdstep_close(int id) */PHP_FUNCTION(birdstep_close){	zval **id;	VConn *conn;	if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &id) == FAILURE) {		WRONG_PARAM_COUNT;	}	PHP_BIRDSTEP_CHK_LNK(id);	SQLDisconnect(conn->hdbc);	SQLFreeConnect(conn->hdbc);	birdstep_del_conn(list,Z_LVAL_PP(id));	php_birdstep_module.num_links--;	RETURN_TRUE;}/* }}} *//* {{{ proto int birdstep_exec(int index, string exec_str) */PHP_FUNCTION(birdstep_exec){	zval **ind, **exec_str;	char *query = NULL;	int indx;	VConn *conn;	Vresult *res;	RETCODE stat;	SWORD cols,i,colnamelen;	SDWORD rows,coldesc;	if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &ind, &exec_str) == FAILURE) {		WRONG_PARAM_COUNT;	}	PHP_BIRDSTEP_CHK_LNK(ind);	convert_to_string_ex(exec_str);	query = Z_STRVAL_PP(exec_str);	res = (Vresult *)emalloc(sizeof(Vresult));	stat = SQLAllocStmt(conn->hdbc,&res->hstmt);	if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: SQLAllocStmt return %d",stat);		efree(res);		RETURN_FALSE;	}	stat = SQLExecDirect(res->hstmt,query,SQL_NTS);	if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Can not execute \"%s\" query",query);		SQLFreeStmt(res->hstmt,SQL_DROP);		efree(res);		RETURN_FALSE;	}

⌨️ 快捷键说明

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