Back to index

lightning-sunbird  0.9+nobinonly
mozLineTerm.cpp
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is XMLterm.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Ramalingam Saravanan.
00018  * Portions created by the Initial Developer are Copyright (C) 1999
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Pierre Phaneuf <pp@ludusdesign.com>
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 // mozLineTerm.cpp: class implementing mozILineTerm/mozILineTermAux interfaces,
00039 // providing an XPCOM/XPCONNECT wrapper for the LINETERM module
00040 
00041 #include <stdio.h>
00042 
00043 #include "nspr.h"
00044 #include "nscore.h"
00045 #include "nsCOMPtr.h"
00046 #include "nsString.h"
00047 #include "nsXPIDLString.h"
00048 #include "plstr.h"
00049 #include "nsReadableUtils.h"
00050 #include "prlog.h"
00051 #include "nsMemory.h"
00052 
00053 #include "nsIServiceManager.h"
00054 #include "nsIPrefBranch.h"
00055 #include "nsIPrefService.h"
00056 #include "nsIPrincipal.h"
00057 
00058 #include "nsIDocument.h"
00059 #include "nsIDOMHTMLDocument.h"
00060 
00061 #include "mozXMLT.h"
00062 #include "mozXMLTermUtils.h"
00063 #include "mozLineTerm.h"
00064 
00065 #define MAXCOL 4096            // Maximum columns in line buffer
00066 
00068 // mozLineTerm implementaion
00070 
00071 NS_GENERIC_FACTORY_CONSTRUCTOR(mozLineTerm)
00072 
00073 NS_IMPL_THREADSAFE_ISUPPORTS2(mozLineTerm, 
00074                               mozILineTerm,
00075                               mozILineTermAux)
00076 
00077 
00078 PRBool mozLineTerm::mLoggingEnabled = PR_FALSE;
00079 
00080 PRBool mozLineTerm::mLoggingInitialized = PR_FALSE;
00081 
00082 NS_METHOD
00083 mozLineTerm::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
00084 {
00085   if (!mLoggingInitialized) {
00086     // Initialize all LINETERM operations
00087     // (This initialization needs to be done at factory creation time;
00088     //  trying to do it earlier, i.e., at registration time,
00089     //  does not work ... something to do with loading of static global
00090     //  variables.)
00091 
00092     int messageLevel = 0;
00093     char* debugStr = (char*) PR_GetEnv("LTERM_DEBUG");
00094 
00095     if (debugStr && (strlen(debugStr) == 1)) {
00096       messageLevel = 98;
00097       debugStr = nsnull;
00098     }
00099 
00100     int result = lterm_init(0);
00101     if (result == 0) {
00102       tlog_set_level(LTERM_TLOG_MODULE, messageLevel, debugStr);
00103     }
00104     mLoggingInitialized = PR_TRUE;
00105 
00106     char* logStr = (char*) PR_GetEnv("LTERM_LOG");
00107     if (logStr && *logStr) {
00108       // Enable LineTerm logging
00109       mozLineTerm::mLoggingEnabled = PR_TRUE;
00110     }
00111   }
00112 
00113   return mozLineTermConstructor( aOuter,
00114                                  aIID,
00115                                  aResult );
00116 }
00117 
00118 mozLineTerm::mozLineTerm() :
00119   mCursorRow(0),
00120   mCursorColumn(0),
00121   mSuspended(PR_FALSE),
00122   mEchoFlag(PR_TRUE),
00123   mObserver(nsnull),
00124   mCookie(EmptyString()),
00125   mLastTime(LL_ZERO)
00126 {
00127   mLTerm = lterm_new();
00128 }
00129 
00130 
00131 mozLineTerm::~mozLineTerm()
00132 {
00133   lterm_delete(mLTerm);
00134   mObserver = nsnull;
00135 }
00136 
00137 
00140 NS_IMETHODIMP mozLineTerm::ArePrefsSecure(PRBool *_retval)
00141 {
00142   nsresult result;
00143 
00144   XMLT_LOG(mozLineTerm::ArePrefsSecure,30,("\n"));
00145 
00146   if (!_retval)
00147     return NS_ERROR_FAILURE;
00148 
00149   *_retval = PR_FALSE;
00150 
00151   nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID);
00152   if (!prefBranch)
00153     return NS_ERROR_FAILURE;
00154 
00155   // Check if Components JS object is secure
00156   PRBool checkXPC;
00157   result = prefBranch->GetBoolPref("security.checkxpconnect", &checkXPC);
00158   if (NS_FAILED(result))
00159     return NS_ERROR_FAILURE;
00160 
00161   if (!checkXPC) {
00162     XMLT_ERROR("mozLineTerm::ArePrefsSecure: Error - Please add the line\n"
00163     "  pref(\"security.checkxpcconnect\",true);\n"
00164     "to your preferences file (.mozilla/prefs.js)\n");
00165     *_retval = PR_FALSE;
00166 #if 0  // Temporarily comented out
00167     return NS_OK;
00168 #endif
00169   }
00170 
00171   nsCAutoString secString ("security.policy.");
00172   /* Get global policy name. */
00173   nsXPIDLCString policyStr;
00174 
00175   result = prefBranch->GetCharPref("javascript.security_policy",
00176                                    getter_Copies(policyStr));
00177   if (NS_SUCCEEDED(result) && !policyStr.IsEmpty()) {
00178     secString.Append(policyStr);
00179   } else {
00180     secString.Append("default");
00181   }
00182 
00183   secString.Append(".htmldocument.cookie");
00184 
00185   XMLT_LOG(mozLineTerm::ArePrefsSecure,32, ("prefStr=%s\n", secString.get()));
00186 
00187   nsXPIDLCString secLevelString;
00188   result = prefBranch->GetCharPref(secString.get(), getter_Copies(secLevelString));
00189 
00190   if (NS_FAILED(result))
00191     return NS_ERROR_FAILURE;
00192 
00193   XMLT_LOG(mozLineTerm::ArePrefsSecure,32,
00194            ("secLevelString=%s\n", secLevelString.get()));
00195 
00196   *_retval = secLevelString.EqualsLiteral("sameOrigin");
00197 
00198   if (!(*_retval)) {
00199     XMLT_ERROR("mozLineTerm::ArePrefsSecure: Error - Please add the line\n"
00200     "  pref(\"security.policy.default.htmldocument.cookie\",\"sameOrigin\");\n"
00201     "to your preferences file (.mozilla/prefs.js)\n");
00202   }
00203 
00204   return NS_OK;
00205 }
00206 
00207 
00212 NS_IMETHODIMP mozLineTerm::GetSecurePrincipal(nsIDOMDocument *domDoc,
00213                                               char** aPrincipalStr)
00214 {
00215   XMLT_LOG(mozLineTerm::GetSecurePrincipal,30,("\n"));
00216 
00217   if (!aPrincipalStr)
00218     return NS_ERROR_FAILURE;
00219 
00220   *aPrincipalStr = nsnull;
00221 
00222   // Get principal string
00223   nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
00224   if (!doc)
00225     return NS_ERROR_FAILURE;
00226 
00227   nsIPrincipal *principal = doc->GetPrincipal();
00228   if (!principal) 
00229     return NS_ERROR_FAILURE;
00230 
00231 #if 0  // Temporarily commented out, because |ToString()| is not implemented.
00232   if (NS_FAILED(principal->ToString(aPrincipalStr)) || !*aPrincipalStr)
00233     return NS_ERROR_FAILURE;
00234 #else
00235   const char temStr[] = "unknown";
00236   PRInt32 temLen = strlen(temStr);
00237   *aPrincipalStr = strncpy((char*) nsMemory::Alloc(temLen+1),
00238                            temStr, temLen+1);
00239 #endif
00240 
00241   XMLT_LOG(mozLineTerm::GetSecurePrincipal,32,("aPrincipalStr=%s\n",
00242                                                *aPrincipalStr));
00243 
00244   // Check if principal is secure
00245   PRBool insecure = PR_FALSE;
00246   if (insecure) {
00247     // Return null string
00248     XMLT_ERROR("mozLineTerm::GetSecurePrincipal: Error - "
00249                "Insecure document principal %s\n", *aPrincipalStr);
00250     nsMemory::Free(*aPrincipalStr);
00251     *aPrincipalStr = (char*) nsMemory::Alloc(1);
00252     **aPrincipalStr = '\0';
00253   }
00254 
00255   return NS_OK;
00256 }
00257 
00258 
00261 NS_IMETHODIMP mozLineTerm::Open(const PRUnichar *command,
00262                                 const PRUnichar *initInput,
00263                                 const PRUnichar *promptRegexp,
00264                                 PRInt32 options, PRInt32 processType,
00265                                 nsIDOMDocument *domDoc)
00266 {
00267   if (mSuspended) {
00268     XMLT_ERROR("mozLineTerm::Open: Error - LineTerm %d is suspended\n",
00269                mLTerm);
00270     return NS_ERROR_FAILURE;
00271   }
00272 
00273   nsAutoString aCookie;
00274   return OpenAux(command, initInput, promptRegexp,
00275                  options, processType,
00276                  24, 80, 0, 0,
00277                  domDoc, nsnull, aCookie);
00278 }
00279 
00280 
00283 NS_IMETHODIMP mozLineTerm::OpenAux(const PRUnichar *command,
00284                                    const PRUnichar *initInput,
00285                                    const PRUnichar *promptRegexp,
00286                                    PRInt32 options, PRInt32 processType,
00287                                    PRInt32 nRows, PRInt32 nCols,
00288                                    PRInt32 xPixels, PRInt32 yPixels,
00289                                    nsIDOMDocument *domDoc,
00290                                    nsIObserver* anObserver,
00291                                    nsString& aCookie)
00292 {
00293   nsresult result;
00294 
00295   XMLT_LOG(mozLineTerm::Open,20,("\n"));
00296 
00297   // Ensure that preferences are secure for LineTerm creation and use
00298   PRBool arePrefsSecure;
00299   result = ArePrefsSecure(&arePrefsSecure);
00300 #if 0  // Temporarily comented out
00301   if (NS_FAILED(result) || !arePrefsSecure)
00302     return NS_ERROR_FAILURE;
00303 #endif
00304 
00305   // Ensure that document principal is secure for LineTerm creation
00306   char* securePrincipal;
00307   result = GetSecurePrincipal(domDoc, &securePrincipal);
00308   if (NS_FAILED(result))
00309     return NS_ERROR_FAILURE;
00310 
00311   if (!*securePrincipal) {
00312     nsMemory::Free(securePrincipal);
00313     XMLT_ERROR("mozLineTerm::OpenAux: Error - "
00314                "Failed to create LineTerm for insecure document principal\n");
00315     return NS_ERROR_FAILURE;
00316   }
00317 
00318   nsCOMPtr<nsIDOMHTMLDocument> domHTMLDoc = do_QueryInterface(domDoc);
00319   if (!domHTMLDoc)
00320       return NS_ERROR_FAILURE;
00321 
00322   // Ensure that cookie attribute of document is defined
00323   NS_NAMED_LITERAL_STRING(cookiePrefix, "xmlterm=");
00324   nsAutoString cookieStr;
00325   result = domHTMLDoc->GetCookie(cookieStr);
00326 
00327   if (NS_SUCCEEDED(result) &&
00328       (cookieStr.Length() > cookiePrefix.Length()) &&
00329       StringBeginsWith(cookieStr, cookiePrefix)) {
00330     // Cookie value already defined for document; simply copy it
00331     mCookie = cookieStr;
00332 
00333   } else {
00334     // Create random session cookie
00335     nsAutoString cookieValue;
00336     result = mozXMLTermUtils::RandomCookie(cookieValue);
00337     if (NS_FAILED(result))
00338       return result;
00339 
00340     mCookie = cookiePrefix;
00341     mCookie += cookieValue;
00342 
00343     // Set new cookie value
00344     result = domHTMLDoc->SetCookie(mCookie);
00345     if (NS_FAILED(result))
00346       return result;
00347   }
00348 
00349   // Return copy of cookie to caller
00350   aCookie = mCookie;
00351 
00352   mObserver = anObserver;  // non-owning reference
00353 
00354   // Convert cookie to CString
00355   char* cookieCStr = ToNewCString(mCookie);
00356   XMLT_LOG(mozLineTerm::Open,22, ("mCookie=%s\n", cookieCStr));
00357 
00358   // Convert initInput to CString
00359   NS_LossyConvertUTF16toASCII initCStr(initInput); // XXX ASCII?
00360   XMLT_LOG(mozLineTerm::Open,22, ("initInput=%s\n", initCStr.get()));
00361 
00362   // List of prompt delimiters
00363   static const PRInt32 PROMPT_DELIMS = 5;
00364   UNICHAR prompt_regexp[PROMPT_DELIMS+1];
00365   ucscopy(prompt_regexp, "#$%>?", PROMPT_DELIMS+1);
00366   PR_ASSERT(ucslen(prompt_regexp) == PROMPT_DELIMS);
00367 
00368   if (anObserver != nsnull) {
00369     result = lterm_open(mLTerm, NULL, cookieCStr, initCStr.get(),
00370                         prompt_regexp, options, processType,
00371                         nRows, nCols, xPixels, yPixels,
00372                         mozLineTerm::Callback, (void *) this);
00373   } else {
00374     result = lterm_open(mLTerm, NULL, cookieCStr, initCStr.get(),
00375                         prompt_regexp, options, processType,
00376                         nRows, nCols, xPixels, yPixels,
00377                         NULL, NULL);
00378   }
00379 
00380   // Free cookie CString
00381   nsMemory::Free(cookieCStr);
00382 
00383   if (mLoggingEnabled) {
00384     // Log time stamp for LineTerm open operation
00385     nsAutoString timeStamp;
00386     result = mozXMLTermUtils::TimeStamp(0, mLastTime, timeStamp);
00387     if (NS_SUCCEEDED(result)) {
00388       char* temStr = ToNewCString(timeStamp);
00389       PR_LogPrint("<TS %s> LineTerm %d opened by principal %s\n",
00390                   temStr, mLTerm, securePrincipal);
00391       nsMemory::Free(temStr);
00392     }
00393   }
00394 
00395   if (result == 0) {
00396     return NS_OK;
00397   } else {
00398     return NS_ERROR_FAILURE;
00399   }
00400 }
00401 
00402 
00405 void mozLineTerm::Callback(gpointer data,
00406                            gint source,
00407                            GdkInputCondition condition)
00408 {
00409   mozLineTerm* lineTerm = (mozLineTerm*) data;
00410 
00411   //XMLT_LOG(mozLineTerm::Callback,50,("\n"));
00412 
00413   PR_ASSERT(lineTerm != nsnull);
00414   PR_ASSERT(lineTerm->mObserver != nsnull);
00415 
00416   lineTerm->mObserver->Observe((nsISupports*) lineTerm, nsnull, nsnull);
00417   return;
00418 }
00419 
00422 NS_IMETHODIMP mozLineTerm::SuspendAux(PRBool aSuspend)
00423 {
00424   mSuspended = aSuspend;
00425   return NS_OK;
00426 }
00427 
00428 
00431 NS_IMETHODIMP mozLineTerm::Close(const PRUnichar* aCookie)
00432 {
00433   XMLT_LOG(mozLineTerm::Close,20, ("\n"));
00434 
00435   if (!mCookie.Equals(aCookie)) {
00436     XMLT_ERROR("mozLineTerm::Close: Error - Cookie mismatch\n");
00437     return NS_ERROR_FAILURE;
00438   }
00439 
00440   if (mSuspended) {
00441     XMLT_ERROR("mozLineTerm::Close: Error - LineTerm %d is suspended\n",
00442                mLTerm);
00443     return NS_ERROR_FAILURE;
00444   }
00445 
00446   if (lterm_close(mLTerm) == 0) {
00447     return NS_OK;
00448   } else {
00449     return NS_ERROR_FAILURE;
00450   }
00451 
00452   mObserver = nsnull;
00453 }
00454 
00455 
00458 NS_IMETHODIMP mozLineTerm::CloseAux(void)
00459 {
00460   XMLT_LOG(mozLineTerm::CloseAux,20, ("\n"));
00461 
00462   if (lterm_close(mLTerm) == 0) {
00463     return NS_OK;
00464   } else {
00465     return NS_ERROR_FAILURE;
00466   }
00467 
00468   mObserver = nsnull;
00469 }
00470 
00471 
00474 NS_IMETHODIMP mozLineTerm::CloseAllAux(void)
00475 {
00476   lterm_close_all();
00477   return NS_OK;
00478 }
00479 
00480 
00485 NS_IMETHODIMP mozLineTerm::ResizeAux(PRInt32 nRows, PRInt32 nCols)
00486 {
00487   int retCode;
00488 
00489   XMLT_LOG(mozLineTerm::ResizeAux,30,("nRows=%d, nCols=%d\n", nRows, nCols));
00490 
00491   // Resize LTERM
00492   retCode = lterm_resize(mLTerm, (int) nRows, (int) nCols);
00493   if (retCode < 0)
00494     return NS_ERROR_FAILURE;
00495 
00496   return NS_OK;
00497 }
00498 
00499 
00502 NS_IMETHODIMP mozLineTerm::Write(const PRUnichar *buf,
00503                                  const PRUnichar* aCookie)
00504 {
00505   if (!mCookie.Equals(aCookie)) {
00506     XMLT_ERROR("mozLineTerm::Write: Error - Cookie mismatch\n");
00507     return NS_ERROR_FAILURE;
00508   }
00509 
00510   if (mSuspended) {
00511     XMLT_ERROR("mozLineTerm::Write: Error - LineTerm %d is suspended\n",
00512                mLTerm);
00513     return NS_ERROR_FAILURE;
00514   }
00515 
00516   XMLT_LOG(mozLineTerm::Write,30,("\n"));
00517 
00518   nsresult result;
00519   UNICHAR ubuf[MAXCOL];
00520   int jLen, retCode;
00521   PRBool newline = PR_FALSE;
00522 
00523   jLen = 0;
00524   while ((jLen < MAXCOL-1) && (buf[jLen] != 0)) {
00525     if (buf[jLen] == U_LINEFEED)
00526       newline = PR_TRUE;
00527 
00528     ubuf[jLen] = (UNICHAR) buf[jLen];
00529 
00530     if (ubuf[jLen] == U_PRIVATE0) {
00531       // Hack to handle input of NUL characters in NUL-terminated strings
00532       // See also: mozXMLTermKeyListener::KeyPress
00533       ubuf[jLen] = U_NUL;
00534     }
00535 
00536     jLen++;
00537   }
00538 
00539   if (jLen >= MAXCOL-1) {
00540     XMLT_ERROR("mozLineTerm::Write: Error - Buffer overflow\n");
00541     return NS_ERROR_FAILURE;
00542   }
00543 
00544   if (mLoggingEnabled && (jLen > 0)) {
00545     /* Log all input to STDERR */
00546     ucsprint(stderr, ubuf, jLen);
00547 
00548     nsAutoString timeStamp;
00549     result = mozXMLTermUtils::TimeStamp(60, mLastTime, timeStamp);
00550 
00551     if (NS_SUCCEEDED(result) && !timeStamp.IsEmpty()) {
00552       char* temStr = ToNewCString(timeStamp);
00553       PR_LogPrint("<TS %s>\n", temStr);
00554       nsMemory::Free(temStr);
00555 
00556     } else if (newline) {
00557       PR_LogPrint("\n");
00558     }
00559   }
00560 
00561   retCode = lterm_write(mLTerm, ubuf, jLen, LTERM_WRITE_PLAIN_INPUT);
00562   if (retCode < 0)
00563     return NS_ERROR_FAILURE;
00564 
00565   return NS_OK;
00566 }
00567 
00568 
00569 NS_IMETHODIMP mozLineTerm::Read(PRInt32 *opcodes, PRInt32 *opvals,
00570                                 PRInt32 *buf_row, PRInt32 *buf_col,
00571                                 const PRUnichar* aCookie,
00572                                 PRUnichar **_retval)
00573 {
00574   if (!mCookie.Equals(aCookie)) {
00575     XMLT_ERROR("mozLineTerm::Read: Error - Cookie mismatch\n");
00576     return NS_ERROR_FAILURE;
00577   }
00578 
00579   if (mSuspended) {
00580     XMLT_ERROR("mozLineTerm::Read: Error - LineTerm %d is suspended\n",
00581                mLTerm);
00582     return NS_ERROR_FAILURE;
00583   }
00584 
00585   return ReadAux(opcodes, opvals, buf_row, buf_col, _retval, nsnull);
00586 }
00587 
00588 
00591 NS_IMETHODIMP mozLineTerm::ReadAux(PRInt32 *opcodes, PRInt32 *opvals,
00592                                    PRInt32 *buf_row, PRInt32 *buf_col,
00593                                    PRUnichar **_retval, PRUnichar **retstyle)
00594 {
00595   UNICHAR ubuf[MAXCOL];
00596   UNISTYLE ustyle[MAXCOL];
00597   int cursor_row, cursor_col;
00598   int retCode, j;
00599 
00600   XMLT_LOG(mozLineTerm::ReadAux,30,("\n"));
00601 
00602   if (!_retval)
00603     return NS_ERROR_NULL_POINTER;
00604 
00605   retCode = lterm_read(mLTerm, 0, ubuf, MAXCOL-1,
00606                        ustyle, opcodes, opvals,
00607                        buf_row, buf_col, &cursor_row, &cursor_col);
00608   if (retCode < 0)
00609     return NS_ERROR_FAILURE;
00610 
00611   if (*opcodes == 0) {
00612     // Return null pointer(s)
00613     *_retval = nsnull;
00614 
00615     if (retstyle)
00616       *retstyle = nsnull;
00617 
00618   } else {
00619     // Return output string
00620     mCursorRow = cursor_row;
00621     mCursorColumn = cursor_col;
00622 
00623     XMLT_LOG(mozLineTerm::ReadAux,72,("cursor_col=%d\n", cursor_col));
00624 
00625     int allocBytes = sizeof(PRUnichar)*(retCode + 1);
00626     *_retval = (PRUnichar*) nsMemory::Alloc(allocBytes);
00627 
00628     for (j=0; j<retCode; j++)
00629       (*_retval)[j] = (PRUnichar) ubuf[j];
00630 
00631     // Insert null string terminator
00632     (*_retval)[retCode] = 0;
00633 
00634     if (retstyle != nsnull) {
00635       // Return style array as well
00636       *retstyle = (PRUnichar*) nsMemory::Alloc(allocBytes);
00637 
00638       for (j=0; j<retCode; j++)
00639         (*retstyle)[j] = (PRUnichar) ustyle[j];
00640 
00641       // Insert null string terminator
00642       (*retstyle)[retCode] = 0;
00643     }
00644   }
00645 
00646   return NS_OK;
00647 }
00648 
00649 
00650 NS_IMETHODIMP mozLineTerm::GetCookie(nsString& aCookie)
00651 {
00652   aCookie = mCookie;
00653   return NS_OK;
00654 }
00655 
00656 
00657 NS_IMETHODIMP mozLineTerm::GetCursorRow(PRInt32 *aCursorRow)
00658 {
00659   *aCursorRow = mCursorRow;
00660   return NS_OK;
00661 }
00662 
00663 
00664 NS_IMETHODIMP mozLineTerm::SetCursorRow(PRInt32 aCursorRow)
00665 {
00666   int retCode;
00667 
00668   if (mSuspended) {
00669     XMLT_ERROR("mozLineTerm::SetCursorRow: Error - LineTerm %d is suspended\n",
00670                mLTerm);
00671     return NS_ERROR_FAILURE;
00672   }
00673 
00674   retCode = lterm_setcursor(mLTerm, aCursorRow, mCursorColumn);
00675   if (retCode < 0)
00676     return NS_ERROR_FAILURE;
00677 
00678   return NS_OK;
00679 }
00680 
00681 
00682 NS_IMETHODIMP mozLineTerm::GetCursorColumn(PRInt32 *aCursorColumn)
00683 {
00684   *aCursorColumn = mCursorColumn;
00685   return NS_OK;
00686 }
00687 
00688 
00689 NS_IMETHODIMP mozLineTerm::SetCursorColumn(PRInt32 aCursorColumn)
00690 {
00691   int retCode;
00692 
00693   if (mSuspended) {
00694     XMLT_ERROR("mozLineTerm::SetCursorColumn: Error - LineTerm %d is suspended\n",
00695                mLTerm);
00696     return NS_ERROR_FAILURE;
00697   }
00698 
00699   retCode = lterm_setcursor(mLTerm, mCursorRow, aCursorColumn);
00700   if (retCode < 0)
00701     return NS_ERROR_FAILURE;
00702 
00703   return NS_OK;
00704 }
00705 
00706 
00707 NS_IMETHODIMP mozLineTerm::GetEchoFlag(PRBool *aEchoFlag)
00708 {
00709   *aEchoFlag = mEchoFlag;
00710   return NS_OK;
00711 }
00712 
00713 
00714 NS_IMETHODIMP mozLineTerm::SetEchoFlag(PRBool aEchoFlag)
00715 {
00716   int result;
00717 
00718   if (mSuspended) {
00719     XMLT_ERROR("mozLineTerm::SetEchoFlag: Error - LineTerm %d is suspended\n",
00720                mLTerm);
00721     return NS_ERROR_FAILURE;
00722   }
00723 
00724   XMLT_LOG(mozLineTerm::SetEchoFlag,70,("aEchoFlag=0x%x\n", aEchoFlag));
00725 
00726   if (aEchoFlag) {
00727     result = lterm_setecho(mLTerm, 1);
00728   } else {
00729     result = lterm_setecho(mLTerm, 0);
00730   }
00731 
00732   if (result != 0)
00733     return NS_ERROR_FAILURE;
00734 
00735   mEchoFlag = aEchoFlag;
00736   return NS_OK;
00737 }