1 # include <kernel/kernel.h> 2 # include <kernel/user.h> 3 4 private object connection; /* associated connection object */ 5 private string name; /* name of user */ 6 7 8 /* 9 * NAME: query_conn() 10 * DESCRIPTION: query the associated connection 11 */ query_conn()12nomask object query_conn() 13 { 14 return connection; 15 } 16 17 /* 18 * NAME: disconnect() 19 * DESCRIPTION: terminate the connection 20 */ disconnect()21static void disconnect() 22 { 23 if (connection) { 24 connection->disconnect(); 25 } 26 } 27 28 /* 29 * NAME: connection() 30 * DESCRIPTION: establish connection 31 */ connection(object LIB_CONN conn)32static void connection(object LIB_CONN conn) 33 { 34 if (conn) { 35 disconnect(); 36 connection = conn; 37 } 38 } 39 40 /* 41 * NAME: redirect() 42 * DESCRIPTION: direct connection to a different user object 43 */ redirect(object LIB_USER user,string str)44static void redirect(object LIB_USER user, string str) 45 { 46 object conn; 47 48 if (!user || !connection) { 49 error("Bad redirect"); 50 } 51 conn = connection; 52 connection = nil; 53 conn->set_user(user, str); 54 } 55 56 /* 57 * NAME: login() 58 * DESCRIPTION: log this user in 59 */ login(string str)60static void login(string str) 61 { 62 if (!name || name == str) { 63 USERD->login(this_object(), name = str); 64 } 65 } 66 67 /* 68 * NAME: logout() 69 * DESCRIPTION: logout this user 70 */ logout()71static void logout() 72 { 73 USERD->logout(this_object(), name); 74 } 75 76 /* 77 * NAME: query_name() 78 * DESCRIPTION: return this user's name (if any) 79 */ query_name()80string query_name() 81 { 82 return name; 83 } 84 85 /* 86 * NAME: message() 87 * DESCRIPTION: forward a message to the connection object 88 */ message(string str)89int message(string str) 90 { 91 if (!str) { 92 error("Bad argument 1 for function message"); 93 } 94 if (connection) { 95 return connection->message(str); 96 } 97 return 0; 98 } 99 100 /* 101 * NAME: message_done() 102 * DESCRIPTION: placeholder function which does no buffering 103 */ message_done()104int message_done() 105 { 106 return MODE_NOCHANGE; 107 } 108 109 /* 110 * NAME: datagram_challenge() 111 * DESCRIPTION: set the challenge for the datagram channel 112 */ datagram_challenge(string str)113static void datagram_challenge(string str) 114 { 115 if (!str) { 116 error("Bad argument 1 for function datagram_challenge"); 117 } 118 if (connection) { 119 connection->datagram_challenge(str); 120 } 121 } 122 123 /* 124 * NAME: datagram() 125 * DESCRIPTION: forward a datagram to the connection object 126 */ datagram(string str)127int datagram(string str) 128 { 129 if (!str) { 130 error("Bad argument 1 for function datagram"); 131 } 132 if (connection) { 133 return connection->datagram(str); 134 } 135 return 0; 136 } 137