//-------------------------------------- int CPROC MEMORY( PSENTIENT ps, PTEXT parameters ) { uint32_t nFree, nUsed, nChunks, nFreeChunks; PVARTEXT vt; PTEXT temp, next; next = GetParam( ps, ¶meters ); while( temp = next ) { if( temp && TextLike( temp, WIDE("log") ) ) { temp = GetParam( ps, ¶meters ); if( temp && TextLike( temp, WIDE("off") ) ) SetAllocateLogging( FALSE ); else { SetAllocateLogging( TRUE ); if( temp ) { next = temp; continue; } } } if( temp && TextLike( temp, WIDE("debug") ) ) { temp = GetParam( ps, ¶meters ); if( temp && TextLike( temp, WIDE("off") ) ) SetAllocateDebug( TRUE ); else { SetAllocateDebug( FALSE ); if( temp ) { next = temp; continue; } } } next = GetParam( ps, ¶meters ); } GetMemStats( &nFree, &nUsed, &nChunks, &nFreeChunks ); vt = VarTextCreate( ); vtprintf( vt, WIDE("Memory : Free %ld(%ld), Used %ld(%ld) (optional paramters \'log\',\'debug\' followed by off to disable."), nFree, nFreeChunks, nUsed, nChunks - nFreeChunks ); EnqueLink( &ps->Command->Output, VarTextGet( vt ) ); VarTextDestroy( &vt ); return FALSE; }
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, ¶meters ); 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; }
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; }