FTP utilities #80

Parent #72Owner #361Flags readSource hellcore/hellcore.db

Aliases: FTP utilities

16 verbs · 14 properties · 0 children

Verbs

VerbSpecFlagsDefinerLines
openthis none thisrxd#8015
closethis none thisrxd#8012
do_commandthis none thisrxd#806
wait_for_responsethis none thisrxd#8023
controlsthis none thisrxd#801
get_messagesthis none thisrxd#8010
open_datathis none thisrxd#8024
get_datathis none thisrxd#809
put_datathis none thisrxd#8016
trustedthis none thisrxd#801
listenthis none thisrxd#8014
close_datathis none thisrxd#8012
getthis none thisrxd#8011
init_for_corethis none thisrxd#805
putthis none thisrxd#8011
data_connectionthis none thisrxd#804

Properties

PropertyDefinerFlagsOwnerValue
trusted#80rc#3611
port#80rc#36121
connections#80#361{}
help_msg#72rc#361<clear>
aliases#1rc#361{"FTP utilities"}
description#1rc#361<clear>
object_size#1r#29{9379, 1298433815}
hidden_verbs#1rc#361<clear>
phelp_msg#1rc#361<clear>
weight#1rc#361<clear>
owner_verbs#1rc#361<clear>
plural_name#1rc#361<clear>
client_image#1rc#361<clear>
listening#1rc#361<clear>

Ancestry

Ancestors (nearest first): #72 Generic Utilities Package#1 root

Children: none

Call graph

calls n80_0 #80:open n80_9 #80:trusted n80_0->n80_9 n66_2 #66:open n80_0->n66_2 n80_3 #80:wait_for_response n80_0->n80_3 n80_2 #80:do_command n80_0->n80_2 n80_5 #80:get_messages n80_0->n80_5 n47_18 #47:iassoc n80_0->n47_18 n66_3 #66:close n80_0->n66_3 n80_3->n47_18 n80_4 #80:controls n80_3->n80_4 n66_11 #66:read n80_3->n66_11 n107_43 #107:tell n80_3->n107_43 n80_2->n80_3 n80_2->n80_4 n66_17 #66:notify n80_2->n66_17 n80_5->n47_18 n80_5->n80_4 n80_1 #80:close n80_1->n80_2 n80_1->n66_3 n80_1->n80_4 n47_17 #47:assoc n80_1->n47_17 n66_12 #66:is_open n80_1->n66_12 n80_4->n47_17 n80_6 #80:open_data n80_6->n66_2 n80_6->n80_2 n80_6->n80_5 n80_6->n47_18 n80_6->n80_4 n80_6->n66_12 n80_10 #80:listen n80_6->n80_10 n80_10->n47_18 n48_8 #48:suspend_if_needed n80_10->n48_8 n80_7 #80:get_data n80_7->n47_18 n80_7->n80_4 n80_8 #80:put_data n80_8->n47_18 n80_8->n80_4 n80_8->n66_12 n80_8->n48_8 n80_11 #80:close_data n80_8->n80_11 n80_11->n66_3 n80_11->n80_4 n80_11->n47_17 n80_11->n66_12 n80_12 #80:get n80_12->n80_0 n80_12->n80_9 n80_12->n80_2 n80_12->n80_1 n80_12->n80_6 n80_12->n80_7 n80_13 #80:init_for_core n1_22 #1:init_for_core n80_13->n1_22 n80_14 #80:put n80_14->n80_0 n80_14->n80_9 n80_14->n80_2 n80_14->n80_1 n80_14->n80_6 n80_14->n80_8 n80_15 #80:data_connection n80_15->n47_18

Source

open

Spec this none thisFlags rxdOwner #361Definer #80

Referenced by

Source

1if (!this:trusted(caller_perms()))
2return E_PERM;
3endif
4{host, ?user = "", ?pass = ""} = args;
5if (typeof(conn = $network:open(host, this.port)) == ERR)
6return {"Unable to connect to host."};
7endif
8this.connections = {@this.connections, {conn, caller_perms(), {}, 0, {}}};
9if (((!this:wait_for_response(conn)) || (user && (!this:do_command(conn, "USER " + user)))) || (pass && (!this:do_command(conn, "PASS " + pass))))
10messages = this:get_messages(conn);
11this.connections = listdelete(this.connections, $list_utils:iassoc(conn, this.connections));
12$network:close(conn);
13return messages;
14endif
15return conn;

close

Spec this none thisFlags rxdOwner #361Definer #80

Referenced by

Source

1conn = args[1];
2if (!this:controls(caller_perms(), conn))
3return E_PERM;
4endif
5this:do_command(conn, "QUIT");
6info = $list_utils:assoc(conn, this.connections);
7this.connections = setremove(this.connections, info);
8$network:close(conn);
9if ($network:is_open(info[4]))
10$network:close(info[4]);
11endif
12return info[3];

do_command

Spec this none thisFlags rxdOwner #361Definer #80

Referenced by

Source

1{conn, cmd, ?nowait = 0} = args;
2if (!this:controls(caller_perms(), conn))
3return E_PERM;
4endif
5$network:notify(conn, cmd);
6return nowait ? 1 | this:wait_for_response(conn);

wait_for_response

Spec this none thisFlags rxdOwner #361Definer #80

Referenced by

Source

1{conn, ?first_only = 0} = args;
2if (!this:controls(caller_perms(), conn))
3return E_PERM;
4endif
5matchstr = first_only ? "^[1-9][0-9][0-9] " | "^[2-9][0-9][0-9] ";
6messages = {};
7result = "";
8while ((typeof(result) == STR) && (!match(result, matchstr)))
9result = $network:read(conn);
10messages = {@messages, result};
11endwhile
12i = $list_utils:iassoc(conn, this.connections);
13this.connections[i][3] = {@this.connections[i][3], @messages};
14if (typeof(result) == STR)
15if (result[1] in {"4", "5"})
16player:tell(result);
17return E_NONE;
18else
19return 1;
20endif
21else
22return result;
23endif

controls

Spec this none thisFlags rxdOwner #361Definer #80

Referenced by

Source

1return args[1].wizard || ({@$list_utils:assoc(args[2], this.connections), 0, 0}[2] == args[1]);

get_messages

Spec this none thisFlags rxdOwner #361Definer #80

Referenced by

Source

1{conn, ?keep = 0} = args;
2if (!this:controls(caller_perms(), conn))
3return E_PERM;
4endif
5i = $list_utils:iassoc(conn, this.connections);
6messages = this.connections[i][3];
7if (!keep)
8this.connections[i][3] = {};
9endif
10return messages;

open_data

Spec this none thisFlags rxdOwner #361Definer #80

Referenced by

Source

1conn = args[1];
2if (!this:controls(caller_perms(), conn))
3return E_PERM;
4endif
5i = $list_utils:iassoc(conn, this.connections);
6if (!$network:is_open(this.connections[i][4]))
7this:do_command(conn, "PASV");
8msg = (msg = this:get_messages(conn, 1))[$];
9if (msg[1..3] != "227")
10return E_TYPE;
11elseif (!(match = match(msg, "(%([0-9]+%),%([0-9]+%),%([0-9]+%),%([0-9]+%),%([0-9]+%),%([0-9]+%))")))
12return E_TYPE;
13elseif (typeof(dconn = $network:open(substitute("%1.%2.%3.%4", match), (toint(substitute("%5", match)) * 256) + toint(substitute("%6", match)))) == ERR)
14return dconn;
15else
16this.connections[i][4] = dconn;
17endif
18this.connections[i][5] = E_INVARG;
19set_task_perms(caller_perms());
20fork (0)
21this:listen(conn, dconn);
22endfork
23endif
24return 1;

get_data

Spec this none thisFlags rxdOwner #361Definer #80

Referenced by

Source

1{conn, ?nowait = 0} = args;
2if (!this:controls(caller_perms(), conn))
3return E_PERM;
4endif
5i = $list_utils:iassoc(conn, this.connections);
6while ((!nowait) && (this.connections[i][5] == E_INVARG))
7suspend(0);
8endwhile
9return this.connections[i][5];

put_data

Spec this none thisFlags rxdOwner #361Definer #80

Referenced by

Source

1{conn, data} = args;
2if (!this:controls(caller_perms(), conn))
3return E_PERM;
4endif
5i = $list_utils:iassoc(conn, this.connections);
6dconn = this.connections[i][4];
7if (!$network:is_open(dconn))
8return E_INVARG;
9else
10for line in (data)
11notify(dconn, line);
12$command_utils:suspend_if_needed(0);
13endfor
14this:close_data(conn);
15this.connections[i][4] = 0;
16endif

trusted

Spec this none thisFlags rxdOwner #361Definer #80

Referenced by

Source

1return args[1].wizard || ((typeof(this.trusted) == LIST) ? args[1] in this.trusted | this.trusted);

listen

Spec this none thisFlags rxdOwner #361Definer #80

Referenced by

Source

1if (caller != this)
2return E_PERM;
3endif
4{conn, dconn} = args;
5data = {};
6line = `read(dconn) ! ANY';
7while (typeof(line) == STR)
8data = {@data, line};
9line = read(dconn);
10$command_utils:suspend_if_needed(0);
11endwhile
12if (i = $list_utils:iassoc(conn, this.connections))
13this.connections[i][5] = data;
14endif

close_data

Spec this none thisFlags rxdOwner #361Definer #80

Referenced by

Source

1conn = args[1];
2if (!this:controls(caller_perms(), conn))
3return E_PERM;
4endif
5if (!$network:is_open(dconn = $list_utils:assoc(conn, this.connections)[4]))
6return E_INVARG;
7else
8$network:close(dconn);
9"...let the reading task come to terms with its abrupt superfluousness...";
10suspend(0);
11return 1;
12endif

get

Spec this none thisFlags rxdOwner #361Definer #80

Referenced by

none

Source

1":get(host, username, password, filename)";
2if (!this:trusted(caller_perms()))
3return E_PERM;
4endif
5if (typeof(conn = this:open(@args[1..3])) != OBJ)
6return E_NACC;
7else
8result = (this:open_data(conn) && this:do_command(conn, "RETR " + args[4])) && this:get_data(conn);
9this:close(conn);
10return result;
11endif

init_for_core

Spec this none thisFlags rxdOwner #361Definer #80

Referenced by

none

Source

1if (caller_perms().wizard)
2this.connections = {};
3this.trusted = 1;
4pass(@args);
5endif

put

Spec this none thisFlags rxdOwner #361Definer #80

Referenced by

none

Source

1":put(host, username, password, filename, data)";
2if (!this:trusted(caller_perms()))
3return E_PERM;
4endif
5if (typeof(conn = this:open(@args[1..3])) != OBJ)
6return E_NACC;
7else
8result = (this:open_data(conn) && this:do_command(conn, "STOR " + args[4], 1)) && this:put_data(conn, args[5]);
9this:close(conn);
10return result;
11endif

data_connection

Spec this none thisFlags rxdOwner #361Definer #80

Referenced by

none

Source

1"return the data connection associated with the control connection args[1]";
2conn = args[1];
3i = $list_utils:iassoc(conn, this.connections);
4return this.connections[i][4];