;"MidgardCORE Network Server Utilities" ;"Copyright 1997, 1998 Midgard Systems and Adam 'Martian' Smyth" ;"This code is free software; you can redistribute it and/or" ;"modify it under the terms of the GNU General Public License" ;"as published by the Free Software Foundation; either version 2" ;"of the License, or (at your option) any later version." ;"This program is distributed in the hope that it will be useful," ;"but WITHOUT ANY WARRANTY; without even the implied warranty of" ;"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the" ;"GNU General Public License for more details." ;"The License is available at http://www.gnu.org/copyleft/gpl.html" ;"The author can be contacted at martian@midgard.org" ;"It is *strongly requested* that users of this code register with the author." ;"The latest release of this code can be found at" ;" http://www.midgard.org:8080/~martian/Code/MOO/network_utils.moo" ;" This module is designed to be pasted as-is into a connection to a MOO server." ;"Begining installation..." ;"Simple sanity check. Don't make more than one, if it already exists."; ;if(`valid($network_utils) ! ANY');while(read()!=";\"-----\"");endwhile;endif @create $generic_utils called Network Server Utilities,NSU @corify NSU as $network_utils ;"-----" ;$network_utils.description=$command_utils:read() Miscellaneous verbs for the Internet server objects. @verb $network_utils:"SetHeader" this none this rxd @program $network_utils:SetHeader {headers, header, value, ?append = 0} = args; if (!append) for l in [1..length(headers)] if (match(headers[l], "^" + header + ": .*$")) headers[l] = tostr(header, ": ", value); return headers; endif endfor endif return {@headers, tostr(header, ": ", value)}; . @verb $network_utils:"ContentLength" this none this rxd @program $network_utils:ContentLength if (typeof(line = args[1]) == STR) return this:BinaryStringLength(line); endif Len = 0; for line in (args[1]) Len = Len + length(line) + 2; ticks_left() < 1000 || seconds_left() < 1 && suspend(0); endfor return Len; . @verb $network_utils:"BinaryStringLength" this none this rxd @program $network_utils:BinaryStringLength return length(decode_binary(args[1], 1)); ""; l = length(args[1]); d = length($string_utils:strip_chars(args[1], "~")); return 2 * d - l; . @verb $network_utils:"INetSTDTime" this none this rxd @program $network_utils:INetSTDTime Time = args ? args[1] | time(); return tostr($time_utils:time_sub("$d, $T $n $Y $H:$M:$S", Time), " -0", $list_utils:assoc(TZ = $time_utils:time_sub("$Z", Time), $time_utils.timezones)[2], "00 (", TZ, ")"); . @verb $network_utils:"BinaryListToDecimal" this none this rxd @program $network_utils:BinaryListToDecimal Val = 0; Mult = 1; for I in ($list_utils:reverse(args[1])) Val = Val + I * Mult; Mult = Mult * 256; endfor return Val; . @verb $network_utils:"BuildMailHeaders" this none this rxd @program $network_utils:BuildMailHeaders {From, To, Subject} = args; return {tostr("Date: ", this:INetStdTime()), tostr("From: ", From), tostr("To: ", To), tostr("Subject: ", Subject)}; . @verb $network_utils:"GetHeader" this none this rxd @program $network_utils:GetHeader {headers, header} = args; for l in [1..length(headers)] if (m = match(headers[l], "^" + header + ": %(.*%)$")) return substitute("%1", m); endif endfor return E_NONE; . @verb $network_utils:"GetAllHeaders" this none this rxd @program $network_utils:GetAllHeaders {headers, header} = args; values = {}; for l in [1..length(headers)] if (m = match(headers[l], "^" + header + ": %(.*%)$")) values = {@values, substitute("%1", m)}; endif endfor return values; . @verb $network_utils:"URL2TEXT" this none this rxd @program $network_utils:URL2TEXT url = args[1]; text = {""}; I = 1; while (I <= length(url)) if (url[I] == "%") C = url[I + 1..I + 2]; C = $math_utils:base_conversion(C, 16, 10); C = tonum(C); if (C == 13) text = {@text, ""}; elseif (C == 10) else C = $string_utils.ascii[C - 31]; text[$] = text[$] + C; endif I = I + 3; else if (url[I] == "+") text[$] = text[$] + " "; else text[$] = text[$] + url[I]; endif I = I + 1; endif $command_utils:suspend_if_needed(0); endwhile if (length(text) == 1) text = text[1]; endif return text; . @verb $network_utils:"InetDateToTime" this none this rxd @program $network_utils:InetDateToTime Date = $string_utils:words(args[1]); if (length(Date) < 7) return $time_utils:from_ctime(args[1]); endif Tz = Date[6]; Date = tostr("DOW ", Date[3], " ", Date[2], " ", Date[5], " ", Date[4], " GMT"); Date = $time_utils:from_ctime(Date); Date = Date - tonum(Tz) / 100 * 3600; return Date; . ;"End of Module"