FTP utilities #87

Parent #1Owner #2Flags readSource QuestCore.db

Aliases: FTP utilities

16 verbs · 7 properties · 0 children

Verbs

VerbSpecFlagsDefinerLines
openthis none thisrxd#8715
closethis none thisrxd#8712
do_commandthis none thisrxd#876
wait_for_responsethis none thisrxd#8723
controlsthis none thisrxd#871
get_messagesthis none thisrxd#8710
open_datathis none thisrxd#8724
get_datathis none thisrxd#879
put_datathis none thisrxd#8716
trustedthis none thisrxd#871
listenthis none thisrxd#8714
close_datathis none thisrxd#8712
getthis none thisrxd#8711
init_for_corethis none thisrxd#875
putthis none thisrxd#8711
data_connectionthis none thisrxd#874

Properties

PropertyDefinerFlagsOwnerValue
trusted#87rc#21
port#87rc#221
connections#87#2{}
key#1c#20
aliases#1rc#2{"FTP utilities"}
description#1rc#2<clear>
object_size#1r#36{9061, 1539462952}

Ancestry

Ancestors (nearest first): #1 Root Class

Children: none

Call graph

calls n87_0 #87:open n87_9 #87:trusted n87_0->n87_9 n72_2 #72:open n87_0->n72_2 n87_3 #87:wait_for_response n87_0->n87_3 n87_2 #87:do_command n87_0->n87_2 n87_5 #87:get_messages n87_0->n87_5 n55_18 #55:iassoc n87_0->n55_18 n72_3 #72:close n87_0->n72_3 n87_3->n55_18 n87_4 #87:controls n87_3->n87_4 n72_11 #72:read n87_3->n72_11 n6_18 #6:tell n87_3->n6_18 n87_2->n87_3 n87_2->n87_4 n72_17 #72:notify n87_2->n72_17 n87_5->n55_18 n87_5->n87_4 n87_1 #87:close n87_1->n87_2 n87_1->n72_3 n87_1->n87_4 n55_17 #55:assoc n87_1->n55_17 n72_12 #72:is_open n87_1->n72_12 n87_4->n55_17 n87_6 #87:open_data n87_6->n72_2 n87_6->n87_2 n87_6->n87_5 n87_6->n55_18 n87_6->n87_4 n87_6->n72_12 n87_10 #87:listen n87_6->n87_10 n87_10->n55_18 n87_7 #87:get_data n87_7->n55_18 n87_7->n87_4 n87_8 #87:put_data n87_8->n55_18 n87_8->n87_4 n87_8->n72_12 n56_8 #56:suspend_if_needed n87_8->n56_8 n87_11 #87:close_data n87_8->n87_11 n87_11->n72_3 n87_11->n87_4 n87_11->n55_17 n87_11->n72_12 n87_12 #87:get n87_12->n87_0 n87_12->n87_9 n87_12->n87_2 n87_12->n87_1 n87_12->n87_6 n87_12->n87_7 n87_13 #87:init_for_core n1_28 #1:init_for_core n87_13->n1_28 n87_14 #87:put n87_14->n87_0 n87_14->n87_9 n87_14->n87_2 n87_14->n87_1 n87_14->n87_6 n87_14->n87_8 n87_15 #87:data_connection n87_15->n55_18

Source

open

Spec this none thisFlags rxdOwner #2Definer #87

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 #2Definer #87

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 #2Definer #87

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 #2Definer #87

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 #2Definer #87

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 #2Definer #87

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 #2Definer #87

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 #2Definer #87

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 #2Definer #87

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 #2Definer #87

Referenced by

Source

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

listen

Spec this none thisFlags rxdOwner #2Definer #87

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(ticks_left() < 4000) && suspend(0);
11endwhile
12if (i = $list_utils:iassoc(conn, this.connections))
13this.connections[i][5] = data;
14endif

close_data

Spec this none thisFlags rxdOwner #2Definer #87

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 #2Definer #87

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 #2Definer #87

Referenced by

none

Source

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

put

Spec this none thisFlags rxdOwner #2Definer #87

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 #2Definer #87

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];