BOOL CRKey::Replace(LPCTSTR pSrc, LPCTSTR pDst) {_STTEX(); // Open files CWinFile src, dst; if ( !src.OpenExisting( pSrc, GENERIC_READ ) ) return FALSE; if ( !dst.OpenNew( pDst, GENERIC_WRITE ) ) return FALSE; // Read in data TMem< BYTE > in; if ( !in.allocate( src.Size() ) ) return FALSE; if ( !src.Read( in.ptr(), in.size() ) ) return FALSE; src.Close(); // Run replace function CPipe outpipe; DWORD op = 0, i = 0; char token[ 256 ]; while ( Replace( &outpipe, &op, in.str(), in.size(), NULL, NULL, token, NULL, &i ) ) { } // end while // Write out the data return dst.Write( outpipe.GetBuffer(), outpipe.GetBufferSize() ); }
/** * Runs a Wine test and captures the output * * @param TestInfo * Pointer to a CTestInfo object containing information about the test. * Will contain the test log afterwards if the user wants to submit data. */ void CWineTest::RunTest(CTestInfo* TestInfo) { DWORD BytesAvailable; stringstream ss, ssFinish; DWORD StartTime; float TotalTime; string tailString; CPipe Pipe; char Buffer[1024]; ss << "Running Wine Test, Module: " << TestInfo->Module << ", Test: " << TestInfo->Test << endl; StringOut(ss.str()); StartTime = GetTickCount(); try { /* Execute the test */ CPipedProcess Process(TestInfo->CommandLine, Pipe); /* Receive all the data from the pipe */ while(Pipe.Read(Buffer, sizeof(Buffer) - 1, &BytesAvailable) && BytesAvailable) { /* Output text through StringOut, even while the test is still running */ Buffer[BytesAvailable] = 0; tailString = StringOut(tailString.append(string(Buffer)), false); if(Configuration.DoSubmit()) TestInfo->Log += Buffer; } if(GetLastError() != ERROR_BROKEN_PIPE) TESTEXCEPTION("CPipe::Read failed for the test run\n"); } catch(CTestException& e) { if(!tailString.empty()) StringOut(tailString); tailString.clear(); StringOut(e.GetMessage()); TestInfo->Log += e.GetMessage(); } /* Print what's left */ if(!tailString.empty()) StringOut(tailString); TotalTime = ((float)GetTickCount() - StartTime)/1000; ssFinish << "Test " << TestInfo->Test << " completed in "; ssFinish << setprecision(2) << fixed << TotalTime << " seconds." << endl; StringOut(ssFinish.str()); TestInfo->Log += ssFinish.str(); }
s64 epoller::DealEvent(s64 overtime) { s64 lTick = tools::GetTimeMillisecond(); epoll_event events[EPOLLER_EVENTS_COUNT]; memset(&events, 0, sizeof(events)); errno = 0; int retCount = epoll_wait(m_lEpollFD, events, EPOLLER_EVENTS_COUNT, 5); if (retCount == -1) { TASSERT(errno == EINTR, "epoll_wait err! %s", strerror(errno)); return tools::GetTimeMillisecond() - lTick; } for (s32 i=0; i<retCount; i++) { epollerEvent * pEvent = (epollerEvent *)events[i].data.ptr; switch (pEvent->type) { case SO_ACCEPT: { SPipe * pSPipe = (SPipe *)pEvent->pData; if (events[i].events & (EPOLLERR | EPOLLHUP | EPOLLRDHUP)) { pSPipe->GetHost()->Error(Kernel::getInstance(), NULL); } else if (events[i].events & EPOLLIN) { pSPipe->DoAccept(); } break; } case SO_CONNECT: { CPipe * pCPipe = (CPipe *)pEvent->pData; if (events[i].events & (EPOLLERR | EPOLLHUP | EPOLLRDHUP)) { pCPipe->GetHost()->OnConnectFailed(Kernel::getInstance()); pCPipe->GetHost()->m_pPipe = NULL; pCPipe->Release(); } else if (events[i].events & EPOLLOUT) { pCPipe->DoConnect(); } break; } default: TASSERT(false, "wtf"); break; } } return tools::GetTimeMillisecond() - lTick; }
/** * Executes the --list command of a module test file to get information about the available tests. * * @return * The number of bytes we read into the m_ListBuffer member variable by capturing the output of the --list command. */ DWORD CWineTest::DoListCommand() { DWORD BytesAvailable; DWORD Temp; wstring CommandLine; CPipe Pipe; /* Build the command line */ CommandLine = m_TestPath; CommandLine += m_CurrentFile; CommandLine += L" --list"; { /* Start the process for getting all available tests */ CPipedProcess Process(CommandLine, Pipe); /* Wait till this process ended */ if(WaitForSingleObject(Process.GetProcessHandle(), ListTimeout) == WAIT_FAILED) TESTEXCEPTION("WaitForSingleObject failed for the test list\n"); } /* Read the output data into a buffer */ if(!Pipe.Peek(NULL, 0, NULL, &BytesAvailable)) TESTEXCEPTION("CPipe::Peek failed for the test list\n"); /* Check if we got any */ if(!BytesAvailable) { stringstream ss; ss << "The --list command did not return any data for " << UnicodeToAscii(m_CurrentFile) << endl; TESTEXCEPTION(ss.str()); } /* Read the data */ m_ListBuffer = new char[BytesAvailable]; if(!Pipe.Read(m_ListBuffer, BytesAvailable, &Temp)) TESTEXCEPTION("CPipe::Read failed\n"); return BytesAvailable; }
BOOL CReg::EncodeUrl(CPipe *pPipe, char chSepNameVal, char chSepValues ) { // Ensure valid pipe if ( NULL == pPipe ) return FALSE; TMem< char > buf; LPREGKEY prk = NULL; while( ( prk = (LPREGKEY)GetNext( prk ) ) != NULL ) { // Write separator if needed if ( pPipe->GetBufferSize() ) pPipe->Write( &chSepValues, 1 ); LPCTSTR pName = prk->key->GetName(); CRKey *pRk = GetKey( pName ); if ( pRk ) { // Write the name if ( buf.grow( CCfgFile::GetMinCanonicalizeBufferSize( strlen( pName ) ) ) ) { buf.Zero(); CCfgFile::CanonicalizeBuffer( buf, (LPBYTE)pName, strlen( pName ) ); pPipe->Write( buf ); } // end if // Separator pPipe->Write( &chSepNameVal, 1 ); // Save the key value CPipe tpipe; prk->key->EncodeUrl( &tpipe, 1, chSepNameVal, chSepValues ); if ( buf.grow( CCfgFile::GetMinCanonicalizeBufferSize( tpipe.GetBufferSize() ) ) ) { buf.Zero(); CCfgFile::CanonicalizeBuffer( buf, (LPBYTE)tpipe.GetBuffer(), tpipe.GetBufferSize() ); pPipe->Write( buf ); } // end if } // end if } // end while return TRUE; }
void sensorFeedback(CPipe motorDone, CPipe motor, MotorData ST400, CSerial serial){ while(motorDone.TestForData() == 0){ //Check if a sensor detects something, otherwise wait until //motor indicates it has completed current instructions /*Insert sensor logic here (maybe a separate thread or new class?)*/ //Make sure ST400.stop is set to 1 if a sensor interrupt occurs //and write to ST400Control if (serial.Open(4, 9600)) { char* lpBuffer = new char[100]; int nBytesRead = serial.ReadData(lpBuffer, 100); strtok(lpBuffer,"\n"); if(atoi(lpBuffer) == 1){ ST400.stop=1; cout<<"HIT"<<endl; //cout<<"YAY I READ FROM ARDRUINO!"<<endl; motor.Write(&ST400, sizeof(ST400)); ST400.stop=0; ST400.leftWheel=0; //Prevent rover from executing remaining steps ST400.rightWheel=0; break; } else{ ST400.stop=0; cout<<"MISS"<<endl; } } } };
BOOL CRKey::Set(LPCTSTR pName, CRKey *pRk) {_STTEX(); if ( !pRk || !pRk->Size() ) { // Clear data Set( pName, "" ); return TRUE; } // end if // Serialize variables CPipe pipe; pRk->EncodeUrl( &pipe ); // Write a NULL character pipe.Write( "", 1 ); // Save the serialized variables Set( pName, (LPCTSTR)pipe.GetBuffer() ); return TRUE; }
bool epoller::AddClient(ITcpSession * client, const char * ip, const s32 port) { s64 lSocket = -1; struct timeval tv; struct sockaddr_in addr; memset(&addr, 0, sizeof (addr)); addr.sin_family = AF_INET; addr.sin_port = htons(port); if (-1 == (lSocket = socket(AF_INET, SOCK_STREAM, 0)) || 0 != setsockopt(lSocket, SOL_SOCKET, SO_REUSEADDR, (const char*) &tv, sizeof (tv)) || !setnonblocking(lSocket) || inet_pton(AF_INET, ip, &addr.sin_addr) <= 0) { ECHO("socket error %s", strerror(errno)); close(lSocket); return false; } s32 ret = connect(lSocket, (struct sockaddr *) &addr, sizeof (addr)); if (ret == 0) { CPipe * pCPipe = CPipe::Create(); s64 lEpollFD = BalancingWorker()->GetEpollFD(); pCPipe->Relate(client, lSocket, lEpollFD); pCPipe->DoConnect(); client->OnConnected(Kernel::getInstance()); } else if (ret < 0 && errno != EINPROGRESS) { ECHO("connect error %s", strerror(errno)); client->OnConnectFailed(Kernel::getInstance()); return false; } else { CPipe * pCPipe = CPipe::Create(); s64 lEpollFD = BalancingWorker()->GetEpollFD(); pCPipe->Relate(client, lSocket, lEpollFD); epoll_event ev; ev.data.ptr = (void *)pCPipe->GetEvent(); ev.events = EPOLLOUT | EPOLLET; s32 res = epoll_ctl(m_lEpollFD, EPOLL_CTL_ADD, lSocket, &ev); TASSERT(res == 0, strerror(errno)); } return true; }
UINT __stdcall elevator_console(void *args) { char str[3]; int val[2]; // save str as int int priority = 0; Sleep(2000); while (1) { // gets request entry sema_io_console.Wait(); MOVE_CURSOR(0, 2); printf("Please enter command:\n"); sema_io_console.Signal(); str[0] = _getch(); // Clears out the enter message sema_io_console.Wait(); MOVE_CURSOR(0, 3); printf("\t\t\t\t\t"); MOVE_CURSOR(0, 3); printf("Servicing: %c", str[0]); sema_io_console.Signal(); str[1] = _getch(); str[2] = '\0'; sema_io_console.Wait(); MOVE_CURSOR(0, 3); printf("\t\t\t\t\t"); MOVE_CURSOR(0, 3); printf("Entered: %s\n", str); // convert input to integers if valid if (atoi(&str[1]) && str[1] != '0') { val[1] = atoi(&str[1]); } else if (str[1] == '0') { val[1] = 0; } MOVE_CURSOR(0, 4); printf("\t\t\t\t\t\t\t\t\t\t"); MOVE_CURSOR(0, 4); if (!strcmp(str, "ee")) { // exit case printf("Shutting down elevators\n"); // Write request and priority type to pipe mypip1 = { 99, 99 }; // exit code pipe.Write(&mypip1, sizeof(mypip1)); // redezvous type here before the return 0 return 0; } else if ((str[0] == 'u' && (0 <= val[1] && val[1] < 9)) || (str[0] == 'd' && (0 < val[1] && val[1] < 10))) { // calling the elevator case printf("Please wait, going %c from floor %c\n", str[0], str[1]); // Write request and priority type to pipe // "3-" is an up request and "4-" is a down request if (str[0] == 'u') { mypip1 = { 30 + val[1],priority }; // exit code } else if (str[0] == 'd') { mypip1 = { 40 + val[1],priority }; // exit code } pipe.Write(&mypip1, sizeof(mypip1)); priority++; } else if ((str[0] == '1' || str[0] == '2') && (0 <= val[1] && val[1] < 10)) { // inside the elevator case printf("Closing door, moving elevator %c to floor %c \n", str[0], str[1]); if (str[0] == '1') { mypip1 = { 10 + val[1],priority }; // exit code } else if (str[0] == '2') { mypip1 = { 20 + val[1],priority }; // exit code } pipe.Write(&mypip1, sizeof(mypip1)); priority++; } else if ((str[0] == '+' || str[0] == '-') && (val[1] == 1 || val[1] == 2)) // servicing elevators and faults { if (!strcmp(str, "+1")) { printf("elevator 1 is in service \n"); } else if (!strcmp(str, "-1")) { printf("elevator 1 is out of service \n"); } else if (!strcmp(str, "+2")) { printf("elevator 2 is in service \n"); } else if (!strcmp(str, "-2")) { printf("elevator 2 is out of service \n"); } // Write request and priority type to pipe // "5-" is an up request and "6-" is a down request if (str[0] == '+') { mypip1 = { 50 + val[1],0 }; // exit code } else if (str[0] == '-') { mypip1 = { 60 + val[1],0 }; // exit code } pipe.Write(&mypip1, sizeof(mypip1)); } else { printf("INVALID ENTRY!\n"); } sema_io_console.Signal(); val[0] = -1; //if val[0] isn't what we want then set it to -1 val[1] = -1; //if val[1] isn't what we want then set it to -1 } }
//@ MAIN int main(){ char KeyData; char KeyData1; int iKeyData; int preflag = 1; int termination_code = 99; //@ SEQ: STARTUP RENDEZVOUS printf("Pretending to rendezvous by sleeping 3 seconds...\n"); Sleep(3000); r1.Wait(); printf("let's go!"); Sleep(1000); MOVE_CURSOR(0,0); printf("----------+---+---------------------+---+--------------------"); MOVE_CURSOR(0,4); printf("----------+---+---------------------+---+--------------------"); MOVE_CURSOR(0,8); printf("----------+---+---------------------+---+--------------------"); MOVE_CURSOR(0,12); printf("----------+---+---------------------+---+--------------------"); MOVE_CURSOR(0,16); printf("----------+---+---------------------+---+--------------------"); MOVE_CURSOR(0,20); printf("----------+---+---------------------+---+--------------------"); MOVE_CURSOR(0,24); printf("----------+---+---------------------+---+--------------------"); MOVE_CURSOR(0,28); printf("----------+---+---------------------+---+--------------------"); MOVE_CURSOR(0,32); printf("----------+---+---------------------+---+--------------------"); MOVE_CURSOR(0,36); printf("----------+---+---------------------+---+--------------------"); MOVE_CURSOR(0,40); printf("----------+---+---------------------+---+--------------------"); fflush(stdout); //@ INIT: THREADS CThread t1(IOToElevator1, ACTIVE, NULL) ; CThread t2(IOToElevator2, ACTIVE, NULL) ; //printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); //MOVE_CURSOR(0,0); //printf("Press x at any time to exit... "); //fflush(stdout); while(flag) { // Master Termination. if (preflag == 0) { pipe3.Write(&termination_code, sizeof(int)); pipe4.Write(&termination_code, sizeof(int)); flag = 0; Sleep(50); pipe1.Write(&termination_code, sizeof(int)); break; } if (TEST_FOR_KEYBOARD() != 0) { KeyData = getch() ; // read next character from keyboard m1->Wait(); MOVE_CURSOR(0,50); printf("first character = %c \n", KeyData); printf("second character? \n"); printf(" \n"); printf(" \n"); fflush(stdout); m1->Signal(); while (TEST_FOR_KEYBOARD() == 0) {} KeyData1 = getch(); m1->Wait(); MOVE_CURSOR(0,51); printf("second character = %c \n", KeyData1); printf("command entered is: %c%c \n", KeyData, KeyData1); //Command Organization. if (KeyData == 'e' && KeyData1 == 'e'){ preflag = 0; printf("terminating. (2 seconds) \n "); Sleep(2000); } else if (KeyData == '-' && KeyData1 == '1') { iKeyData = 70; pipe1.Write(&iKeyData, sizeof(int)); printf("FREEZING Elevator 1! "); } else if (KeyData == '-' && KeyData1 == '2') { iKeyData = 71; pipe1.Write(&iKeyData, sizeof(int)); printf("FREEZING Elevator 2! "); } else if (KeyData == '+' && KeyData1 == '1') { iKeyData = 75; pipe1.Write(&iKeyData, sizeof(int)); printf("FAULT FIXED for Elevator 1! "); } else if (KeyData == '+' && KeyData1 == '2') { iKeyData = 76; pipe1.Write(&iKeyData, sizeof(int)); printf("FAULT FIXED for Elevator 2! "); } else if (KeyData == 'u'&& ( (KeyData1-'0') >= 0 && (KeyData1-'0') < 10 ) ) { iKeyData = 10 + KeyData1 - '0'; pipe1.Write(&iKeyData, sizeof(int)); printf("Someone Outside Floor %d wants to go UP. ", (KeyData1 - '0') ); } else if (KeyData == 'd'&& ( (KeyData1-'0') >= 0 && (KeyData1-'0') < 10 )) { iKeyData = 20 + KeyData1 - '0'; pipe1.Write(&iKeyData, sizeof(int)); printf("Someone Outside Floor %d wants to go DOWN. ", (KeyData1 - '0') ); } else if (KeyData == '1'&& ( (KeyData1-'0') >= 0 && (KeyData1-'0') < 10 )) { iKeyData = 50 + KeyData1 - '0'; pipe1.Write(&iKeyData, sizeof(int)); printf("Someone Inside Elevator 1 Pressed Floor %d. ", (KeyData1 - '0') ); } else if (KeyData == '2'&& ( (KeyData1-'0') >= 0 && (KeyData1-'0') < 10 )) { iKeyData = 60 + KeyData1 - '0'; pipe1.Write(&iKeyData, sizeof(int)); printf("Someone Inside Elevator 2 Pressed Floor %d. ", (KeyData1 - '0') ); } else{ printf("ERROR: illegible code. "); } fflush(stdout); m1->Signal(); KeyData = '0'; KeyData1 = '0'; iKeyData = 0; } m1->Wait(); // 9 MOVE_CURSOR(20,2); printf(" |"); if (Ele1Status.updir[9] == 1 || Ele2Status.updir[9] == 1) TEXT_COLOUR(14); printf("UP "); TEXT_COLOUR(7); if (Ele1Status.downdir[9] == 1 || Ele2Status.downdir[9] == 1) TEXT_COLOUR(14); printf("DOWN"); TEXT_COLOUR(7); printf("| "); //8 MOVE_CURSOR(20,6); printf(" |"); if (Ele1Status.updir[8] == 1 || Ele2Status.updir[8] == 1) TEXT_COLOUR(14); printf("UP "); TEXT_COLOUR(7); if (Ele1Status.downdir[8] == 1 || Ele2Status.downdir[8] == 1) TEXT_COLOUR(14); printf("DOWN"); TEXT_COLOUR(7); printf("| "); //7 MOVE_CURSOR(20,10); printf(" |"); if (Ele1Status.updir[7] == 1 || Ele2Status.updir[7] == 1) TEXT_COLOUR(14); printf("UP "); TEXT_COLOUR(7); if (Ele1Status.downdir[7] == 1 || Ele2Status.downdir[7] == 1) TEXT_COLOUR(14); printf("DOWN"); TEXT_COLOUR(7); printf("| "); //6 MOVE_CURSOR(20,14); printf(" |"); if (Ele1Status.updir[6] == 1 || Ele2Status.updir[6] == 1) TEXT_COLOUR(14); printf("UP "); TEXT_COLOUR(7); if (Ele1Status.downdir[6] == 1 || Ele2Status.downdir[6] == 1) TEXT_COLOUR(14); printf("DOWN"); TEXT_COLOUR(7); printf("| "); //5 MOVE_CURSOR(20,18); printf(" |"); if (Ele1Status.updir[5] == 1 || Ele2Status.updir[5] == 1) TEXT_COLOUR(14); printf("UP "); TEXT_COLOUR(7); if (Ele1Status.downdir[5] == 1 || Ele2Status.downdir[5] == 1) TEXT_COLOUR(14); printf("DOWN"); TEXT_COLOUR(7); printf("| "); //4 MOVE_CURSOR(20,22); printf(" |"); if (Ele1Status.updir[4] == 1 || Ele2Status.updir[4] == 1) TEXT_COLOUR(14); printf("UP "); TEXT_COLOUR(7); if (Ele1Status.downdir[4] == 1 || Ele2Status.downdir[4] == 1) TEXT_COLOUR(14); printf("DOWN"); TEXT_COLOUR(7); printf("| "); //3 MOVE_CURSOR(20,26); printf(" |"); if (Ele1Status.updir[3] == 1 || Ele2Status.updir[3] == 1) TEXT_COLOUR(14); printf("UP "); TEXT_COLOUR(7); if (Ele1Status.downdir[3] == 1 || Ele2Status.downdir[3] == 1) TEXT_COLOUR(14); printf("DOWN"); TEXT_COLOUR(7); printf("| "); //2 MOVE_CURSOR(20,30); printf(" |"); if (Ele1Status.updir[2] == 1 || Ele2Status.updir[2] == 1) TEXT_COLOUR(14); printf("UP "); TEXT_COLOUR(7); if (Ele1Status.downdir[2] == 1 || Ele2Status.downdir[2] == 1) TEXT_COLOUR(14); printf("DOWN"); TEXT_COLOUR(7); printf("| "); //1 MOVE_CURSOR(20,34); printf(" |"); if (Ele1Status.updir[1] == 1 || Ele2Status.updir[1] == 1) TEXT_COLOUR(14); printf("UP "); TEXT_COLOUR(7); if (Ele1Status.downdir[1] == 1 || Ele2Status.downdir[1] == 1) TEXT_COLOUR(14); printf("DOWN"); TEXT_COLOUR(7); printf("| "); //0 MOVE_CURSOR(20,38); printf(" |"); if (Ele1Status.updir[0] == 1 || Ele2Status.updir[0] == 1) TEXT_COLOUR(14); printf("UP "); TEXT_COLOUR(7); if (Ele1Status.downdir[0] == 1 || Ele2Status.downdir[0] == 1) TEXT_COLOUR(14); printf("DOWN"); TEXT_COLOUR(7); printf("| "); fflush(stdout); MOVE_CURSOR(0,50); fflush(stdout); m1->Signal(); Sleep(1); } t1.WaitForThread() ; t2.WaitForThread() ; printf("\nExiting... (waiting on other processes)"); r2.Wait(); return 0; }
BOOL CNetFile::HttpRequest(LPCTSTR pUrl, CRKey *pHeaders, CRKey *pData, LPCTSTR pMethod, LPCTSTR pLocal, BOOL bCloseFileAfterDownload, HWND hWndParent, DWORD dwUrlEncoding) {_STT(); // Lose previous file Destroy(); // Downloading m_bUpload = FALSE; // Save parent window m_hWndParent = hWndParent; // Save close file status m_bCloseFileAfterDownload = bCloseFileAfterDownload; // Sanity check if ( pUrl == NULL || *pUrl == NULL ) return FALSE; // Are we downloading to file or ram? m_bMem = ( pLocal == NULL ); { // Copy the url char buf[ sizeof( m_szUrl ) ] = { 0 }; DWORD size = sizeof( m_szUrl ) - 1; // Is it a local file? if ( GetFileAttributes( pUrl ) == MAXDWORD ) { // Fix the url if ( InternetCanonicalizeUrl( pUrl, buf, &size, 0 ) ) { strcpy_sz( m_szUrl, buf ); } // Copy the url name else strcpy_sz( m_szUrl, pUrl ); } // end if // Copy the local file name else strcpy_sz( m_szUrl, pUrl ); } // end copy url if ( !m_bMem ) { // Where to download the file if ( pLocal != DOWNLOADTEMP ) { strcpy_sz( m_szLocal, pLocal ); } else CWinFile::CreateTemp( m_szLocal ); // Create a file to load data if ( !m_local.OpenNew( m_szLocal, GENERIC_READ | GENERIC_WRITE ) ) return FALSE; } // end else // Set status m_dwTransferStatus = NETFILE_DS_INITIALIZING; // Save request method if ( pMethod == NULL || *pMethod == 0 ) m_sMethod = "POST"; else m_sMethod = pMethod; // Set data DWORD dwContentLength = 0; if ( pData != NULL ) { CPipe pipe; pData->EncodeUrl( &pipe, dwUrlEncoding ); m_sData.copy( (LPCTSTR)pipe.GetBuffer(), pipe.GetBufferSize() ); dwContentLength = pipe.GetBufferSize(); } // end if // Set headers if ( strcmpi( m_sMethod, "GET" ) ) { CRKey rkHeaders; if ( pHeaders != NULL ) rkHeaders.Copy( pHeaders ); rkHeaders.Set( "Content-Type", "application/x-www-form-urlencoded" ); rkHeaders.Set( "Content-Length", dwContentLength ); CPipe pipe; rkHeaders.EncodeHttpHeaders( &pipe ); m_sHeaders.copy( (LPCTSTR)pipe.GetBuffer(), pipe.GetBufferSize() ); } // end if // Create a thread to download the file if ( !StartThread() ) { Destroy(); m_dwTransferStatus = NETFILE_DS_ERROR; return FALSE; } // end if return TRUE; }
BOOL CNetCmd::vMsg( const GUID *pNode, const GUID *pClass, DWORD dwFunction, CReg *pParams, DWORD dwBuffers, LPVOID *pArgs ) {_STT(); // Verify we have authority to send this message if ( !OnTxAuthenticate( pNode, pClass, dwFunction ) ) return FALSE; // Get destination CNetCom *pNc = GetNode( pNode ); if ( pNc == NULL || !pNc->IsValid() ) return FALSE; // Copy message data CNetMsg::SMsg msg; ZeroMemory( &msg, sizeof( msg ) ); msg.dwFunction = dwFunction; // Encode params CPipe params; if ( pParams ) pParams->SaveRegFile( ¶ms, NULL, "" ); // Calculate the total size needed DWORD dwBlocks = 3; if ( params.GetBufferSize() ) dwBlocks++; DWORD dwTotalSize = ( sizeof( CNetMsg::SAddress ) * 2 ) + sizeof( CNetMsg::SMsg ) + params.GetBufferSize(); DWORD i; LPVOID *ptrExtra = pArgs; for ( i = 0; i < dwBuffers; i++ ) { RULIB_TRY { DWORD dwType = *(LPDWORD)( ptrExtra ); LPBYTE pPtr = *(LPBYTE*)( ptrExtra + 1 ); DWORD dwSize = *(LPDWORD)( ptrExtra + 2 ); dwBlocks++; // Zero means NULL terminated if ( dwSize == 0 && pPtr != NULL ) dwSize = strlen( (LPCTSTR)pPtr ); dwTotalSize += dwSize; ptrExtra += 3; } // end try RULIB_CATCH_ALL { return FALSE; } } // end for // Lock the tx buffer CTlLocalLock ll( *pNc->Tx() ); if ( !ll.IsLocked() ) return FALSE; // Initialze the packet pNc->Tx()->InitPacket( NETMSG_PACKETTYPE, dwBlocks, dwTotalSize ); CNetMsg::SAddress addr; // Destination information memcpy( &addr.guidNode, pNc->Rx()->Address(), sizeof( GUID ) ); if ( pClass ) memcpy( &addr.guidClass, pClass, sizeof( GUID ) ); else ZeroMemory( &addr.guidClass, sizeof( addr.guidClass ) ); pNc->Tx()->AddPacketData( NETMSGDT_DSTADDRESS, &addr, sizeof( addr ) ); // Source information memcpy( &addr.guidNode, pNc->Tx()->Address(), sizeof( GUID ) ); ZeroMemory( &addr.guidClass, sizeof( addr.guidClass ) ); pNc->Tx()->AddPacketData( NETMSGDT_SRCADDRESS, &addr, sizeof( addr ) ); // Add message pNc->Tx()->AddPacketData( NETMSGDT_MSG, &msg, sizeof( msg ) ); // Add params if any if ( params.GetBufferSize() ) pNc->Tx()->AddPacketData( NETMSGDT_PARAMS, params.GetBuffer(), params.GetBufferSize() ); // Add the data to the packet ptrExtra = pArgs; for ( i = 0; i < dwBuffers; i++ ) { RULIB_TRY { DWORD dwType = *(LPDWORD)( ptrExtra ); LPBYTE pPtr = *(LPBYTE*)( ptrExtra + 1 ); DWORD dwSize = *(LPDWORD)( ptrExtra + 2 ); // Zero means NULL terminated if ( dwSize == 0 && pPtr != NULL ) dwSize = strlen( (LPCTSTR)pPtr ); // Add packet data block pNc->Tx()->AddPacketData( dwType, pPtr, dwSize ); ptrExtra += 3; } // end try RULIB_CATCH_ALL { return FALSE; } } // end for // Make it official return pNc->Tx()->EndPacket(); }