00001 // 00002 // The UserTTYConn class - connect to a direct-to-the-user tty... 00003 // 00004 // ***** BEGIN LICENSE BLOCK ***** 00005 // Version: MPL 1.1/GPL 2.0/LGPL 2.1 00006 // 00007 // The contents of this file are subject to the Mozilla Public License 00008 // Version 1.1 (the "License"); you may not use this file except in 00009 // compliance with the License. You may obtain a copy of the License at 00010 // http://www.mozilla.org/MPL/ 00011 // 00012 // Software distributed under the License is distributed on an "AS IS" 00013 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00014 // the License for the specific language governing rights and limitations 00015 // under the License. 00016 // 00017 // The Original Code is the consmgr network/serial-line monitoring package. 00018 // 00019 // The Initial Developer of the Original Code is Chris P. Ross. 00020 // Portions created by the Initial Developer are Copyright (C) 2000-2008 00021 // the Initial Developer. All Rights Reserved. 00022 // 00023 // Contributor(s): 00024 // Geoff Adams 00025 // 00026 // Alternatively, the contents of this file may be used under the terms of 00027 // either the GNU General Public License Version 2 or later (the "GPL"), or 00028 // the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 00029 // in which case the provisions of the GPL or the LGPL are applicable instead 00030 // of those above. If you wish to allow use of your version of this file only 00031 // under the terms of either the GPL or the LGPL, and not to allow others to 00032 // use your version of this file under the terms of the MPL, indicate your 00033 // decision by deleting the provisions above and replace them with the notice 00034 // and other provisions required by the GPL or the LGPL. If you do not delete 00035 // the provisions above, a recipient may use your version of this file under 00036 // the terms of any one of the MPL, the GPL or the LGPL. 00037 // 00038 // ***** END LICENSE BLOCK ***** 00039 00040 extern "C" { 00041 #include <unistd.h> 00042 #include <fcntl.h> 00043 #include <signal.h> 00044 } 00045 00046 #include "consmgr.h" 00047 #include "userttyconn.h" 00048 00049 #define OOB_MARKER 0x1c 00050 00051 #warning "The ability of UserTTYConn to remove the control bytes from the data stream has been removed. This might need to be fixed if we don't move all of this out into a protocol." 00052 00053 #if 0 00054 // Look for OOB command sequences in the user input 00055 void 00056 UserTTYConn::process_data(Data *blob) 00057 { 00058 clog << "UserTTYConn::process_data: Got Data of length " << blob->len() << endl; 00059 00060 if (blob->len() < 1) 00061 return; 00062 00063 // Now, loop through the data, looking for OOB command sequences. 00064 unsigned char *data = blob->data(); 00065 size_t i = 0; 00066 while (i < blob->len()) { 00067 if (in_oob_sequence) { 00068 if (handle_oob_sequence(blob, i)) 00069 in_oob_sequence = false; 00070 } else if (at_line_start && *data == OOB_MARKER) { 00071 in_oob_sequence = true; 00072 // blob->del_range(i, 1); 00073 } else { 00074 // It's an in-band character. 00075 at_line_start = (*data == '\n' || *data == '\r'); 00076 i++; 00077 } 00078 } 00079 00080 // (Note that, in the above, an OOB command sequence must occur at the 00081 // start of a line, and does not add any in-band data, so it leaves us 00082 // at the start of the line.) 00083 } 00084 #endif 00085 00086 // Returns whether the OOB sequence is complete. (There might be some more 00087 // expected characters coming in a subsequent Blob.) 00088 bool 00089 UserTTYConn::handle_oob_sequence(Data *blob, size_t offset) 00090 { 00091 if (blob->len() == 0) 00092 return false; 00093 00094 // We only handle single-byte commands (after the OOB_MARKER) for now, 00095 // so this is pretty easy. 00096 unsigned char c = blob->data()[offset]; 00097 switch (c) { 00098 case OOB_MARKER: 00099 // Leave the marker character in place; this allows the user 00100 // to send the OOB marker character by typing it twice. In 00101 // order for the OOB parser not to consume this character, 00102 // though, we need to trick it by indicating that this is not 00103 // at the start of a line. In fact, that will be true the 00104 // moment this character is sent, anyway. 00105 at_line_start = false; 00106 break; 00107 case '.': 00108 // XXX - Need to send a message to the main program to quit. 00109 // Let's be a little rude for now. 00110 // Actually, what we should do is send a disconnection message to 00111 // our owning Messageable. It's up to the Connection object to 00112 // decide that the user disconnecting means the program should quit. 00113 //cerr << "Killing me softly..." << endl; 00114 kill(getpid(), SIGTERM); 00115 break; // NOTREACHED 00116 case '?': 00117 // XXX - Need to send a message to the main program to print 00118 // out an OOB-command help message. 00119 break; 00120 } 00121 00122 #if 0 00123 if (c != OOB_MARKER) 00124 blob->del_range(offset, 1); 00125 #endif 00126 00127 return true; 00128 }