Commit 96b09fef1737bfafd9309adb38051d3105e65d24

Authored by Perry Werneck
1 parent b8868eed
Exists in master

Atualizando módulo PHP para permitir persistência nas sessões usando o módulo de serviço.

@@ -230,6 +230,14 @@ run: \ @@ -230,6 +230,14 @@ run: \
230 230
231 php -d extension=$(BINDBG)/$(LIBNAME) testprograms/version.php 231 php -d extension=$(BINDBG)/$(LIBNAME) testprograms/version.php
232 232
  233 +cleanDebug:
  234 + @rm -fr $(OBJDBG)
  235 + @rm -fr $(BINDBG)
  236 +
  237 +cleanRelease:
  238 + @rm -fr $(OBJRLS)
  239 + @rm -fr $(BINRLS)
  240 +
233 clean: 241 clean:
234 242
235 @rm -fr $(BINDIR) 243 @rm -fr $(BINDIR)
pw3270-php5.cbp
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 <FileVersion major="1" minor="6" /> 3 <FileVersion major="1" minor="6" />
4 <Project> 4 <Project>
5 <Option title="PHP5 Bindings for pw3270/lib3270" /> 5 <Option title="PHP5 Bindings for pw3270/lib3270" />
  6 + <Option makefile_is_custom="1" />
6 <Option pch_mode="2" /> 7 <Option pch_mode="2" />
7 <Option compiler="gcc" /> 8 <Option compiler="gcc" />
8 <Build> 9 <Build>
@@ -126,3 +126,53 @@ PHP_METHOD(tn3270, getrevision) @@ -126,3 +126,53 @@ PHP_METHOD(tn3270, getrevision)
126 trace("String = [%s]",str.c_str()); 126 trace("String = [%s]",str.c_str());
127 RETURN_STRING(str.c_str(),1); 127 RETURN_STRING(str.c_str(),1);
128 } 128 }
  129 +
  130 +PHP_METHOD(tn3270, getname)
  131 +{
  132 + tn3270_object * obj = (tn3270_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
  133 +
  134 + string str = obj->hSession->get_session_name();
  135 +
  136 + trace("String = [%s]",str.c_str());
  137 + RETURN_STRING(str.c_str(),1);
  138 +}
  139 +
  140 +PHP_METHOD(tn3270, __tostring)
  141 +{
  142 + tn3270_object * obj = (tn3270_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
  143 + string str;
  144 +
  145 + try {
  146 +
  147 + str = obj->hSession->get_contents();
  148 +
  149 + } catch(std::exception &e) {
  150 +
  151 + str.clear();
  152 +
  153 + }
  154 +
  155 + trace("String = [%s]",str.c_str());
  156 + RETURN_STRING(str.c_str(),1);
  157 +}
  158 +
  159 +PHP_METHOD(tn3270, __get)
  160 +{
  161 + tn3270_object * obj = (tn3270_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
  162 + const char * text;
  163 + int szText;
  164 +
  165 + if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &text, &szText) == FAILURE)
  166 + RETURN_NULL();
  167 +
  168 + if(!strncasecmp("online",text,szText)) {
  169 + RETURN_BOOL(obj->hSession->is_connected());
  170 + } else if(!strncasecmp("ready",text,szText)) {
  171 + RETURN_BOOL(obj->hSession->is_ready());
  172 + } else if(!strncasecmp("name",text,szText)) {
  173 + string str = obj->hSession->get_session_name();
  174 + RETURN_STRING(str.c_str(),1);
  175 + }
  176 +
  177 + RETURN_BOOL(0);
  178 +}
@@ -43,12 +43,16 @@ static zend_object_handlers tn3270_object_handlers; @@ -43,12 +43,16 @@ static zend_object_handlers tn3270_object_handlers;
43 zend_function_entry tn3270_methods[] = 43 zend_function_entry tn3270_methods[] =
44 { 44 {
45 PHP_ME( tn3270, __construct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) 45 PHP_ME( tn3270, __construct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
  46 + PHP_ME( tn3270, __tostring, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
  47 + PHP_ME( tn3270, __get, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
46 48
47 PHP_ME( tn3270, getversion, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) 49 PHP_ME( tn3270, getversion, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
48 PHP_ME( tn3270, getrevision, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) 50 PHP_ME( tn3270, getrevision, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
  51 + PHP_ME( tn3270, getname, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
49 52
50 PHP_ME( tn3270, connect, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) 53 PHP_ME( tn3270, connect, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
51 PHP_ME( tn3270, disconnect, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) 54 PHP_ME( tn3270, disconnect, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
  55 + PHP_ME( tn3270, close, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
52 56
53 PHP_ME( tn3270, isconnected, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) 57 PHP_ME( tn3270, isconnected, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
54 PHP_ME( tn3270, isready, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) 58 PHP_ME( tn3270, isready, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
@@ -51,6 +51,8 @@ PHP_METHOD(tn3270, connect) @@ -51,6 +51,8 @@ PHP_METHOD(tn3270, connect)
51 char text[szHost+1]; 51 char text[szHost+1];
52 strncpy(text,host,szHost); 52 strncpy(text,host,szHost);
53 text[szHost] = 0; 53 text[szHost] = 0;
  54 +
  55 + printf("[%s][%u]\n",text,(int) wait);
54 rc = obj->hSession->connect(text,(int) wait); 56 rc = obj->hSession->connect(text,(int) wait);
55 } 57 }
56 else 58 else
@@ -137,3 +139,11 @@ PHP_METHOD(tn3270, action) @@ -137,3 +139,11 @@ PHP_METHOD(tn3270, action)
137 RETURN_LONG(obj->hSession->action(buffer)); 139 RETURN_LONG(obj->hSession->action(buffer));
138 140
139 } 141 }
  142 +
  143 +PHP_METHOD(tn3270, close)
  144 +{
  145 + tn3270_object * obj = (tn3270_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
  146 +
  147 + RETURN_LONG(obj->hSession->close());
  148 +}
  149 +
src/php3270.h.in
@@ -48,12 +48,17 @@ @@ -48,12 +48,17 @@
48 48
49 // 3270 session methods 49 // 3270 session methods
50 PHP_METHOD(tn3270,__construct); 50 PHP_METHOD(tn3270,__construct);
  51 + PHP_METHOD(tn3270,__tostring);
  52 + PHP_METHOD(tn3270,__get);
  53 + PHP_METHOD(tn3270,__set);
51 54
52 PHP_METHOD(tn3270,getversion); 55 PHP_METHOD(tn3270,getversion);
53 PHP_METHOD(tn3270,getrevision); 56 PHP_METHOD(tn3270,getrevision);
  57 + PHP_METHOD(tn3270,getname);
54 58
55 PHP_METHOD(tn3270,connect); 59 PHP_METHOD(tn3270,connect);
56 PHP_METHOD(tn3270,disconnect); 60 PHP_METHOD(tn3270,disconnect);
  61 + PHP_METHOD(tn3270,close);
57 PHP_METHOD(tn3270,isconnected); 62 PHP_METHOD(tn3270,isconnected);
58 PHP_METHOD(tn3270,isready); 63 PHP_METHOD(tn3270,isready);
59 PHP_METHOD(tn3270,waitforready); 64 PHP_METHOD(tn3270,waitforready);
@@ -86,3 +86,18 @@ PHP_METHOD(tn3270, setstringat) @@ -86,3 +86,18 @@ PHP_METHOD(tn3270, setstringat)
86 RETURN_LONG(obj->hSession->set_string_at(row,col,buffer)); 86 RETURN_LONG(obj->hSession->set_string_at(row,col,buffer));
87 } 87 }
88 88
  89 +PHP_METHOD(tn3270, __set)
  90 +{
  91 + /*
  92 + tn3270_object * obj = (tn3270_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
  93 + const char * name;
  94 + int szName;
  95 + const char * text;
  96 + int szText;
  97 +
  98 + if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &szName, &text, &szText) == FAILURE)
  99 + RETURN_NULL();
  100 + */
  101 +
  102 + RETURN_NULL();
  103 +}
testprograms/service.php 0 → 100644
@@ -0,0 +1,29 @@ @@ -0,0 +1,29 @@
  1 +<?php
  2 +
  3 + printf("PW3270 Connection test\n");
  4 +
  5 + $host = new tn3270("service://?");
  6 +
  7 + echo "Sessão: " . $host->name . "\n";
  8 +
  9 + $rc = $host->connect("tn3270://fandezhi.efglobe.com:23",10);
  10 + if($rc != 0) {
  11 + die("Connection failed, rc=" . $rc . "\n");
  12 + }
  13 +
  14 + $rc = $host->waitforready(10);
  15 + if($rc != 0) {
  16 + die("Host is not ready, rc=" . $rc . "\n");
  17 + }
  18 +
  19 + echo "Connected: " . ($host->online ? "Yes" : "No") . "\n";
  20 + echo "Ready: " . ($host->ready ? "Yes" : "No") . "\n";
  21 +
  22 + echo "Contents:\n" . $host . "\n";
  23 +
  24 + $host->disconnect();
  25 + $host->close();
  26 +
  27 + die("Success!!\n");
  28 +
  29 +?>