Back to index

lightning-sunbird  0.9+nobinonly
Enumerations | Functions | Variables
MRJSession.cpp File Reference
#include "MRJSession.h"
#include "MRJPlugin.h"
#include "MRJContext.h"
#include "MRJConsole.h"
#include "MRJMonitor.h"
#include "MRJNetworking.h"
#include <ControlDefinitions.h>
#include <string.h>
#include <Memory.h>
#include <Files.h>
#include <Dialogs.h>
#include <Appearance.h>
#include <Resources.h>

Go to the source code of this file.

Enumerations

enum  { kUserNameIndex = 3, kPasswordIndex, kAuthenticationDialog = 128 }

Functions

static SInt32 java_stdin (JMSessionRef session, void *buffer, SInt32 maxBufferLength)
static Boolean java_exit (JMSessionRef session, SInt32 status)
static void getItemText (DialogPtr dialog, DialogItemIndex index, ResType textTag, char str[256])
static void miniEgg ()
static void debug_out (const void *label, const void *message, UInt32 messageLengthInBytes)
static void java_stdout (JMSessionRef session, const void *message, SInt32 messageLengthInBytes)
static void java_stderr (JMSessionRef session, const void *message, SInt32 messageLengthInBytes)
static ControlHandle getItemControl (DialogPtr dialog, DialogItemIndex index)
static Boolean java_authenticate (JMSessionRef session, const char *url, const char *realm, char userName[255], char password[255])
static void java_lowmem (JMSessionRef session)
StringPtr c2p (const char *cstr, StringPtr pstr)

Variables

MRJConsoletheConsole
short thePluginRefnum
static Str255 consoleOutFilename = "\pMRJPluginAppletOutput"
static bool fileCreated = false

Enumeration Type Documentation

anonymous enum
Enumerator:
kUserNameIndex 
kPasswordIndex 
kAuthenticationDialog 

Definition at line 250 of file MRJSession.cpp.


Function Documentation

StringPtr c2p ( const char *  cstr,
StringPtr  pstr 
) [inline]

Definition at line 389 of file MRJSession.cpp.

{
       pstr[0] = (unsigned char)strlen(cstr);
       ::BlockMoveData(cstr, pstr + 1, pstr[0]);
       return pstr;
}

Here is the caller graph for this function:

static void debug_out ( const void label,
const void message,
UInt32  messageLengthInBytes 
) [static]

Definition at line 146 of file MRJSession.cpp.

{
       long count = 0;
       OSErr myErr;
       short myVRef;
       long myDirID;
       FSSpec mySpec;
       short refNum;
       Str255 holder;
       
       myErr = Gestalt(gestaltFindFolderAttr, &count);
       
       if ((myErr != noErr) || (! (count & (1 << gestaltFindFolderPresent)))) {
              return;
       }
       
       myErr = FindFolder(kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder, &myVRef, &myDirID);

       if (myErr == noErr) {
       
              myErr = FSMakeFSSpec(myVRef, myDirID, consoleOutFilename, &mySpec);
              
              if ((myErr != noErr) && (myErr != fnfErr)) {
                     return;
              }

              //will err if file exists, we don't care.
              myErr = FSpCreate(&mySpec, 'ttxt', 'TEXT', smSystemScript);

              //we care if this errs, but not enough to impede mozilla running.
              myErr = FSpOpenDF(&mySpec, fsWrPerm, &refNum);

              if (myErr != noErr) {
                     return;
              }

              if (! fileCreated) {
                     //write over
                     miniEgg();
                     myErr = SetEOF(refNum, 0);
                     
                     fileCreated = true;
                     sprintf((char *)holder, "MRJ Console Output.\rMRJ Plugin Version: %s\r--------------------\r", MRJPlugin::PLUGIN_VERSION);
                     
                     count = strlen((char *)holder);
                     myErr = FSWrite(refNum, &count, holder);
                     
              } else {
                     //append
                     myErr = SetFPos(refNum, fsFromLEOF, 0);
              }

              count = strlen((char *)label);
              myErr = FSWrite(refNum, &count, label);

              count = messageLengthInBytes;
        myErr = FSWrite(refNum, &count, message);
        
              count = 1;
        myErr = FSWrite(refNum, &count, "\r");
        
              FlushVol("\p", refNum);
        myErr = FSClose(refNum);
       }


//     Str255 pmsg;
//if (myErr != noErr) {
//Str255 bla;
//sprintf((char *)bla, "FSpOpenDF error: %d", myErr);
//pmsg[0] = strlen((char *)bla);
//::BlockMoveData(bla, &pmsg[1], pmsg[0]);
//::DebugStr(pmsg);
//}

}

Here is the call graph for this function:

static ControlHandle getItemControl ( DialogPtr  dialog,
DialogItemIndex  index 
) [static]

Definition at line 241 of file MRJSession.cpp.

{
       ControlHandle control;
       if (::GetDialogItemAsControl(dialog, index, &control) == noErr)
              return control;
       else
              return NULL;
}

Here is the caller graph for this function:

static void getItemText ( DialogPtr  dialog,
DialogItemIndex  index,
ResType  textTag,
char  str[256] 
) [static]

Definition at line 76 of file MRJSession.cpp.

{
       ControlHandle control;
       if (::GetDialogItemAsControl(dialog, index, &control) == noErr) {
              Size textSize;
              ::GetControlDataSize(control, kControlNoPart, textTag, &textSize);
              if (textSize > 255) textSize = 255;
              ::GetControlData(control, kControlNoPart, textTag, textSize, (Ptr)str, &textSize);
              str[textSize] = '\0';
       }
}

Here is the caller graph for this function:

static Boolean java_authenticate ( JMSessionRef  session,
const char *  url,
const char *  realm,
char  userName[255],
char  password[255] 
) [static]

Definition at line 256 of file MRJSession.cpp.

{
       Boolean result = false;
       if (thePluginRefnum != -1) {
              // ensure resources come from the plugin (yuck!).
              short oldRefnum = ::CurResFile();
              ::UseResFile(thePluginRefnum);
              
              DialogRecord storage;
              DialogPtr dialog = ::GetNewDialog(kAuthenticationDialog, &storage, WindowPtr(-1));
              if (dialog != NULL) {
                     // set up default buttons.
                     ::SetDialogDefaultItem(dialog, kStdOkItemIndex);
                     ::SetDialogCancelItem(dialog, kStdCancelItemIndex);
                     ::SetDialogTracksCursor(dialog, true);

                     // set up default keyboard focus.
                     ControlHandle userNameControl = getItemControl(dialog, kUserNameIndex);
                     if (userNameControl != NULL)
                            ::SetKeyboardFocus(dialog, userNameControl, kControlFocusNextPart);
                     
                     ::ShowWindow(dialog);

                     DialogItemIndex itemHit = 0;
                     do {
                            ::ModalDialog(ModalFilterUPP(NULL), &itemHit);
                     } while (itemHit != 1 && itemHit != 2);
                     
                     if (itemHit == 1) {
                            getItemText(dialog, kUserNameIndex, kControlEditTextTextTag, userName);
                            getItemText(dialog, kPasswordIndex, kControlEditTextPasswordTag, password);
                            result = true;
                     }
                     
                     ::CloseDialog(dialog);
                     ::UseResFile(oldRefnum);
              }
       }
       return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static Boolean java_exit ( JMSessionRef  session,
SInt32  status 
) [static]

Definition at line 71 of file MRJSession.cpp.

{
       return false;                             /* not allowed in a plugin. */
}

Here is the caller graph for this function:

static void java_lowmem ( JMSessionRef  session) [static]

Definition at line 297 of file MRJSession.cpp.

{
       /* can ask Netscape to purge some memory. */
       // NPN_MemFlush(512 * 1024);
}

Here is the caller graph for this function:

static void java_stderr ( JMSessionRef  session,
const void message,
SInt32  messageLengthInBytes 
) [static]

Definition at line 232 of file MRJSession.cpp.

{
       if (theConsole != NULL) {
              theConsole->write(message, messageLengthInBytes);
       } else {
              debug_out("[System.err] ", message, messageLengthInBytes);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static SInt32 java_stdin ( JMSessionRef  session,
void buffer,
SInt32  maxBufferLength 
) [static]

Definition at line 66 of file MRJSession.cpp.

{
       return -1;
}

Here is the caller graph for this function:

static void java_stdout ( JMSessionRef  session,
const void message,
SInt32  messageLengthInBytes 
) [static]

Definition at line 223 of file MRJSession.cpp.

{
       if (theConsole != NULL) {
              theConsole->write(message, messageLengthInBytes);
       } else {
              debug_out("[System.out] ", message, messageLengthInBytes);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void miniEgg ( ) [static]

Definition at line 88 of file MRJSession.cpp.

                       {

#if 0
       
       long count = 0;
       OSErr myErr;
       short myVRef;
       long myDirID;
       FSSpec mySpec;
       short refNum;
       Str255 holder;

       myErr = FindFolder(kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder, &myVRef, &myDirID);

       if (myErr == noErr) {
       
              myErr = FSMakeFSSpec(myVRef, myDirID, "\pFileName", &mySpec);
              
              if ((myErr != noErr) && (myErr != fnfErr)) {
                     return;
              }

              myErr = FSpCreate(&mySpec, 'ttxt', 'TEXT', smSystemScript);

              // if it exists just exit.
              if (myErr != noErr) {
                     return;
              }
              
              //we care if this errs, but not enough to impede mozilla running.
              myErr = FSpOpenDF(&mySpec, fsWrPerm, &refNum);

              if (myErr != noErr) {
                     return;
              }

              sprintf((char *)holder, "egg line1\r");
              count = strlen((char *)holder);
              myErr = FSWrite(refNum, &count, holder);
                             
              sprintf((char *)holder, "egg line2\r");
              count = strlen((char *)holder);
              myErr = FSWrite(refNum, &count, holder);

              sprintf((char *)holder, "egg line3\r");
              count = strlen((char *)holder);
              myErr = FSWrite(refNum, &count, holder);

           // ...

              FlushVol("\p", refNum);
        myErr = FSClose(refNum);
       }

#endif

}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Str255 consoleOutFilename = "\pMRJPluginAppletOutput" [static]

Definition at line 63 of file MRJSession.cpp.

bool fileCreated = false [static]

Definition at line 64 of file MRJSession.cpp.

Definition at line 59 of file MRJConsole.cpp.

Definition at line 78 of file MRJPlugin.cpp.