summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Skalski <askalski@php.net>1999-09-16 18:38:11 +0000
committerAndrew Skalski <askalski@php.net>1999-09-16 18:38:11 +0000
commit93313c576c1a98779d3e5e11e239e6cf8eb760b7 (patch)
tree5ef0017ffbc1c7dbc66ed807c37ae34641451278
parentf0688ad7e248c3065f4f9a29ed307804efd023a5 (diff)
downloadphp-git-93313c576c1a98779d3e5e11e239e6cf8eb760b7.tar.gz
added ftp_systype() and ftp_listraw() functions
-rw-r--r--ext/ftp/ftp.c111
-rw-r--r--ext/ftp/ftp.h2
2 files changed, 113 insertions, 0 deletions
diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c
index 717a751d5e..8eaadd682e 100644
--- a/ext/ftp/ftp.c
+++ b/ext/ftp/ftp.c
@@ -45,6 +45,8 @@ function_entry php3_ftp_functions[] = {
PHP_FE(ftp_login, NULL)
PHP_FE(ftp_chdir, NULL)
PHP_FE(ftp_nlist, NULL)
+ PHP_FE(ftp_listraw, NULL)
+ PHP_FE(ftp_systype, NULL)
PHP_FE(ftp_get, NULL)
PHP_FE(ftp_put, NULL)
PHP_FE(ftp_quit, NULL)
@@ -251,6 +253,115 @@ PHP_FUNCTION(ftp_nlist)
fclose(outfp);
}
+PHP_FUNCTION(ftp_listraw)
+{
+ pval *arg1, *arg2;
+ int id, type;
+ netbuf *net;
+ FILE *outfp;
+ char *entry = NULL;
+ char *ptr;
+ long size;
+ char ch;
+
+
+ /* arg1 - netbuf
+ * arg2 - directory
+ */
+ if ( ARG_COUNT(ht) != 2 ||
+ getParameters(ht, 2, &arg1, &arg2) == FAILURE)
+ {
+ WRONG_PARAM_COUNT;
+ }
+
+ convert_to_long(arg1);
+ convert_to_string(arg2);
+
+ id = arg1->value.lval;
+ net = php3_list_find(id, &type);
+ if (!net || type != le_netbuf) {
+ php_error(E_WARNING, "Unable to find netbuf %d", id);
+ RETURN_FALSE;
+ }
+
+ /* set up a temporary output file */
+ if ((outfp = tmpfile()) == NULL) {
+ php_error(E_WARNING, "error opening tmpfile");
+ RETURN_FALSE;
+ }
+
+ /* list to the temporary file */
+ if (!FtpDir(outfp, arg2->value.str.val, net) || ferror(outfp)) {
+ fclose(outfp);
+ RETURN_FALSE;
+ }
+
+ array_init(return_value);
+ rewind(outfp);
+
+ /* Pluck out each file name and save to the return array. */
+ do {
+ /* scan for end of line */
+ size = 1;
+ while ((ch = getc(outfp)) != '\n') {
+ if (ch == EOF) {
+ size = -1;
+ break;
+ }
+ size++;
+ }
+
+ if (size > 0) {
+ /* seek back to the start of file name and copy
+ * to a buffer. add the buffer to the array.
+ */
+ fseek(outfp, -size, SEEK_CUR);
+ entry = emalloc(size);
+ ptr = entry;
+ while (--size)
+ *ptr++ = getc(outfp);
+ *ptr = 0;
+
+ add_next_index_string(return_value, entry, 0);
+ }
+
+ /* eat the \n */
+ (void) getc(outfp);
+ } while (size != -1);
+ fclose(outfp);
+}
+
+PHP_FUNCTION(ftp_systype)
+{
+ pval *arg1;
+ int id, type;
+ netbuf *net;
+ char buf[64];
+
+
+ /* arg1 - netbuf
+ * arg2 - directory
+ */
+ if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg1) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+
+ convert_to_long(arg1);
+
+ id = arg1->value.lval;
+ net = php3_list_find(id, &type);
+ if (!net || type != le_netbuf) {
+ php_error(E_WARNING, "Unable to find netbuf %d", id);
+ RETURN_FALSE;
+ }
+
+ if (!FtpSysType(buf, sizeof(buf), net)) {
+ RETURN_FALSE;
+ }
+
+ RETURN_STRING(buf, 1);
+}
+
PHP_FUNCTION(ftp_get)
{
pval *arg1, *arg2, *arg3, *arg4;
diff --git a/ext/ftp/ftp.h b/ext/ftp/ftp.h
index 798633e6e1..e23b659ae5 100644
--- a/ext/ftp/ftp.h
+++ b/ext/ftp/ftp.h
@@ -19,6 +19,8 @@ PHP_FUNCTION(ftp_connect);
PHP_FUNCTION(ftp_login);
PHP_FUNCTION(ftp_chdir);
PHP_FUNCTION(ftp_nlist);
+PHP_FUNCTION(ftp_listraw);
+PHP_FUNCTION(ftp_systype);
PHP_FUNCTION(ftp_get);
PHP_FUNCTION(ftp_put);
PHP_FUNCTION(ftp_quit);