Commit 9fc848d393049557f18b5ca6e05e3e1ceae6082e
1 parent
fbe03567
Exists in
master
and in
5 other branches
Iniciando implementação de módulo PHP
Showing
5 changed files
with
329 additions
and
0 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,69 @@ |
| 1 | +/* | |
| 2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | + * | |
| 6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | + * | |
| 8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | + * Free Software Foundation. | |
| 11 | + * | |
| 12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | + * obter mais detalhes. | |
| 16 | + * | |
| 17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | + * | |
| 21 | + * Este programa está nomeado como init.cc e possui - linhas de código. | |
| 22 | + * | |
| 23 | + * Contatos: | |
| 24 | + * | |
| 25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | + * | |
| 28 | + * Referências: | |
| 29 | + * | |
| 30 | + * http://devzone.zend.com/1435/wrapping-c-classes-in-a-php-extension/ | |
| 31 | + * | |
| 32 | + */ | |
| 33 | + | |
| 34 | + #include "php3270.h" | |
| 35 | + | |
| 36 | +/*--[ Implement ]--------------------------------------------------------------------------------------------------*/ | |
| 37 | + | |
| 38 | +PHP_METHOD(tn3270, __construct) | |
| 39 | +{ | |
| 40 | + char * name; | |
| 41 | + int szName = 0; | |
| 42 | + char * url; | |
| 43 | + int szURL = 0; | |
| 44 | + tn3270_object * obj = (tn3270_object *) zend_object_store_get_object(getThis() TSRMLS_CC); | |
| 45 | + | |
| 46 | + trace("%s %d",__FUNCTION__,ZEND_NUM_ARGS()); | |
| 47 | + | |
| 48 | + // http://www.php.net/manual/pt_BR/internals2.funcs.php | |
| 49 | + if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sss", &name, &szName, &url, &szURL) == FAILURE) | |
| 50 | + RETURN_NULL(); | |
| 51 | + | |
| 52 | + trace("szName=%d",szName); | |
| 53 | + | |
| 54 | + if(szName) | |
| 55 | + { | |
| 56 | + char text[szName+1]; | |
| 57 | + strncpy(text,name,szName); | |
| 58 | + text[szName] = 0; | |
| 59 | + trace("session_name=\"%s\"",text); | |
| 60 | + obj->hSession = session::start(text); | |
| 61 | + } | |
| 62 | + else | |
| 63 | + { | |
| 64 | + obj->hSession = session::start(); | |
| 65 | + } | |
| 66 | + | |
| 67 | + | |
| 68 | +} | |
| 69 | + | ... | ... |
| ... | ... | @@ -0,0 +1,123 @@ |
| 1 | +/* | |
| 2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | + * | |
| 6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | + * | |
| 8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | + * Free Software Foundation. | |
| 11 | + * | |
| 12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | + * obter mais detalhes. | |
| 16 | + * | |
| 17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | + * | |
| 21 | + * Este programa está nomeado como main.cc e possui - linhas de código. | |
| 22 | + * | |
| 23 | + * Contatos: | |
| 24 | + * | |
| 25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | + * | |
| 28 | + * Referências: | |
| 29 | + * | |
| 30 | + * http://devzone.zend.com/1435/wrapping-c-classes-in-a-php-extension/ | |
| 31 | + * | |
| 32 | + */ | |
| 33 | + | |
| 34 | + #include "php3270.h" | |
| 35 | + | |
| 36 | +/*--[ Globals ]----------------------------------------------------------------------------------------------------*/ | |
| 37 | + | |
| 38 | +static zend_class_entry * tn3270_ce = NULL; | |
| 39 | +static zend_object_handlers tn3270_object_handlers; | |
| 40 | + | |
| 41 | +/*--[ Implement ]--------------------------------------------------------------------------------------------------*/ | |
| 42 | + | |
| 43 | +zend_function_entry tn3270_methods[] = | |
| 44 | +{ | |
| 45 | + PHP_ME( tn3270, __construct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) | |
| 46 | + | |
| 47 | + | |
| 48 | + {NULL, NULL, NULL} | |
| 49 | +}; | |
| 50 | + | |
| 51 | +void tn3270_free_storage(void *object TSRMLS_DC) | |
| 52 | +{ | |
| 53 | + tn3270_object *obj = (tn3270_object *)object; | |
| 54 | + | |
| 55 | + trace("%s",__FUNCTION__); | |
| 56 | + | |
| 57 | + zend_object_std_dtor(&obj->std TSRMLS_CC); | |
| 58 | + delete obj->hSession; | |
| 59 | + | |
| 60 | + efree(obj); | |
| 61 | +} | |
| 62 | + | |
| 63 | +zend_object_value tn3270_create_handler(zend_class_entry *type TSRMLS_DC) | |
| 64 | +{ | |
| 65 | + zend_object_value retval; | |
| 66 | + tn3270_object * obj = (tn3270_object *) emalloc(sizeof(tn3270_object)); | |
| 67 | + | |
| 68 | + trace("%s",__FUNCTION__); | |
| 69 | + | |
| 70 | + memset(obj, 0, sizeof(tn3270_object)); | |
| 71 | + | |
| 72 | + zend_object_std_init( &(obj->std), type TSRMLS_CC ); | |
| 73 | + | |
| 74 | + object_properties_init((zend_object*) &(obj->std), type); | |
| 75 | + | |
| 76 | + retval.handle = zend_objects_store_put(obj, NULL, tn3270_free_storage, NULL TSRMLS_CC); | |
| 77 | + retval.handlers = &tn3270_object_handlers; | |
| 78 | + | |
| 79 | + return retval; | |
| 80 | +} | |
| 81 | + | |
| 82 | +PHP_MINIT_FUNCTION(tn3270) | |
| 83 | +{ | |
| 84 | + zend_class_entry ce; | |
| 85 | + | |
| 86 | + trace("%s",__FUNCTION__); | |
| 87 | + | |
| 88 | + INIT_CLASS_ENTRY(ce, "tn3270", tn3270_methods); | |
| 89 | + | |
| 90 | + tn3270_ce = zend_register_internal_class(&ce TSRMLS_CC); | |
| 91 | + tn3270_ce->create_object = tn3270_create_handler; | |
| 92 | + | |
| 93 | + memcpy(&tn3270_object_handlers,zend_get_std_object_handlers(), sizeof(zend_object_handlers)); | |
| 94 | + tn3270_object_handlers.clone_obj = NULL; | |
| 95 | + | |
| 96 | + return SUCCESS; | |
| 97 | +} | |
| 98 | + | |
| 99 | +zend_module_entry lib3270_module_entry = | |
| 100 | +{ | |
| 101 | +#if ZEND_MODULE_API_NO >= 20010901 | |
| 102 | + STANDARD_MODULE_HEADER, | |
| 103 | +#endif | |
| 104 | + PHP_LIB3270_EXTNAME, | |
| 105 | + NULL, /* Functions */ | |
| 106 | + PHP_MINIT(tn3270), | |
| 107 | + NULL, /* MSHUTDOWN */ | |
| 108 | + NULL, /* RINIT */ | |
| 109 | + NULL, /* RSHUTDOWN */ | |
| 110 | + NULL, /* MINFO */ | |
| 111 | +#if ZEND_MODULE_API_NO >= 20010901 | |
| 112 | + PHP_LIB3270_EXTVER, | |
| 113 | +#endif | |
| 114 | + STANDARD_MODULE_PROPERTIES | |
| 115 | +}; | |
| 116 | + | |
| 117 | +// #ifdef COMPILE_DL_LIB3270 | |
| 118 | +extern "C" | |
| 119 | +{ | |
| 120 | + ZEND_GET_MODULE(lib3270) | |
| 121 | +} | |
| 122 | +// #endif | |
| 123 | + | ... | ... |
| ... | ... | @@ -0,0 +1,61 @@ |
| 1 | +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> | |
| 2 | +<CodeBlocks_project_file> | |
| 3 | + <FileVersion major="1" minor="6" /> | |
| 4 | + <Project> | |
| 5 | + <Option title="php3270" /> | |
| 6 | + <Option pch_mode="2" /> | |
| 7 | + <Option compiler="gcc" /> | |
| 8 | + <Build> | |
| 9 | + <Target title="Debug"> | |
| 10 | + <Option output=".bin/Debug/php3270" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="0" extension_auto="1" /> | |
| 11 | + <Option object_output=".obj/Debug/" /> | |
| 12 | + <Option type="3" /> | |
| 13 | + <Option compiler="gcc" /> | |
| 14 | + <Option parameters="-d extension=$PWD/.bin/Debug/php3270.so sample.php" /> | |
| 15 | + <Option host_application="php" /> | |
| 16 | + <Option run_host_application_in_terminal="1" /> | |
| 17 | + <Compiler> | |
| 18 | + <Add option="-g" /> | |
| 19 | + <Add option="-DDEBUG=1" /> | |
| 20 | + </Compiler> | |
| 21 | + </Target> | |
| 22 | + <Target title="Release"> | |
| 23 | + <Option output=".bin/Release/php3270" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="0" extension_auto="1" /> | |
| 24 | + <Option object_output=".obj/Release/" /> | |
| 25 | + <Option type="3" /> | |
| 26 | + <Option compiler="gcc" /> | |
| 27 | + <Compiler> | |
| 28 | + <Add option="-O2" /> | |
| 29 | + <Add option="-DNDEBUG=1" /> | |
| 30 | + </Compiler> | |
| 31 | + <Linker> | |
| 32 | + <Add option="-s" /> | |
| 33 | + </Linker> | |
| 34 | + </Target> | |
| 35 | + </Build> | |
| 36 | + <Compiler> | |
| 37 | + <Add option="-Wall" /> | |
| 38 | + <Add option="-fPIC" /> | |
| 39 | + <Add option="`php-config --includes`" /> | |
| 40 | + <Add option="`pkg-config --cflags dbus-1`" /> | |
| 41 | + <Add directory="../include" /> | |
| 42 | + </Compiler> | |
| 43 | + <Linker> | |
| 44 | + <Add option="`pkg-config --libs dbus-1`" /> | |
| 45 | + </Linker> | |
| 46 | + <Unit filename="../classlib/exception.cc" /> | |
| 47 | + <Unit filename="../classlib/local.cc" /> | |
| 48 | + <Unit filename="../classlib/remote.cc" /> | |
| 49 | + <Unit filename="../classlib/session.cc" /> | |
| 50 | + <Unit filename="../include/pw3270/class.h" /> | |
| 51 | + <Unit filename="init.cc" /> | |
| 52 | + <Unit filename="main.cc" /> | |
| 53 | + <Unit filename="php3270.h" /> | |
| 54 | + <Unit filename="sample.php" /> | |
| 55 | + <Extensions> | |
| 56 | + <code_completion /> | |
| 57 | + <envvars /> | |
| 58 | + <debugger /> | |
| 59 | + </Extensions> | |
| 60 | + </Project> | |
| 61 | +</CodeBlocks_project_file> | ... | ... |
| ... | ... | @@ -0,0 +1,68 @@ |
| 1 | +/* | |
| 2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | + * | |
| 6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | + * | |
| 8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | + * Free Software Foundation. | |
| 11 | + * | |
| 12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | + * obter mais detalhes. | |
| 16 | + * | |
| 17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | + * | |
| 21 | + * Este programa está nomeado como php3270.h e possui - linhas de código. | |
| 22 | + * | |
| 23 | + * Contatos: | |
| 24 | + * | |
| 25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | + * | |
| 28 | + * Referências: | |
| 29 | + * | |
| 30 | + * http://devzone.zend.com/1435/wrapping-c-classes-in-a-php-extension/ | |
| 31 | + * | |
| 32 | + */ | |
| 33 | + | |
| 34 | +#ifndef PHP_LIB3270_INCLUDED | |
| 35 | + | |
| 36 | + #define PHP_LIB3270_INCLUDED 1 | |
| 37 | + | |
| 38 | + #define PHP_LIB3270_EXTNAME "lib3270" | |
| 39 | + #define PHP_LIB3270_EXTVER "5.0" | |
| 40 | + | |
| 41 | + extern "C" | |
| 42 | + { | |
| 43 | + #include "php.h" | |
| 44 | + } | |
| 45 | + | |
| 46 | + extern zend_module_entry lib3270_module_entry; | |
| 47 | + #define phpext_lib3270_ptr &lib3270_module_entry; | |
| 48 | + | |
| 49 | + // 3270 session methods | |
| 50 | + PHP_METHOD(tn3270,__construct); | |
| 51 | + | |
| 52 | + | |
| 53 | + #undef PACKAGE_NAME | |
| 54 | + #undef PACKAGE_VERSION | |
| 55 | + #undef HAVE_MALLOC_H | |
| 56 | + #include <pw3270/class.h> | |
| 57 | + | |
| 58 | + // PHP object | |
| 59 | + using namespace PW3270_NAMESPACE; | |
| 60 | + | |
| 61 | + struct tn3270_object | |
| 62 | + { | |
| 63 | + zend_object std; | |
| 64 | + session * hSession; | |
| 65 | + }; | |
| 66 | + | |
| 67 | + | |
| 68 | +#endif // PHP_LIB3270_INCLUDED | ... | ... |