The attached diff adds 2 ftp functions. I read the
README.SUBMITTING_PATCH and went thru all the steps, but there are no
tests for ftp, and I didn't understand how to update the docs. So if
someone would like to help me with that, great.

Basically, I modifed ftpbuf_t adding a 2 dimensional array (array of
strings) to store the conversation, and an int that indicates the next
element in first dimension the array. I modified ftp_putcmd and
ftp_getresp to add what gets sent/recvd in the conversation. And lastly
I added ftp_get_resp which returns the 3 digit return code from the
server of the last command sent, and ftp_get_conv (which I would not be
opposed to changing the name of, that's just what I came up with) that
returns the ftp conversation as an array. Both functions must be called
before ftp_close (or ftp_quit) because it frees the resource.

The array I defined is 2500x4096. 4096 was already there as the
FTP_BUFSIZE, 2500 maybe a little excesive but in my environment it could
get that bad. :/ So I was thinking that maybe I should add a optional
flag on ftp_connect on where or not to trace the conversation? Thoughts?

Jess
Index: ext/ftp/ftp.c
===================================================================
RCS file: /repository/php-src/ext/ftp/ftp.c,v
retrieving revision 1.106
diff -u -r1.106 ftp.c
--- ext/ftp/ftp.c       5 Oct 2004 23:53:09 -0000       1.106
+++ ext/ftp/ftp.c       16 Dec 2004 04:13:02 -0000
@@ -1125,6 +1125,16 @@
                size = sprintf(ftp->outbuf, "%s\r\n", cmd);
        }
 
+    /* write command to convbuff[] */
+       if(ftp->convcntr < FTP_CONV_BUFSIZE){
+               if(strcmp(cmd,"PASS") != 0){
+                       sprintf(ftp->convbuf[ftp->convcntr], "---> %s", 
ftp->outbuf);
+               } else {
+                       sprintf(ftp->convbuf[ftp->convcntr], "---> PASS 
XXXXXXXX");
+               }
+       }
+       ftp->convcntr++;
+
        data = ftp->outbuf;
 
        if (my_send(ftp, ftp->fd, data, size) != size) {
@@ -1205,6 +1215,13 @@
                        return 0;
                }
 
+        /* copy contents of inbuf to convbuff[] */
+               if(ftp->convcntr < FTP_CONV_BUFSIZE){
+                       memcpy(ftp->convbuf[ftp->convcntr], ftp->inbuf, 
FTP_BUFSIZE);
+                       ftp->convcntr++;
+               }
+                               
+               
                /* Break out when the end-tag is found */
                if (isdigit(ftp->inbuf[0]) && isdigit(ftp->inbuf[1]) && 
isdigit(ftp->inbuf[2]) && ftp->inbuf[3] == ' ') {
                        break;
Index: ext/ftp/ftp.h
===================================================================
RCS file: /repository/php-src/ext/ftp/ftp.h,v
retrieving revision 1.42
diff -u -r1.42 ftp.h
--- ext/ftp/ftp.h       8 Jan 2004 17:32:08 -0000       1.42
+++ ext/ftp/ftp.h       16 Dec 2004 04:13:02 -0000
@@ -37,6 +37,7 @@
 
 /* XXX this should be configurable at runtime XXX */
 #define        FTP_BUFSIZE     4096
+#define FTP_CONV_BUFSIZE 2500
 
 typedef enum ftptype {
        FTPTYPE_ASCII,
@@ -84,6 +85,9 @@
        int                             old_ssl;        /* old mode = forced 
data encryption */
        SSL                             *ssl_handle;      /* handle for control 
connection */
        int                             ssl_active;               /* ssl active 
on control conn */
+       char    convbuf[FTP_CONV_BUFSIZE][FTP_BUFSIZE]; /* complete 
conversation */
+       int     convcntr;               /* position of next element in convbuf 
*/
+
 #endif
 
 } ftpbuf_t;
Index: ext/ftp/php_ftp.c
===================================================================
RCS file: /repository/php-src/ext/ftp/php_ftp.c,v
retrieving revision 1.101
diff -u -r1.101 php_ftp.c
--- ext/ftp/php_ftp.c   27 Sep 2004 14:25:13 -0000      1.101
+++ ext/ftp/php_ftp.c   16 Dec 2004 04:13:02 -0000
@@ -87,6 +87,8 @@
        PHP_FE(ftp_nb_continue,         NULL)
        PHP_FE(ftp_nb_put,                      NULL)
        PHP_FE(ftp_nb_fput,                     NULL)
+       PHP_FE(ftp_get_resp,                    NULL)
+       PHP_FE(ftp_get_conv,                    NULL)
        PHP_FALIAS(ftp_quit, ftp_close, NULL)
        {NULL, NULL, NULL}
 };
@@ -1236,6 +1238,49 @@
 }
 /* }}} */
 
+/* {{{ proto string ftp_get_resp(resource stream)
+ *    Returns the response code of last command */
+PHP_FUNCTION(ftp_get_resp)
+{
+        zval            *z_ftp;
+        ftpbuf_t        *ftp;
+        int             resp;
+
+        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_ftp) == 
FAILURE) {
+               return;
+        }
+
+       ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, 
le_ftpbuf);
+       if (0 == (resp = ftp_get_lastresp(ftp))) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
+               RETURN_FALSE;
+       }
+       RETURN_LONG(resp);
+}
+/* }}} */
+
+/* {{{ proto array ftp_get_conv(resource stream)
+ *    Returns an array containing the entire FTP conversation */
+PHP_FUNCTION(ftp_get_conv)
+{
+       zval            *z_ftp;
+       ftpbuf_t        *ftp;
+       char            *ptr1, **ptr2;
+       zend_bool       recursive = 0;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &z_ftp) == 
FAILURE) {
+               return;
+       }
+
+       ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, 
le_ftpbuf);
+
+       array_init(return_value);
+       for (ptr1 = (char*)ftp->convbuf; **ptr2; ptr1 += FTP_BUFSIZE) {
+               *ptr2 = ptr1;
+               add_next_index_string(return_value, *ptr2, 1);
+       }
+}
+/* }}} */
+
 #endif /* HAVE_FTP */
 
 /*
Index: ext/ftp/php_ftp.h
===================================================================
RCS file: /repository/php-src/ext/ftp/php_ftp.h,v
retrieving revision 1.28
diff -u -r1.28 php_ftp.h
--- ext/ftp/php_ftp.h   8 Jan 2004 17:32:08 -0000       1.28
+++ ext/ftp/php_ftp.h   16 Dec 2004 04:13:02 -0000
@@ -69,6 +69,8 @@
 PHP_FUNCTION(ftp_nb_put);
 PHP_FUNCTION(ftp_nb_fput);
 PHP_FUNCTION(ftp_nb_continue);
+PHP_FUNCTION(ftp_get_resp);
+PHP_FUNCTION(ftp_get_conv);
 
 #define phpext_ftp_ptr php_ftp_module_ptr
 
-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to