cvs: php4 /ext/saprfc .cvsignore Makefile.in README config.m4 php_saprfc.c php_saprfc.h saprfc.php

From: Date: Wed, 09 May 2001 06:58:45 +0000
Subject: cvs: php4 /ext/saprfc .cvsignore Makefile.in README config.m4 php_saprfc.c php_saprfc.h saprfc.php
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-5611@lists.php.net to get a copy of this message
hholzgra Tue May 8 23:58:45 2001 EDT Added files: /php4/ext/saprfc .cvsignore saprfc.php Modified files: /php4/ext/saprfc Makefile.in README config.m4 php_saprfc.c php_saprfc.h Log: some basic functionality: o - pen/close rfc connections - get connection and server info

Index: php4/ext/saprfc/Makefile.in diff -u php4/ext/saprfc/Makefile.in:1.1 php4/ext/saprfc/Makefile.in:1.2 --- php4/ext/saprfc/Makefile.in:1.1 Tue May 1 13:15:59 2001 +++ php4/ext/saprfc/Makefile.in Tue May 8 23:58:45 2001 @@ -1,8 +1,8 @@ -# $Id: Makefile.in,v 1.1 2001/05/01 20:15:59 hholzgra Exp $ +# $Id: Makefile.in,v 1.2 2001/05/09 06:58:45 hholzgra Exp $ LTLIBRARY_NAME = libsaprfc.la LTLIBRARY_SOURCES = php_saprfc.c -LTLIBRARY_SHARED_NAME = php_saprfc.la +LTLIBRARY_SHARED_NAME = saprfc.la LTLIBRARY_SHARED_LIBADD = $(SAPRFC_SHARED_LIBADD) include $(top_srcdir)/build/dynlib.mk Index: php4/ext/saprfc/README diff -u php4/ext/saprfc/README:1.1 php4/ext/saprfc/README:1.2 --- php4/ext/saprfc/README:1.1 Tue May 1 13:15:59 2001 +++ php4/ext/saprfc/README Tue May 8 23:58:45 2001 @@ -3,5 +3,22 @@ right now it does not much configure is working and it will build against the rfc lib -but there is no functionality in it -but it will grow ... +connection resource management is working +remote server info is implemented +but no general rfc call mechanisms like parameter passing + +you need the SAP R/3 RFC SDK to compile this extension +the SDK comes with R/3, an evaluation copy for linux +is available as an ISO CD image at +ftp://ftp.sap.com/pub/linuxlab/test_drive/LNX_testdrive.iso +or you can order a CD from the SAP Shop at +http://www.sap.com/shop + +the script saprfc.php in this directory does asume you +have this evaluation system installed on localhost and +are using the default user and password (you can change +all these in the open calls argument string) +it will open a connection to this system and print some +information on the connection and server + +wait for more ... :) Index: php4/ext/saprfc/config.m4 diff -u php4/ext/saprfc/config.m4:1.1 php4/ext/saprfc/config.m4:1.2 --- php4/ext/saprfc/config.m4:1.1 Tue May 1 13:15:59 2001 +++ php4/ext/saprfc/config.m4 Tue May 8 23:58:45 2001 @@ -1,4 +1,4 @@ -dnl $Id: config.m4,v 1.1 2001/05/01 20:15:59 hholzgra Exp $ +dnl $Id: config.m4,v 1.2 2001/05/09 06:58:45 hholzgra Exp $ dnl config.m4 for extension saprfc @@ -27,7 +27,7 @@ fi # --with-saprfc -> add include path - PHP_ADD_INCLUDE($SAPRFC_DIR/include) + AC_ADD_INCLUDE($SAPRFC_DIR/include) # --with-saprfc -> chech for lib and symbol presence LIBNAME=rfc @@ -39,7 +39,7 @@ LIBS=$old_LIBS PHP_SUBST(SAPRFC_SHARED_LIBADD) - PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $SAPRFC_DIR/lib, SAPRFC_SHARED_LIBADD) + AC_ADD_LIBRARY_WITH_PATH($LIBNAME, $SAPRFC_DIR/lib, SAPRFC_SHARED_LIBADD) PHP_EXTENSION(saprfc, $ext_shared) fi Index: php4/ext/saprfc/php_saprfc.c diff -u php4/ext/saprfc/php_saprfc.c:1.1 php4/ext/saprfc/php_saprfc.c:1.2 --- php4/ext/saprfc/php_saprfc.c:1.1 Tue May 1 13:15:59 2001 +++ php4/ext/saprfc/php_saprfc.c Tue May 8 23:58:45 2001 @@ -25,13 +25,57 @@ ZEND_DECLARE_MODULE_GLOBALS(saprfc) */ + + +void rfc_param(RFC_PARAMETER *rfc_param, + char *abap_field_name, + unsigned data_type, + void *data_addr, + unsigned data_len) +{ + RFC_PARAMETER *p = rfc_param; + + p->name = (void *)abap_field_name; + p->nlen = abap_field_name == NULL ? 0 : strlen(abap_field_name); + p->type = data_type; + p->addr = data_addr; + p->leng = data_len; + + /* init next parameter for no more parameter */ + + p++; + p->name = NULL; + p->nlen = 0; + p->type = 0; + p->addr = NULL; + p->leng = 0; + + return; +} + + + + + + /* True global resources - no need for thread safety here */ static int le_saprfc; +static void saprfc_destruct(zend_rsrc_list_entry *rsrc) { + RFC_HANDLE *p_handle = (RFC_HANDLE *)rsrc->ptr; + + RfcClose(*p_handle); + efree(p_handle); +} + +#define RESOURCE int + /* Every user visible function must have an entry in saprfc_functions[]. */ function_entry saprfc_functions[] = { - PHP_FE(confirm_saprfc_compiled, NULL) /* For testing, remove later. */ + PHP_FE(saprfc_open, NULL) + PHP_FE(saprfc_close, NULL) + PHP_FE(saprfc_info, NULL) {NULL, NULL, NULL} /* Must be the last line in saprfc_functions[] */ }; @@ -61,6 +105,8 @@ REGISTER_INI_ENTRIES(); */ + le_saprfc = zend_register_list_destructors_ex(saprfc_destruct, NULL, "saprfc_hanlde", module_number); + RfcInit(); return SUCCESS; @@ -96,37 +142,131 @@ DISPLAY_INI_ENTRIES(); */ } + -/* Remove the following function when you have succesfully modified config.m4 - so that your module can be compiled into PHP, it exists only for testing - purposes. */ - -/* Every user-visible function in PHP should document itself in the source */ -/* {{{ proto string confirm_saprfc_compiled(string arg) - Return a string to confirm that the module is compiled in */ -PHP_FUNCTION(confirm_saprfc_compiled) -{ - zval **arg; - int len; - char string[256]; +/* {{{ proto int saprfc_open(string what) + open sap connection */ +PHP_FUNCTION(saprfc_open) +{ + zval **what; + RFC_HANDLE *p_handle = (RFC_HANDLE *)emalloc(sizeof(RFC_HANDLE)); + RFC_ERROR_INFO_EX error_info; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &what) == FAILURE){ WRONG_PARAM_COUNT; } - convert_to_string_ex(arg); + convert_to_string_ex(what); - len = sprintf(string, "Congratulations, you have successfully modified ext/saprfc/config.m4, module %s is compiled into PHP", Z_STRVAL_PP(arg)); - RETURN_STRINGL(string, len, 1); + *p_handle = RfcOpenEx((*what)->value.str.val,&error_info); + if( *p_handle == RFC_HANDLE_NULL ) { + /* TODO error handling */ + RETURN_FALSE; + } + + ZEND_REGISTER_RESOURCE(return_value, p_handle, le_saprfc); } /* }}} */ -/* The previous line is meant for emacs, so it can correctly fold and unfold - functions in source code. See the corresponding marks just before function - definition, where the functions purpose is also documented. Please follow - this convention for the convenience of others editing your code. -*/ +/* {{{ proto void saprfc_close(int handle) + */ +PHP_FUNCTION(saprfc_close) +{ + zval **handle; + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &handle) == FAILURE){ + WRONG_PARAM_COUNT; + } + + convert_to_long_ex(handle); + + zend_list_delete((*handle)->value.lval); +} +/* }}} */ + +/* {{{ proto void saprfc_info(int handle) + */ +PHP_FUNCTION(saprfc_info) +{ + zval **handle; + int type; + RFC_HANDLE *p_handle; + RFC_PARAMETER exporting[6], + importing[4], + parameters[6]; + + RFC_TABLE tables[5]; + + RFCSI rfcsi; + RFC_RC rfc_rc; + + char *exception = NULL, + *function = NULL; + + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &handle) == FAILURE){ + WRONG_PARAM_COUNT; + } + + convert_to_long_ex(handle); + p_handle = zend_list_find((*handle)->value.lval,&type); + + memset(&exporting[0], 0, sizeof(exporting)); + memset(&importing[0], 0, sizeof(importing)); + + rfc_param(&importing[0], "RFCSI_EXPORT", TYPC, &rfcsi, sizeof(rfcsi)); + tables[0].name = NULL; + + rfc_rc = RfcCallReceive(*p_handle, + "RFC_SYSTEM_INFO", + exporting, + importing, + tables, + &exception); + + php_printf("<pre>\n"); + +#define OUT( text, value ) \ + php_printf( "%-22s %-.*s\n", text, (int) sizeof(rfcsi.value), rfcsi.value ) +#define OUTX( text, value, add ) \ + php_printf( "%-22s %-.*s %s\n", text, (int) sizeof(rfcsi.value), \ + rfcsi.value, (add) ) +#define NLINE php_printf( "\n" ) +#define HEADER( text ) \ + php_printf( "%s\n-----------------------------------------------\n\n", \ + (text) ) + + NLINE; + NLINE; + HEADER( "SAP System Information" ); + NLINE; + OUT( "Destination", rfcdest ); + NLINE; + if (rfcsi.rfchost2[0] != ' ') + OUT( "Host", rfchost2 ); + else + OUT( "Host", rfchost ); + OUT( "System ID", rfcsysid ); + OUT( "Database", rfcdatabs ); + OUT( "DB host", rfcdbhost ); + OUT( "DB system", rfcdbsys ); + NLINE; + OUT( "SAP release", rfcsaprl ); + OUT( "SAP kernel release", rfckernrl ); + NLINE; + OUT( "RFC Protokoll", rfcproto ); + OUT( "Characters", rfcchartyp ); + OUT( "Integers ", rfcinttyp ); + OUT( "Floating P.", rfcflotyp ); + OUT( "SAP machine id", rfcmach ); + NLINE; + OUTX( "Timezone", rfctzone, + rfcsi.rfcdayst[0] != ' ' ? "(Daylight saving time)" : "" ); + + NLINE; + NLINE; + php_printf("</pre>\n"); +} +/* }}} */ /* * Local variables: Index: php4/ext/saprfc/php_saprfc.h diff -u php4/ext/saprfc/php_saprfc.h:1.1 php4/ext/saprfc/php_saprfc.h:1.2 --- php4/ext/saprfc/php_saprfc.h:1.1 Tue May 1 13:15:59 2001 +++ php4/ext/saprfc/php_saprfc.h Tue May 8 23:58:45 2001 @@ -20,6 +20,9 @@ #ifndef PHP_SAPRFC_H #define PHP_SAPRFC_H +#include <saprfc.h> +#include <rfcsi.h> + extern zend_module_entry saprfc_module_entry; #define phpext_saprfc_ptr &saprfc_module_entry @@ -35,7 +38,9 @@ PHP_RSHUTDOWN_FUNCTION(saprfc); PHP_MINFO_FUNCTION(saprfc); -PHP_FUNCTION(confirm_saprfc_compiled); /* For testing, remove later. */ +PHP_FUNCTION(saprfc_open); +PHP_FUNCTION(saprfc_close); +PHP_FUNCTION(saprfc_info); /* Declare any global variables you may need between the BEGIN Index: php4/ext/saprfc/.cvsignore +++ php4/ext/saprfc/.cvsignore deps Makefile *.lo *.la libs libs.mk Index: php4/ext/saprfc/saprfc.php +++ php4/ext/saprfc/saprfc.php <? # very simple testcase assuming you have the SAP R/3 evaluation system CD # from CeBit/2000 installed on localhost $module = 'saprfc'; if (!extension_loaded($module)) { $str = "Module $module is not compiled into PHP"; echo "$str\n"; exit; } $conn = saprfc_open("TYPE=3 CLIENT=000 USER=DEVELOPER PASSWD=ABAP LANG=E LCHECK=0 ASHOST=localhost SYSNR=17 USE_SAPGUI=0"); if($conn) { saprfc_info($conn); saprfc_close($conn); } else { echo "Connection to R/3 failed\n"; } ?>
« previous php.cvs (#5611) next »