Ejemplo n.º 1
0
//--------------------------------------
int CPROC CMD_GETPARTIAL( PSENTIENT ps, PTEXT parameters )
{
	if( ps->Data )
	{
		PTEXT pSave, temp;
		pSave = parameters;
		if( ( temp = GetParam( ps, &parameters ) ) )
		{
			if( temp == pSave )
			{
				DECLTEXT( msg, WIDE("Parameter to GetPartial was not a variable reference.") );
				EnqueLink( &ps->Command->Output, &msg );
				return FALSE;
			}

			if( GetIndirect( temp ) )
			{
				LineRelease( GetIndirect( temp ) );
				SetIndirect( temp, NULL );
			}

			if( ps->Data->Partial )
			{
				SetIndirect( temp, ps->Data->Partial );
				ps->Data->Partial = NULL;
				if( ps->CurrentMacro )
					ps->CurrentMacro->state.flags.bSuccess = TRUE;
			}
		}
	}
	 return FALSE;
}
Ejemplo n.º 2
0
int KeystrokePaste( PCONSOLE_INFO pdp )
{
    if( OpenClipboard(NULL) )
    {
        uint32_t format;
        // successful open...
        format = EnumClipboardFormats( 0 );
        while( format )
        {
            //DECLTEXT( msg, "                                     " );
            //msg.data.size = sprintf( msg.data.data, "Format: %d", format );
            //EnqueLink( pdp->ps->Command->ppOutput, SegDuplicate( (PTEXT)&msg ) );
#ifndef CF_TEXT
#define CF_TEXT 1
#endif
            if( format == CF_TEXT )
            {
                HANDLE hData = GetClipboardData( CF_TEXT );
                LPVOID pData = GlobalLock( hData );
                PTEXT pStroke = SegCreateFromText( pData );
                int ofs, n;
                GlobalUnlock( hData );
                n = ofs = 0;
                while( pStroke->data.data[n] )
                {
                    pStroke->data.data[ofs] = pStroke->data.data[n];
                    if( pStroke->data.data[n] == '\r' ) // trash extra returns... keep newlines
                    {
                        n++;
                        continue;
                    }
                    else
                    {
                        ofs++;
                        n++;
                    }
                }
                pStroke->data.size = ofs;
                pStroke->data.data[ofs] = pStroke->data.data[n];
                if( PSI_DoStroke( pdp, pStroke ) ) 1;
                //   RenderCommandLine( pdp );
                //EnqueLink( pdp->ps->Command->ppOutput, SegDuplicate(pStroke) );
                LineRelease( pStroke );
                break;
            }
            format = EnumClipboardFormats( format );
        }
        CloseClipboard();
    }
    else
    {
#ifdef __DEKWARE__PLUGIN__
        DECLTEXT( msg, "Clipboard was not available" );
        EnqueLink( &pdp->common.Owner->Command->Output, &msg );
#endif
    }
    return 0;

}
Ejemplo n.º 3
0
//--------------------------------------
int CPROC PARSE( PSENTIENT ps, PTEXT parameters )
{
	PTEXT temp;
	PTEXT devname;
	if( ( devname = GetParam( ps, &parameters ) ) )
	{
	// find device to see if it's already open...
	// by name!
	// but - this causes a problem for nested scripts
	// which are going to have to be artificiailly inceminated
	// with a unique name maybe something like script_#####
		PDATAPATH pdp = FindOpenDevice( ps, devname );
		if( pdp )
		{
			if( !ps->CurrentMacro )
			{
				PVARTEXT pvt;
				pvt = VarTextCreate();
				vtprintf( pvt, WIDE("Device named %s is already open."), GetText( devname ) );
				EnqueLink( &ps->Command->Output, (POINTER)VarTextGet( pvt ) );
				VarTextDestroy( &pvt );
			}
			return -1;
		}
		if( ( temp = GetParam( ps, &parameters ) ) )
		{
			PDATAPATH pdp;
			lprintf( WIDE("Opening device handle named: %s"), GetText( devname ) );
			if( ( pdp = OpenDevice( &ps->Data, ps, temp, parameters ) ) )
			{
				while( devname->flags & TF_INDIRECT )
					devname = GetIndirect( devname );
				pdp->pName = SegDuplicate( devname );
				if( pdp->Type )
				{
					if( ps->CurrentMacro )
					{
						ps->CurrentMacro->state.flags.bSuccess = TRUE;
					}
				}
				else
				{
					DestroyDataPath( pdp ); // new one did not finish open...
				}
			}
		}
		else
		{
			DECLTEXT( msg, WIDE("Parse must specify a name (/(parse/open) <name> <device> <options...)") );
			EnqueLink( &ps->Command->Output, (PTEXT)&msg );
		}
	}
	return FALSE;
}
Ejemplo n.º 4
0
int CPROC CHANGEDIR( PSENTIENT ps, PTEXT parameters )
{
   PTEXT pDir, pDir1;
   pDir1 = MacroDuplicateEx( ps, parameters, TRUE, TRUE );
   if( pDir1 )
      pDir = BuildLine( pDir1 );
   else
      return FALSE;
   LineRelease( pDir1 );
   if( SetCurrentPath( GetText( pDir ) ) )
   {
      if( ps->CurrentMacro )
         ps->CurrentMacro->state.flags.bSuccess = TRUE;
      else
      {
			DECLTEXT( msg, WIDE("Changed directory successfully.") );
			{
            TEXTCHAR buf[257];
				GetCurrentPath( buf, sizeof( buf ) );
				SetDefaultFilePath( buf );
			}
         EnqueLink( &ps->Command->Output, &msg );
      }
   }
   else
   {
      if( !ps->CurrentMacro )
      {
         DECLTEXT( msg, WIDE("Failed to change directory.") );
         EnqueLink( &ps->Command->Output, &msg );
      }
   }
   LineRelease( pDir );

   return FALSE;
}
Ejemplo n.º 5
0
void ReformatInput( PCHAT_LIST list )
{
		if( !list->input.phb_Input->pBlock )
		{
			list->input.phb_Input->pBlock = list->input.phb_Input->region->pHistory.root.next;
			list->input.phb_Input->pBlock->nLinesUsed = 1;
			list->input.phb_Input->pBlock->pLines[0].flags.deleted = 0;
			list->input.phb_Input->nLine = 1;
		}
		list->input.phb_Input->pBlock->pLines[0].pLine = list->input.CommandInfo->CollectionBuffer;
		SetStart( list->input.phb_Input->pBlock->pLines[0].pLine );
		{
			DECLTEXT( blank_eol, "" );
			list->input.phb_Input->pBlock->pLines[0].nLineLength = LineLengthExEx( list->input.phb_Input->pBlock->pLines[0].pLine, FALSE, 8, (PTEXT)&blank_eol );
		}
		//if( !pdp->flags.bDirect && pdp->flags.bWrapCommand )
		BuildDisplayInfoLines( list->input.phb_Input, list->input_font );
}
Ejemplo n.º 6
0
int Widget_DoStroke( PCHAT_LIST list, PTEXT stroke )
{
	INDEX i;
	int bOutput = FALSE;
	DECLTEXT( key, " " );
	//Log1( "Do Stroke with %c", stroke->data.data[0] );
	if( list->input.command_mark_start != list->input.command_mark_end )
	{
		int n;
		SetUserInputPosition( list->input.CommandInfo, list->input.command_mark_start, COMMAND_POS_SET );
		for( n = 0; n < ( list->input.command_mark_end - list->input.command_mark_start ); n++ )
			DeleteUserInput( list->input.CommandInfo );
		list->input.command_mark_start = list->input.command_mark_end = 0;
	}
	{
		PTEXT seg;
		size_t outchar;
		int had_cr = 0;
		seg = stroke;
		while( seg )
		{
			outchar = 0;
			for( i = 0; i < seg->data.size; i++ )
			{
				if( seg->data.data[i] == '\n' ) {
					if( !had_cr )
						seg->data.data[outchar++] = '\n'; // carriage return = linefeed
					else
						had_cr = FALSE;
				} else if( seg->data.data[i] == '\r' ) {
					had_cr = TRUE;
					seg->data.data[outchar++] = '\n'; // carriage return = linefeed
				}  else
					seg->data.data[outchar++] = seg->data.data[i]; // save any other character
			}
			if( outchar != i )
				seg->data.size = outchar;
			seg = NEXTLINE( seg );
		}
		GatherUserInput( list->input.CommandInfo
						, (PTEXT)stroke );
	}
	return TRUE;
}
Ejemplo n.º 7
0
int CPROC PRIORITY( PSENTIENT ps, PTEXT parameters )
{
	// Just a note : Thread priority does not work 
	// there are MANY MANY threads involved - so only
	// process priority applies...
#if defined( WIN32 ) || defined( _WIN32 )
	PTEXT pTemp;
   HANDLE hToken, hProcess;
   TOKEN_PRIVILEGES tp;
   OSVERSIONINFO osvi;
   DWORD dwPriority = 0xA5A5A5A5;

   osvi.dwOSVersionInfoSize = sizeof( osvi );
   GetVersionEx( &osvi );
   if( osvi.dwPlatformId  == VER_PLATFORM_WIN32_NT )
   {
      // allow shutdown priviledges....
      // wonder if /shutdown will work wihtout this?
      if( DuplicateHandle( GetCurrentProcess(), GetCurrentProcess()
                        , GetCurrentProcess(), &hProcess, 0
                        , FALSE, DUPLICATE_SAME_ACCESS  ) )
         if( OpenProcessToken( hProcess, TOKEN_ADJUST_PRIVILEGES, &hToken ) )
         {
            tp.PrivilegeCount = 1;
            if( LookupPrivilegeValue( NULL
                                    , SE_SHUTDOWN_NAME
                                    , &tp.Privileges[0].Luid ) )
            {
               tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
               AdjustTokenPrivileges( hToken, FALSE, &tp, 0, NULL, NULL );
            }
            else
               GetLastError();
         }
         else
            GetLastError();
      else
         GetLastError();
   }

	if( ps->CurrentMacro )
      ps->CurrentMacro->state.flags.bSuccess = TRUE;

	pTemp = GetParam( ps, &parameters );
	if( pTemp )
	{
		if( TextLike( pTemp, WIDE("idle") ) )
		{
	      dwPriority = IDLE_PRIORITY_CLASS;
		}
		else if( TextLike( pTemp, WIDE("normal") ) )
		{
	      dwPriority = NORMAL_PRIORITY_CLASS;
		}
		else if( TextLike( pTemp, WIDE("high") ) )
		{
	      dwPriority = HIGH_PRIORITY_CLASS;
		}
		else if( TextLike( pTemp, WIDE("realtime") ) )
		{
	      dwPriority = REALTIME_PRIORITY_CLASS;
		}
		else
		{
			if( !ps->CurrentMacro )
			{
				DECLTEXT( msg, WIDE("Invalid process priority (not idle, normal, high, or realtime)") );
				EnqueLink( &ps->Command->Output, &msg );
			}
			else
			{
		      ps->CurrentMacro->state.flags.bSuccess = FALSE;
			}
		}
	}
	else
	{
		if( !ps->CurrentMacro )
		{
			DECLTEXT( msg, WIDE("No process priority specified (idle,normal,high,realtime)") );
			EnqueLink( &ps->Command->Output, &msg );
		}
		else
		{
		   ps->CurrentMacro->state.flags.bSuccess = FALSE;
		}
	}

	if( dwPriority != 0xA5A5A5A5 )
		SetPriorityClass( GetCurrentProcess(), dwPriority );

	if( !b95 )
	{
		// NT type system we opened these handles
		CloseHandle( hProcess );
		CloseHandle( hToken );
	}
#endif
	return 0;
}
Ejemplo n.º 8
0
VOID KeyEventProc(PCONSOLE_INFO pdp, KEY_EVENT_RECORD event)
{
#ifdef USE_OLD_CODE
   // this must here gather keystrokes and pass them forward into the
   // opened sentience...
//   PTEXT temp;
	int bOutput = FALSE;
   lprintf( "Entering handle a key event..." );
	Lock( pdp );
   lprintf( "Got the lock, waiting for collection buffer..." );
   if( event.bKeyDown )
   {
      PTEXT key;
      // here is where we evaluate the curent keystroke....

      for( ; event.wRepeatCount; event.wRepeatCount-- )
      {
         int mod = KEYMOD_NORMAL;
         extern PSIKEYDEFINE KeyDefs[];
         if(event.dwControlKeyState& (RIGHT_CTRL_PRESSED|LEFT_CTRL_PRESSED))
            mod |= KEYMOD_CTRL;
         if(event.dwControlKeyState& (RIGHT_ALT_PRESSED|LEFT_ALT_PRESSED))
            mod |= KEYMOD_ALT;
         if( KeyDefs[event.wVirtualKeyCode].flags & KDF_CAPSKEY )
         {
            if( event.dwControlKeyState & CAPSLOCK_ON )
            {
               if( !(event.dwControlKeyState& SHIFT_PRESSED) )
                  mod |= KEYMOD_SHIFT;
            }
            else
            {
               if( event.dwControlKeyState& SHIFT_PRESSED )
                  mod |= KEYMOD_SHIFT;
            }
         }
         else
            if( event.dwControlKeyState& SHIFT_PRESSED )
               mod |= KEYMOD_SHIFT;
         if( pdp->Keyboard[event.wVirtualKeyCode][mod].flags.bStroke ||
             pdp->Keyboard[event.wVirtualKeyCode][mod].flags.bMacro )
         {
            if( pdp->Keyboard[event.wVirtualKeyCode][mod].flags.bStroke )
            {
               bOutput |= DoStroke(pdp, pdp->Keyboard[event.wVirtualKeyCode][mod].data.stroke);
            }
            else if( pdp->Keyboard[event.wVirtualKeyCode][mod].flags.bMacro )
            {
               if( pdp->common.Owner->pRecord != pdp->Keyboard[event.wVirtualKeyCode][mod].data.macro )
                  InvokeMacro( pdp->common.Owner
                             , pdp->Keyboard[event.wVirtualKeyCode][mod].data.macro
                             , NULL );
               // do macro!!!!!
            }
         }
         else
         {
				if( key = KeyDefs[event.wVirtualKeyCode].op[mod].data.pStroke )
				{
					if( KeyDefs[event.wVirtualKeyCode].op[mod].bFunction )
						bOutput |= ((KeyFunc)key)(pdp);
					else
					{
						bOutput |= DoStroke( pdp, key );
					}
				}
         }
      }
      // call to clear and re-write the current buffer....
      //if( bOutput ) // so we don't output on shift, control, etc...
         //RenderCommandLine( pdp );
   }
   else
   {
      // key up's don't matter like ever...
   }
	Unlock( pdp );
#else
   // this must here gather keystrokes and pass them forward into the
   // opened sentience...
//   PTEXT temp;
   int bOutput = FALSE;
   int mod = KEYMOD_NORMAL;
   if( !pdp ) // not a valid window handle/device path
        return;
   //Log( "Entering keyproc..." );
   EnterCriticalSec( &pdp->Lock );
   //while( LockedExchange( &pdp->common.CommandInfo->CollectionBufferLock, 1 ) )
   //   Sleep(0);
   Log1( "mod = %x", pdp->dwControlKeyState );
   mod = pdp->dwControlKeyState;

   if( KeyDefs[event.wVirtualKeyCode].flags & KDF_CAPSKEY )
   {
      if( event.dwControlKeyState & CAPSLOCK_ON )
      {
         mod ^= KEYMOD_SHIFT;
      }
   }

   if( event.bKeyDown )
   {
      for( ; event.wRepeatCount; event.wRepeatCount-- )
		{
			unsigned char KeyState[256];
			DECLTEXT( key, "                   " );
			GetKeyboardState( KeyState );
			SetTextSize( &key, ToAscii( event.wVirtualKeyCode
											  , event.wVirtualScanCode
											  , KeyState
											  , (unsigned short*)key.data.data
											  , 0 ) );
			KeyPressHandler( pdp, event.wVirtualKeyCode, mod, (PTEXT)&key );
		}
#if 0
      // here is where we evaluate the curent keystroke....
      for( ; event.wRepeatCount; event.wRepeatCount-- )
		{

         // check current keyboard override...
         if( pdp->Keyboard[event.wVirtualKeyCode][mod].flags.bStroke ||
             pdp->Keyboard[event.wVirtualKeyCode][mod].flags.bMacro )
         {
            if( pdp->Keyboard[event.wVirtualKeyCode][mod].flags.bStroke )
            {
               bOutput |= DoStroke(pdp, pdp->Keyboard[event.wVirtualKeyCode][mod].data.stroke);
            }
            else if( pdp->Keyboard[event.wVirtualKeyCode][mod].flags.bMacro )
            {
               if( pdp->common.Owner->pRecord != pdp->Keyboard[event.wVirtualKeyCode][mod].data.macro )
                  InvokeMacro( pdp->common.Owner
                             , pdp->Keyboard[event.wVirtualKeyCode][mod].data.macro
                             , NULL );
            }
         }
         else // key was not overridden
         {
            int result;
            Log1( "Keyfunc = %d", KeyDefs[event.wVirtualKeyCode].op[mod].bFunction );
            switch( KeyDefs[event.wVirtualKeyCode].op[mod].bFunction )
            {
            case KEYDATA_DEFINED:
               Log( "Key data_defined" );
               bOutput |= DoStroke( pdp, (PTEXT)&KeyDefs[event.wVirtualKeyCode].op[mod].data.pStroke );
                    result = UPDATE_NOTHING; // unsure about this - recently added.
                    // well it would appear that the stroke results in whether to update
                    // the command prompt or not.
                break;
            case KEYDATA:
               {
                  char KeyState[256];
                  DECLTEXT( key, "                   " );
                  GetKeyboardState( KeyState );
                  SetTextSize( &key, ToAscii( event.wVirtualKeyCode
                                            , event.wVirtualScanCode
                                            , KeyState
                                            , (void*)key.data.data
                                            , 0 ) );
                  if( GetTextSize( (PTEXT)&key ) )
                     bOutput |= DoStroke( pdp, (PTEXT)&key );
                  result = UPDATE_NOTHING; // already taken care of?!
               }
               break;
            case COMMANDKEY:
               result = KeyDefs[event.wVirtualKeyCode].op[mod].data.CommandKey( pdp->common.CommandInfo );
               break;
            case HISTORYKEY:
               result = KeyDefs[event.wVirtualKeyCode].op[mod].data.HistoryKey( pdp->pHistoryDisplay );
               break;
            case CONTROLKEY:
               KeyDefs[event.wVirtualKeyCode].op[mod].data.ControlKey( &pdp->dwControlKeyState, TRUE );
               result = UPDATE_NOTHING;
               break;
            case SPECIALKEY:
               result = KeyDefs[event.wVirtualKeyCode].op[mod].data.SpecialKey( pdp );
               break;
            }
            switch( result )
            {
            case UPDATE_COMMAND:
               bOutput = TRUE;
               break;
				case UPDATE_HISTORY:
					if( UpdateHistory( pdp ) )
						DoRenderHistory(pdp, TRUE);
						DoRenderHistory(pdp, FALSE);

					break;
				case UPDATE_DISPLAY:
					ChildCalculate( pdp );
					break;
            }
         }
      }
      //if( bOutput )
		//   RenderCommandLine( pdp );
#endif
   }
   else
   {
    // flag is redundant for CONTOLKEY type...
      // key up's only matter if key is upaction flaged...
    switch( KeyDefs[event.wVirtualKeyCode].op[mod].bFunction )
    {
        case CONTROLKEY:
            KeyDefs[event.wVirtualKeyCode].op[mod].data.ControlKey( &pdp->dwControlKeyState, FALSE );
            break;
        }
   }
   LeaveCriticalSec( &pdp->Lock );
   //lprintf( "Left critical section on wincon." );
#endif
}
Ejemplo n.º 9
0
void ParseURI( CTEXTSTR string )
{
   int state;
	PTEXT words;
	PTEXT delete_seg = NULL;
	PTEXT line = SegCreateFromText( string );
	PTEXT filename = NULL;
   PTEXT varname = NULL;
	PTEXT varvalue = NULL;
   PTEXT content = NULL;
   int content_length;

	struct {
		uint32_t bInvalid : 1;
		uint32_t bGet : 1;
		uint32_t bPost : 1;
		uint32_t bBinary : 1; // reading the content...
		uint32_t bValue : 1;
	} flags;
// we got a line, therefore we can process it...
	// only thing then is the last line in the block ...

	state = GET_FILENAME;

	words = burst( line );
	delete_seg = words;
	// though...
	LineRelease( line );
	flags.bValue = 0;

	while( words )
	{
		DECLTEXT( page, WIDE("page") );
		DECLTEXT( CGI, WIDE("CGI") );
		//printf( "state:%d word:%s \r\n",state, GetText(words ) );
		// what does stuff have now?  the whole thign?  a line?
		if( !GetTextSize( words ) ) switch( state )
		{
		case GET_HTTP_EOL:
			state = GET_HTTP_METAVAR;
			break;
		case GET_HTTP_METAVAR:
		case GET_CGI:
			goto AddCGIVariable;
			break;
		}
		else switch( state )
		{
		case RESET:
			state = GET_COMMAND;
			continue;  // skip ahead  and try new state;
			break;
		case GET_COMMAND:
			if( TextLike( words, WIDE("GET") ) )
			{
				state = GET_FILENAME;
				//flags.bGet = TRUE;
			}
			else if( TextLike( words, WIDE("POST") ) )
			{
				state = GET_FILENAME;
				//flags.bPost = TRUE;
			}
			else
			{
				flags.bInvalid = TRUE;
			}
			break;
		case GET_FILENAME:
			if( !filename && TextIs( words, WIDE("/") ) )
			{
				// this is rude, and should never be done,
				// however this filter consumes all data anyhow, SO
				// mangling this will not hurt much...
				words->format.position.offset.spaces = 0;
			}
			if( TextIs( words, WIDE("?") ) || words->format.position.offset.spaces )
			{
				if( !words->format.position.offset.spaces )
					state = GET_CGI;
				else
					state = GET_HTTP_VERSION;
				filename = NEXTLINE( filename );
				LineRelease( SegBreak( filename ) );
				HTTPCollapse( &filename );
				//AddVariableExxx( ps, ps->Current, (PTEXT)&page, filename, FALSE,TRUE,TRUE DBG_SRC );
				//AddVariable( ps, ps->Current, (PTEXT)&CGI, TextDuplicate( NEXTLINE( words ), FALSE ) );
				LineRelease( filename );
				filename = NULL;
			}
			else
			{
				filename = SegAppend( filename, SegDuplicate( words ) );
			}
			break;
		case GET_CGI:
			if( words->format.position.offset.spaces )
			{
				state = GET_HTTP_VERSION;
				goto AddCGIVariable;
			}
			else
			{
				if( TextIs( words, WIDE("=") ) )
				{
					HTTPCollapse( &varname );
					flags.bValue = 1;
				}
				else if( TextIs( words, WIDE("&") ) )
				{
				AddCGIVariable:
					HTTPCollapse( &varvalue );
					HTTPCollapse( &varname );
					if( TextLike( varname, WIDE("content-length") ) )
					{
						content_length= IntCreateFromText( GetText( varvalue ) );
					}
					{
						struct VAR *v = New( struct VAR );
						v->varname = varname;
						varname = NULL;
						v->varvalue = varvalue;
						varvalue = NULL;
						AddLink( &l.vars, v );
					}
					//AddVariableExxx( ps, ps->Current, pmdp->varname, pmdp->varvalue, FALSE,TRUE,TRUE DBG_SRC );
					//LineRelease( varname );
					//LineRelease( varvalue );
					//varname = NULL;
					//varvalue = NULL;
					flags.bValue = 0;
				}
				else
				{
					if( flags.bValue )
					{
						varvalue = SegAppend( varvalue, SegDuplicate( words ) );
					}
					else
					{
						//printf( "add var" );
						varname = SegAppend( varname, SegDuplicate( words ) );
					}
				}
			}
			break;
		case GET_HTTP_VERSION:
			if( TextIs( words, WIDE("HTTP") ) )
					{
						// okay - don't really do anything... next word is the version...
					}
					else
					{
                  // TextIs( words, "/" ); // this is a token before the number...
						// Version better be something like 1.1 1.0?
						// well wait for EOL...
						state = GET_HTTP_EOL;
					}
					break;
				case GET_HTTP_EOL:
					if( !GetTextSize( words ) )
					{
						state = GET_HTTP_METAVAR;
					}
					break;
				case GET_HTTP_METAVAR:
					{
						if( !flags.bValue && TextIs( words, WIDE(":") ) )
						{
                     flags.bValue = TRUE;
						}
						else
						{
							if( flags.bValue )
							{
                        varvalue = SegAppend( varvalue, SegDuplicate( words ) );
							}
							else
							{
                        varname = SegAppend( varname, SegDuplicate( words ) );
							}
						}
					}
               break;
				case GET_HTTP_CONTENT:
					if( !content_length )
					{
                  DebugBreak();
                  state = RESET;
					}
					else
					{
						// hmm we've parsed everything up to here, but now we need blocks, binary blocks.
						content = SegAppend( content, words );
						if( LineLength( content ) == content_length )
						{
							//ProcessPostCGI( common.Owner, content );
							//AddVariableExxx( ps, ps->Current, (PTEXT)&CGI, content, FALSE,TRUE,TRUE DBG_SRC );
							//AddVariable( ps, ps->Current, (PTEXT)&CGI, content );
							LineRelease( content );

							//InvokeBehavior( "http.request", common.Owner->Current, common.Owner, NULL );
							//InvokeBehavior( "http_request", common.Owner->Current, common.Owner, NULL );
							state = RESET;
						}
                  words = NULL;
					}
					break;
		}
Ejemplo n.º 10
0
int CPROC MakeProcess( PSENTIENT ps, PENTITY peInit, PTEXT parameters )
{
	// parameters specify command and parameters to launch...
	// perhaps a working directory? May or may not want it
	// in the current directory...
	// /make process test WIDE("command arguments") WIDE("work path") <attributes?>
	// /make process test WIDE("notepad trigger.txt") 
	PSENTIENT ps2;
	PPROCESS process = New( PROCESS );
	TEXTCHAR MyPath[256];
	GetCurrentPath( MyPath, sizeof( MyPath ) );
	ps2 = CreateAwareness( peInit );
	MemSet( process, 0, sizeof( PROCESS ) );
	Log( WIDE("Have a process, and woke it up... setting the link") );
	SetLink( &peInit->pPlugin, iProcess, process );
	SetLink( &peInit->pDestroy, iProcess, DestroyProcess );
	Log( WIDE("Set the link, getting params...") );
	{
		PTEXT text, cmd = NULL;
		text = GetParam( ps, &parameters );
		if( text && TextIs( text, WIDE("\"") ) )
		{
	      Log( WIDE("Found a quote, getting command line") );
			while( (text = GetParam( ps, &parameters )) && !TextIs( text, WIDE("\"") ) )
			{
				cmd = SegAppend( cmd, SegDuplicate( text ) );
			}
			cmd->format.position.offset.spaces = 0;
			process->command = BuildLine( cmd );
			if( text ) // closed, and may have start path....
			{
				text = GetParam( ps, &parameters );
		   	if( text && TextIs( text, WIDE("\"") ) )
				{
					Log( WIDE("Found a quote, getting the path") );
					while( (text = GetParam( ps, &parameters )) && !TextIs( text, WIDE("\"") ) )
					{
						cmd = SegAppend( cmd, SegDuplicate( text ) );
		   		}
		   		cmd->format.position.offset.spaces = 0;
		   		process->directory = BuildLine( cmd );
				}
			}
		}
		else
		{
			DECLTEXT( msg, WIDE("Must specify process to execute in quotes (\")") );
			EnqueLink( &ps->Command->Output, &msg );
		WakeAThread( ps2 );
			return -1; // abort creation.
		}
	}
	Log2( WIDE("Starting %s in %s"), GetText( process->command ), GetText( process->directory ) );
	process->si.cb = sizeof( process->si );
	// remaining startup info members are NULL - specifying we do NOT care
	// why why when where how the process starts.
	if( StartProcess( process ) )
	{
		DECLTEXTSZ( msg, 256 );
		msg.data.size = snprintf( msg.data.data, 256*sizeof(TEXTCHAR), WIDE("Failed to start \"%s\" in \"%s\" error: %ld"),
										 GetText( process->command ),
										 GetText( process->directory ),
										 GetLastError() );
		EnqueLink( &ps->Command->Output, SegDuplicate( (PTEXT)&msg ) );
		WakeAThread( ps2 );
		return -1; // abort creation.
	}
	// well otherwise would seem we've launched a valid application
	// we have valid process and thread handles to it which can be monitored
	// and well that's about that.
	WakeAThread( ps2 );
	return 0;
}
Ejemplo n.º 11
0
int InitImage( PSENTIENT ps, PENTITY pe, PTEXT parameters )
{
	INDEX idx;
	for( idx = 0; idx < NUM_IMAGE_VARS; idx++ )
	{
      PTEXT saveparms = parameters;
		PTEXT arg;
		Image parent = GetLink( &FindContainer( pe )->pPlugin, iImage );
		arg = GetParam( ps, &parameters );
		if( IsNumber( arg ) )
		{
			PTEXT arg2 = GetParam( ps, &parameters );
			if( IsNumber( arg2 ) )
			{
            Image image;
				if( parent )
					image = MakeSubImage( parent
											  , 0, 0 // need other 2 arguments.
											  , atoi( GetText( arg ) )
											  , atoi( GetText( arg2 ) )
											  );
            else
					image = MakeImageFile( atoi( GetText( arg ) )
													, atoi( GetText( arg2 ) ) );
				SetLink( &pe->pPlugin, iImage, image );
				if( ps->CurrentMacro )
					ps->CurrentMacro->state.flags.bSuccess = TRUE;
				else
				{
					DECLTEXT( msg, "Invalid second parameter, expecting a number" );
               EnqueLink( &ps->Command->Output, &msg );
				}
				// if more args - warn?
			}
		}
		else
		{
         Image image;
			// expect that the remainder is a name..
			parameters = saveparms;
			arg = GetFileName( ps, &parameters );
         // loaded image file doesn't care for parent status...
			image = LoadImageFile( GetText( arg ) );
			if( image )
			{
				SetLink( &pe->pPlugin, iImage, image );
				if( ps->CurrentMacro )
					ps->CurrentMacro->state.flags.bSuccess = TRUE;
				else
				{
					DECLTEXT( msg, "Failed to load image..." );
               EnqueLink( &ps->Command->Output, &msg );
				}
			}
		}
		AddVolatileVariable( pe, ImageVars + idx, 0 );
		{
			int n;
			for( n = 0; n < NUM_METHODS; n++ )
            AddMethod( pe, ImageMethods + n );
		}

	}
	return 0; // return success
}
Ejemplo n.º 12
0
int GetInputData( int bWord, PSENTIENT ps, PTEXT parameters )
{
	if( ps->Data )
	{
		PTEXT pSave, temp;
		PTEXT *pInd = NULL;
		pSave = parameters;
		lprintf( WIDE("Get data from datapath...") );
		if( !( ( temp = GetParam( ps, &parameters ) ) ) )
		{
			lprintf( WIDE("No parameters specified to get line") );
			LineRelease( ps->pLastResult );
			ps->pLastResult = NULL;
			pInd = &ps->pLastResult;
		}
		else
		{
			if( temp == pSave )
			{
				DECLTEXT( msg, WIDE("is not a valid variable reference.") );
				EnqueLink( &ps->Command->Output, SegAppend( SegDuplicate( temp ), (PTEXT)&msg ) );
				return FALSE;
			}
			if( temp->flags & TF_INDIRECT )
			{
				LineRelease( GetIndirect( temp ) );
				SetIndirect( temp, NULL );
				pInd = (PTEXT*)&temp->data.size;
			}
			else
			{
				DECLTEXT( msg, WIDE("is not a valid variable reference(not indirect).") );
				EnqueLink( &ps->Command->Output, SegAppend( SegDuplicate( temp ), (PTEXT)&msg ) );
				return FALSE;
			}
		}

		if( !pInd )
		{
			DECLTEXT( msg, WIDE("FATAL ERROR: Did not set pInd (GetLine)") );
			EnqueLink( &ps->Command->Output, (PTEXT)&msg );
				return FALSE;
		  }
		// try grabbing an existing line - could be put there from BURST of prior...

		if( !ps->Data->CurrentWord ) // just got last word off line...
		{
			if( ps->Data->CurrentLine )
			{
				LineRelease( ps->Data->CurrentLine );
				ps->Data->CurrentLine = NULL;
			}
		}

		if( !ps->Data->CurrentLine )
		{
			 // Gather Data from input source....
		 // data from HT_CLIENT 'appears' asynchrous
		  // to scripting....
			if( ps->Data->Read )
				ps->Data->Read( ps->Data ); // this returns a completeline...
			ps->Data->CurrentLine = (PTEXT)DequeLink( &ps->Data->Input );
		}

		if( ps->Data->CurrentLine )
			if( !ps->Data->CurrentWord )
				ps->Data->CurrentWord = ps->Data->CurrentLine;

		if( ps->Data->CurrentWord )
		{
			// indirect pointer will be null.
			if( bWord )
			{
				*pInd = SegDuplicate( ps->Data->CurrentWord );
				ps->Data->CurrentWord = NEXTLINE( ps->Data->CurrentWord );
			}
			else
			{
				// duplicate to end of line... which may be whole - or
				// may be partial because of prior GETWORD from the line...
				// then release the data input line...
				// must duplicate the data in either case cause
				// it will be deleted with additional setting of the
				// variable...
					 *pInd = TextDuplicate( ps->Data->CurrentWord, FALSE );
				LineRelease( ps->Data->CurrentWord );
				ps->Data->CurrentLine = NULL; // do NOT release this line...
				ps->Data->CurrentWord = NULL; // no word on line
			}
		}
		if( ps->CurrentMacro && *pInd )
			ps->CurrentMacro->state.flags.bSuccess = TRUE;
	}
	 return FALSE;
}
Ejemplo n.º 13
0
//--------------------------------------
int CPROC COMMAND( PSENTIENT ps, PTEXT parameters )
{
	PTEXT temp;
	 PTEXT devname;
	 if( ( devname = GetParam( ps, &parameters ) ) )
	 {
		  // find device to see if it's already open...
		  // by name! 
		  // but - this causes a problem for nested scripts
		  // which are going to have to be artificiailly inceminated
		  // with a unique name maybe something like script_#####
		  PDATAPATH pdp = FindOpenDevice( ps, devname );
		  if( pdp )
		  {
			if( !ps->CurrentMacro )
			{
					 PVARTEXT pvt;
					 pvt = VarTextCreate();
					 vtprintf( pvt, WIDE("Device named %s is already open."), GetText( devname ) );
					 EnqueLink( &ps->Command->Output, (POINTER)VarTextGet( pvt ) );
					 VarTextDestroy( &pvt );
				}
				return -1;
		  }
		 if( ( temp = GetParam( ps, &parameters ) ) )
		  {
			  PDATAPATH pdp;

			  //lprintf( WIDE("Opening device handle named: %s"), GetText( devname ) );
			  if( ( pdp = OpenDevice( &ps->Command, ps, temp, parameters ) ) )
			  {
				  PTEXT pCommand;
				  PDATAPATH pOldPath;
				  while( devname->flags & TF_INDIRECT )
					  devname = GetIndirect( devname );
				  pdp->pName = SegDuplicate( devname );
				  if( ps->Command )
				  {
				  // remove old command queue so close won't remove
				  // ps->Command->Input = NULL;
				  // close the command queue...

				  // update to the new queue in the sentience
				  // if the new one is a data source, then we
				  // need to move old commands to new path -
				  // otherwise they may/will get lost.
					  if( ps->Command->flags.Data_Source
						 && !ps->Command->flags.Dont_Relay_Prior)
								 {
									 pOldPath = ps->Command->pPrior;

												 // move all commands from old queue to new queue
									 while( ( pCommand = (PTEXT)DequeLink( &pOldPath->Input ) ) )
									 {
										 EnqueLink( &ps->Command->Input, pCommand );
									 }

									 while( ( pCommand = (PTEXT)DequeLink( &pOldPath->Output ) ) )
									 {
										 EnqueLink( &ps->Command->Output, pCommand );
									 }
								 }
				  }
				  if( ps->CurrentMacro )
					  ps->CurrentMacro->state.flags.bSuccess = TRUE;
			  }
		  }
		  else
		  {
				DECLTEXT( msg, WIDE("Command must specify a name (/command <name> <device> <options...)") );
				EnqueLink( &ps->Command->Output, (PTEXT)&msg );
		  }
	}
	return FALSE;
}