cvs: php4 /ext/signio Makefile.in config.m4 php_signio.h signio.c

From: Date: Sat, 15 Jul 2000 01:27:11 +0000
Subject: cvs: php4 /ext/signio Makefile.in config.m4 php_signio.h signio.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-762@lists.php.net to get a copy of this message
jdonagher Fri Jul 14 18:27:11 2000 EDT Added files: /php4/ext/signio Makefile.in config.m4 php_signio.h signio.c Log: @- Added extension Signio (John Donagher, John Campbell) # Initial commit of a new extension for processing live credit card or # Telecheck transactions through Signio/Verisign. Signio's SDK is required # to compile this extension. # Pertinent userland functions are: # signio_transaction() # signio_version() Index: php4/ext/signio/Makefile.in +++ php4/ext/signio/Makefile.in LTLIBRARY_NAME = libsignio.la LTLIBRARY_SOURCES = signio.c LTLIBRARY_SHARED_NAME = signio.la LTLIBRARY_SHARED_LIBADD = $(SIGNIO_SHARED_LIBADD) include $(top_srcdir)/build/dynlib.mk Index: php4/ext/signio/config.m4 +++ php4/ext/signio/config.m4 dnl config.m4 for extension readline dnl don't forget to call PHP_EXTENSION(readline) PHP_ARG_WITH(signio,for signio support, [ --with-signio[=DIR] Include Signio support. DIR is the Signio SDK source directory.]) if test "$PHP_SIGNIO" != "no"; then for i in /usr/local /usr $PHP_SIGNIO $PHP_SIGNIO/lib; do if test -r $i/pfpro.h; then SIGNIO_INC_DIR=$i elif test -r $i/include/pfpro.h; then SIGNIO_INC_DIR=$i/include fi if test -r $i/lib/libpfpro.so; then SIGNIO_LIB_DIR=$i/lib elif test -r $i/libpfpro.so; then SIGNIO_LIB_DIR=$i fi done if test -z "$SIGNIO_INC_DIR"; then AC_MSG_ERROR(Could not find pfpro.h. Please make sure you have the Signio Payflow Pro SDK installed.) fi if test -z "$SIGNIO_LIB_DIR"; then AC_MSG_ERROR(Could not find libpfpro.so. Please make sure you have the Signio Payflow Pro SDK installed.) fi AC_ADD_INCLUDE($SIGNIO_INC_DIR) AC_ADD_LIBRARY_WITH_PATH(pfpro, $SIGNIO_LIB_DIR, SIGNIO_SHARED_LIBADD) PHP_SUBST(SIGNIO_SHARED_LIBADD) AC_DEFINE(HAVE_SIGNIO, 1, [ ]) PHP_EXTENSION(signio, $ext_shared) fi Index: php4/ext/signio/php_signio.h +++ php4/ext/signio/php_signio.h /* +----------------------------------------------------------------------+ | PHP version 4.0 | +----------------------------------------------------------------------+ | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/2_02.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: John Donagher (john@webmeta.com) | | John Campbell | +----------------------------------------------------------------------+ */ #ifndef _PHP_SIGNIO_H #define _PHP_SIGNIO_H #if HAVE_SIGNIO /* Signio SDK header file */ #include <pfpro.h> extern zend_module_entry signio_module_entry; #define phpext_signio_ptr &signio_module_entry #ifdef PHP_WIN32 #define PHP_SIGNIO_API __declspec(dllexport) #else #define PHP_SIGNIO_API #endif PHP_MINIT_FUNCTION(signio); PHP_MSHUTDOWN_FUNCTION(signio); PHP_RINIT_FUNCTION(signio); PHP_RSHUTDOWN_FUNCTION(signio); PHP_MINFO_FUNCTION(signio); PHP_FUNCTION(signio_transaction); PHP_FUNCTION(signio_version); typedef struct { int le_signio; } php_signio_globals; #ifdef ZTS #define SIGNIOG(v) (signio_globals->v) #define SIGNIOLS_FETCH() php_signio_globals *signio_globals = ts_resource(gd_signio_id) #else #define SIGNIOG(v) (signio_globals.v) #define SIGNIOLS_FETCH() #endif #else #define phpext_signio_ptr NULL #endif #endif /* _PHP_SIGNIO_H */ /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: */ Index: php4/ext/signio/signio.c +++ php4/ext/signio/signio.c /* +----------------------------------------------------------------------+ | PHP version 4.0 | +----------------------------------------------------------------------+ | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/2_02.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: John Donagher (john@webmeta.com), | | John Campbell | +----------------------------------------------------------------------+ */ #include "php.h" #include "php_ini.h" #include "php_signio.h" /* You should tweak config.m4 so this symbol (or some else suitable) gets defined. */ #if HAVE_SIGNIO #ifdef ZTS int signio_globals_id; #else php_signio_globals signio_globals; #endif /* Every user visible function must have an entry in signio_functions[]. */ function_entry signio_functions[] = { PHP_FE(signio_transaction, NULL) PHP_FE(signio_version, NULL) {NULL, NULL, NULL} /* Must be the last line in signio_functions[] */ }; zend_module_entry signio_module_entry = { "signio", signio_functions, PHP_MINIT(signio), PHP_MSHUTDOWN(signio), PHP_RINIT(signio), /* Replace with NULL if there's nothing to do at request start */ PHP_RSHUTDOWN(signio), /* Replace with NULL if there's nothing to do at request end */ PHP_MINFO(signio), STANDARD_MODULE_PROPERTIES }; #ifdef COMPILE_DL_SIGNIO ZEND_GET_MODULE(signio) #endif /* Remove comments and fill if you need to have entries in php.ini PHP_INI_BEGIN() PHP_INI_END() */ PHP_MINIT_FUNCTION(signio) { /* Remove comments if you have entries in php.ini REGISTER_INI_ENTRIES(); */ return SUCCESS; } PHP_MSHUTDOWN_FUNCTION(signio) { /* Remove comments if you have entries in php.ini UNREGISTER_INI_ENTRIES(); */ return SUCCESS; } /* Remove if there's nothing to do at request start */ PHP_RINIT_FUNCTION(signio) { return SUCCESS; } /* Remove if there's nothing to do at request end */ PHP_RSHUTDOWN_FUNCTION(signio) { return SUCCESS; } PHP_MINFO_FUNCTION(signio) { php_info_print_table_start(); php_info_print_table_header(2, "signio support", "enabled"); php_info_print_table_end(); /* Remove comments if you have entries in php.ini DISPLAY_INI_ENTRIES(); */ } /* {{{ proto array signio_transaction(array input [, string hostname] [, int port] [, int timeout] [, string proxyaddress] [, int proxyport] [, string proxylogon] [, proxypassword]) Process a live credit card transaction through the Signio payment gateway */ PHP_FUNCTION(signio_transaction) { zval **yyparmlist, /* Parameter list to be sent to Signio */ **yyhost=NULL, /* Hostname (i.e. live or test server) */ **yyport=NULL, /* Port to connect to on server */ **yytimeout=NULL, /* Obvious */ **yyproxyaddress=NULL, /* Proxy IP address if required */ **yyproxyport=NULL, /* Port on proxy to connect to */ **yyproxylogon=NULL, /* Obvious */ **yyproxypassword=NULL; /* Obvious */ HashTable *hash; /* Initialize a hash that we'll use to implode the associative array the user will pass in */ zval **entry, *data; /* Some variables we'll use for */ char *string_key; /* string and array manipulation */ ulong num_key; char buf[128], sbuf[128]; char *p1, *p2, *p_end, /* Pointers for string manipulation */ *sp1, *sp2, *sp_end, *pdelim1="&", *pdelim2="="; /* The variables that we will pass to Signio's ProcessPNTransaction */ /* function in Signio's required types and a char bucket to hold */ /* the response. */ char *parmlist,*host,*proxyaddress,*proxylogon,*proxypassword; int port,proxyport; long timeout; char transresponse[512]=""; char instr[1024]; /* The imploded string we'll pass */ int instr_len=0; /* to the Signio API */ /* Initialize some defaults as defined by Signio's SDK */ host="test.signio.com"; port=443; timeout=30; proxyport=0; /* Parameter translation conditionals */ if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 8 || zend_get_parameters_ex(ZEND_NUM_ARGS(), &yyparmlist, &yyhost, &yyport, &yytimeout, &yyproxyaddress, &yyproxyport, &yyproxylogon, &yyproxypassword) == FAILURE) { WRONG_PARAM_COUNT; } if ((*yyparmlist)->type != IS_ARRAY) { php_error(E_WARNING, "First argument to signio_transaction() should be an array"); return; } if (yyhost != NULL) { convert_to_string_ex(yyhost); host = (*yyhost)->value.str.val; } if (yyport != NULL) { convert_to_long_ex(yyport); port = (*yyport)->value.lval; } if (yytimeout != NULL) { convert_to_long_ex(yytimeout); timeout = (*yytimeout)->value.lval; } if (yyproxyaddress != NULL) { convert_to_string_ex(yyproxyaddress); proxyaddress = (*yyproxyaddress)->value.str.val; } if (yyproxyport != NULL) { convert_to_long_ex(yyproxyport); proxyport = (*yyproxyport)->value.lval; } if (yyproxylogon != NULL) { convert_to_string_ex(yyproxylogon); proxylogon = (*yyproxylogon)->value.str.val; } if (yyproxypassword != NULL) { convert_to_string_ex(yyproxypassword); proxypassword = (*yyproxypassword)->value.str.val; } /* Hash the passed-in associative array */ hash = HASH_OF(*yyparmlist); zend_hash_internal_pointer_reset(hash); /* Here we go. Iterate through the array and implode in the format: key=val&key2=val2&key3=val3 as required by Signio. */ while (zend_hash_get_current_data(hash, (void **)&entry) == SUCCESS) { if (instr_len > 0) { strcpy(instr+instr_len, "&"); instr_len+=1; } MAKE_STD_ZVAL(data); switch (zend_hash_get_current_key(hash, &string_key, &num_key)) { case HASH_KEY_IS_STRING: data->type = IS_STRING; data->value.str.val = string_key; data->value.str.len = strlen(string_key); strcpy(instr+instr_len, data->value.str.val); instr_len+=strlen(data->value.str.val); strcpy(instr+instr_len, "="); instr_len+=1; break; case HASH_KEY_IS_LONG: data->type = IS_LONG; data->value.lval = num_key; sprintf(buf,"%d",data->value.lval); strcpy(instr+instr_len,buf); instr_len+=strlen(buf); strcpy(instr+instr_len, "="); instr_len+=1; break; default: zval_dtor(data); php_error(E_WARNING, "Invalid type found in argument 1 of signio_transaction()"); } switch ((*entry)->type) { case IS_LONG: sprintf(buf,"%d",(*entry)->value.lval); break; case IS_STRING: sprintf(buf,"%s",(*entry)->value.str.val); break; default: zval_dtor(data); php_error(E_WARNING, "Invalid type found in argument 1 of signio_transaction()"); } strcpy(instr+instr_len,buf); instr_len+=strlen(buf); zend_hash_move_forward(hash); } /* I made the decision to wrap PNInit()/PNCleanup() functionality into the transaction function. We really don't know what the functions really do and therefore can't gauge what if any performance impact they might cause in the case where multiple transactions will be passed in the same process. It will be much cleaner (userland) to simply call the signio_transaction() function and not have to worry about the other two functions */ PNInit(); /* Signio API function */ ProcessPNTransaction(host, port, proxyaddress, proxyport, proxylogon, proxypassword, instr, instr_len, timeout, transresponse); /* Signio API function */ PNCleanup(); /* Signio API function */ /* Initiate a return array */ array_init(return_value); /* Clean our str[n]cpy buffers */ memset(buf, 0, sizeof(buf)); memset(sbuf, 0, sizeof(sbuf)); /* This final chunk of code is to walk the string returned by Signio and build a string array to return to the user */ p_end = transresponse + strlen(transresponse); p1 = transresponse; p2 = (char*)php_memnstr(transresponse, pdelim1, 1, p_end); sp1 = (char*)php_memnstr(transresponse, pdelim2, 1, p2); strncpy(buf, p1, sp1-p1); sp1++; strncpy(sbuf, sp1, p2-sp1); add_assoc_string(return_value, &buf[0], &sbuf[0], 1); do { memset(buf, 0, sizeof(buf)); memset(sbuf, 0, sizeof(sbuf)); p1 = p2+1; if ((sp2 = (char*)php_memnstr(p1, pdelim1, 1, p_end)) != NULL) { sp1 = (char*)php_memnstr(p1, pdelim2, 1, sp2); strncpy(buf, p1, sp1-p1); sp1++; strncpy(sbuf, sp1, sp2-sp1); add_assoc_string(return_value, &buf[0], &sbuf[0], 1); } } while ((p2 = (char*)php_memnstr(p1, pdelim1, 1, p_end)) != NULL); if (p1 <= p_end) { memset(buf, 0, sizeof(buf)); memset(sbuf, 0, sizeof(sbuf)); sp1 = (char*)php_memnstr(p1, pdelim2, 1, p_end); strncpy(buf, p1, sp1-p1); sp1++; strncpy(sbuf, sp1, p_end-sp1); add_assoc_string(return_value, &buf[0], &sbuf[0], 1); } } /* }}} */ /* {{{ proto string signio_version(void) Return the version of the Signio SDK */ PHP_FUNCTION(signio_version) { zval **arg; char *string; string = PNVersion(); RETVAL_STRING(string, 1); } /* }}} */ #endif /* HAVE_SIGNIO */ /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: */

« previous php.cvs (#762) next »