void ParseInteractiveLine(OSCbuf *buf, char *mesg) { char *messageName, *token, *p; typedArg args[MAX_ARGS]; int thisArg; p = mesg; while (isspace(*p)) p++; if (*p == '\0') return; messageName = p; if (strcmp(messageName, "play\n") == 0) { /* Special kludge feature to save typing */ typedArg arg; if (OSC_openBundle(buf, OSCTT_Immediately())) { complain("Problem opening bundle: %s\n", OSC_errorMessage); return; } arg.type = INT; arg.datum.i = 0; WriteMessage(buf, "/voices/0/tp/timbre_index", 1, &arg); arg.type = FLOAT; arg.datum.i = 0.0f; WriteMessage(buf, "/voices/0/tm/goto", 1, &arg); if (OSC_closeBundle(buf)) { complain("Problem closing bundle: %s\n", OSC_errorMessage); } return; } while (!isspace(*p) && *p != '\0') p++; if (isspace(*p)) { *p = '\0'; p++; } thisArg = 0; while (*p != '\0') { /* flush leading whitespace */ while (isspace(*p)) p++; if (*p == '\0') break; if (*p == '"') { /* A string argument: scan for close quotes */ p++; args[thisArg].type = STRING; args[thisArg].datum.s = p; while (*p != '"') { if (*p == '\0') { complain("Unterminated quote mark: ignoring line\n"); return; } p++; } *p = '\0'; p++; } else { token = p; while (!isspace(*p) && (*p != '\0')) p++; if (isspace(*p)) { *p = '\0'; p++; } args[thisArg] = ParseToken(token); } thisArg++; if (thisArg >= MAX_ARGS) { complain("Sorry, your message has more than MAX_ARGS (%d) arguments; ignoring the rest.\n", MAX_ARGS); break; } } if (WriteMessage(buf, messageName, thisArg, args) != 0) { complain("Problem sending message: %s\n", OSC_errorMessage); } }
int main(int argc, char *argv[]) { GOOGLE_PROTOBUF_VERIFY_VERSION; const std::string strPipeIn("\\\\.\\pipe\\HekatePipeInbound"); const std::string strPipeOut("\\\\.\\pipe\\HekatePipeOutbound"); std::cout << "Starting pipe connections.\n"; HANDLE hPipeIn = CreateFileA(strPipeIn.c_str(), GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, nullptr); if (hPipeIn == INVALID_HANDLE_VALUE) { std::cerr << "Could not open " << strPipeIn << "Error = 0x" << std::hex << GetLastError() << std::endl; exit(-1); } HANDLE hPipeOut = CreateFileA(strPipeOut.c_str(), GENERIC_READ, 0, nullptr, OPEN_EXISTING, 0, nullptr); if (hPipeOut == INVALID_HANDLE_VALUE) { std::cerr << "Could not open " << strPipeOut << std::endl << "Error = 0x" << std::hex << GetLastError() << std::endl; exit(-1); } std::cout << "Pipes connected. Changing read mode." << std::endl; DWORD dwMode = PIPE_READMODE_MESSAGE; BOOL bRet = SetNamedPipeHandleState(hPipeOut, &dwMode, nullptr, nullptr); if (bRet != 0) { std::cerr << "Could not change read mode on " << strPipeOut << "Error = 0x" << std::hex << GetLastError() << std::endl; exit(-1); } std::cout << "Creating read loop thread." << std::endl; DWORD dwThreadId = 0; HANDLE hThread = CreateThread(nullptr, 0, ReadLoop, (LPVOID)hPipeOut, 0, &dwThreadId); if (hThread == INVALID_HANDLE_VALUE) { std::cerr << "Could not create read loop thread." << std::endl << "Error = 0x" << std::hex << GetLastError() << std::endl; exit(-1); } std::cout << "Created read thread." << std::endl; WriteMessage(hPipeIn, Hekate::Protobuf::Message::HekateClientMessageBuilder::CreateAddHookMessage("send")); WriteMessage(hPipeIn, Hekate::Protobuf::Message::HekateClientMessageBuilder::CreateAddHookMessage("sendto")); WriteMessage(hPipeIn, Hekate::Protobuf::Message::HekateClientMessageBuilder::CreateAddHookMessage("WSASend")); WriteMessage(hPipeIn, Hekate::Protobuf::Message::HekateClientMessageBuilder::CreateAddHookMessage("WSASendTo")); WriteMessage(hPipeIn, Hekate::Protobuf::Message::HekateClientMessageBuilder::CreateAddHookMessage("recv")); WriteMessage(hPipeIn, Hekate::Protobuf::Message::HekateClientMessageBuilder::CreateAddHookMessage("recvfrom")); WriteMessage(hPipeIn, Hekate::Protobuf::Message::HekateClientMessageBuilder::CreateAddHookMessage("WSARecv")); WriteMessage(hPipeIn, Hekate::Protobuf::Message::HekateClientMessageBuilder::CreateAddHookMessage("WSARecvFrom")); WaitForSingleObject(hThread, INFINITE); std::cout << std::endl << "Exiting." << std::endl; CloseHandle(hPipeIn); CloseHandle(hPipeOut); google::protobuf::ShutdownProtobufLibrary(); return 0; }
bool BTCtcp::SendMsg_Verack(void) { BTCMessage msgVerack(btcmsg_verack, BTC_TestNetwork); // construct message with "verack" command // no payload return WriteMessage(msgVerack); }
void TypeError(){ WriteIndicator(GetCurrentColumn()); WriteMessage("Conflicting Types"); exit(1); }
int main() { WSADATA wsaData; struct addrinfo *result = NULL, *ptr = NULL, hints; int recvbuflen = DEFAULT_BUFLEN; int iResult; iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); // Initialize Winsock. if(iResult != 0) { printf("WSAStartup failed with error: %d\n", iResult); return 1; } ZeroMemory(&hints, sizeof(hints)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; iResult = getaddrinfo(NULL, DEFAULT_PORT, &hints, &result); // Resolve the server address and port if(iResult != 0) { printf("getaddrinfo failed with error: %d\n", iResult); WSACleanup(); return 1; } for(ptr = result; ptr != NULL; ptr = ptr->ai_next) // Attempt to connect to an address until one succeeds. { ConnectSocket = socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol); // Create a SOCKET for connecting to server. if(ConnectSocket == INVALID_SOCKET) { printf("socket failed with error: %ld\n", WSAGetLastError()); WSACleanup(); return 1; } iResult = connect(ConnectSocket, ptr->ai_addr, (int)ptr->ai_addrlen); // Connect to server. if(iResult == SOCKET_ERROR) { closesocket(ConnectSocket); ConnectSocket = INVALID_SOCKET; continue; } break; } freeaddrinfo(result); if(ConnectSocket == INVALID_SOCKET) { printf("Unable to connect to server!\n"); WSACleanup(); return 1; } else std::cout << "Server connection established." << std::endl; std::cout << "Sending confirmation message to server." << std::endl; char sendbuf[] = "CONFIRM CONNECTION!"; iResult = send(ConnectSocket, sendbuf, strlen(sendbuf), 0); // Send an initial buffer. if(iResult == SOCKET_ERROR) { printf("SEND failed with error: %d\n", WSAGetLastError()); closesocket(ConnectSocket); WSACleanup(); return 1; } else std::cout << "Confirmation message was successfull." << std::endl; std::thread receive(ReceiveMessages, ConnectSocket); // Start thread for receiving messages. receive.detach(); while(WriteMessage() == true && receiving); // Send messages to server. shutdown(ConnectSocket, SD_SEND); closesocket(ConnectSocket); WSACleanup(); std::cout << "--- CLOSING GAME ---" << std::endl; std::this_thread::sleep_for(std::chrono::seconds(5)); return 0; }
nsresult nsOutlookMail::ImportMailbox( PRUint32 *pDoneSoFar, PRBool *pAbort, PRInt32 index, const PRUnichar *pName, nsIFile *pDest, PRInt32 *pMsgCount) { if ((index < 0) || (index >= m_folderList.GetSize())) { IMPORT_LOG0( "*** Bad mailbox identifier, unable to import\n"); *pAbort = PR_TRUE; return( NS_ERROR_FAILURE); } PRInt32 dummyMsgCount = 0; if (pMsgCount) *pMsgCount = 0; else pMsgCount = &dummyMsgCount; CMapiFolder *pFolder = m_folderList.GetItem( index); OpenMessageStore( pFolder); if (!m_lpMdb) { IMPORT_LOG1( "*** Unable to obtain mapi message store for mailbox: %S\n", pName); return( NS_ERROR_FAILURE); } if (pFolder->IsStore()) return( NS_OK); nsresult rv; nsOutlookCompose compose; SimpleBufferTonyRCopiedTwice copy; copy.Allocate( kCopyBufferSize); // now what? CMapiFolderContents contents( m_lpMdb, pFolder->GetCBEntryID(), pFolder->GetEntryID()); BOOL done = FALSE; ULONG cbEid; LPENTRYID lpEid; ULONG oType; LPMESSAGE lpMsg = nsnull; int attachCount; ULONG totalCount; PRFloat64 doneCalc; nsCString fromLine; int fromLen; PRBool lostAttach = PR_FALSE; nsCOMPtr<nsIOutputStream> destOutputStream; rv = NS_NewLocalFileOutputStream(getter_AddRefs(destOutputStream), pDest, -1, 0600); NS_ENSURE_SUCCESS(rv, rv); while (!done) { if (!contents.GetNext( &cbEid, &lpEid, &oType, &done)) { IMPORT_LOG1( "*** Error iterating mailbox: %S\n", pName); return( NS_ERROR_FAILURE); } totalCount = contents.GetCount(); doneCalc = *pMsgCount; doneCalc /= totalCount; doneCalc *= 1000; if (pDoneSoFar) { *pDoneSoFar = (PRUint32) doneCalc; if (*pDoneSoFar > 1000) *pDoneSoFar = 1000; } if (!done && (oType == MAPI_MESSAGE)) { if (!m_mapi.OpenMdbEntry( m_lpMdb, cbEid, lpEid, (LPUNKNOWN *) &lpMsg)) { IMPORT_LOG1( "*** Error opening messages in mailbox: %S\n", pName); return( NS_ERROR_FAILURE); } CMapiMessage msg( lpMsg); BOOL bResult = msg.FetchHeaders(); if (bResult) bResult = msg.FetchBody(); if (bResult) fromLine = msg.GetFromLine( fromLen); attachCount = msg.CountAttachments(); BuildAttachments( msg, attachCount); if (!bResult) { IMPORT_LOG1( "*** Error reading message from mailbox: %S\n", pName); return( NS_ERROR_FAILURE); } // -------------------------------------------------------------- compose.SetBody( msg.GetBody()); // Need to convert all headers to unicode (for i18n). // Init header here since 'composes' is used for all msgs. compose.SetHeaders(""); nsAutoString newheader; nsCAutoString tempCStr(msg.GetHeaders(), msg.GetHeaderLen()); rv = nsMsgI18NConvertToUnicode(nsMsgI18NFileSystemCharset(), tempCStr, newheader); NS_ASSERTION(NS_SUCCEEDED(rv), "failed to convert headers to utf8"); if (NS_SUCCEEDED(rv)) compose.SetHeaders(NS_ConvertUTF16toUTF8(newheader).get()); compose.SetAttachments( &m_attachments); // See if it's a drafts folder. Outlook doesn't allow drafts // folder to be configured so it's ok to hard code it here. nsAutoString folderName(pName); nsMsgDeliverMode mode = nsIMsgSend::nsMsgDeliverNow; mode = nsIMsgSend::nsMsgSaveAsDraft; if ( folderName.LowerCaseEqualsLiteral("drafts") ) mode = nsIMsgSend::nsMsgSaveAsDraft; /* If I can't get no headers, I can't get no satisfaction */ if (msg.GetHeaderLen()) { nsCAutoString cType; SetDefaultContentType(msg, cType); nsCOMPtr<nsIFile> compositionFile; rv = compose.SendTheMessage(mode, cType, getter_AddRefs(compositionFile)); if (NS_SUCCEEDED( rv)) { rv = compose.CopyComposedMessage( fromLine, compositionFile, destOutputStream, copy); DeleteFile( compositionFile); if (NS_FAILED( rv)) { IMPORT_LOG0( "*** Error copying composed message to destination mailbox\n"); return( rv); } (*pMsgCount)++; } } else rv = NS_OK; // The following code to write msg to folder when compose.SendTheMessage() fails is commented // out for now because the code doesn't handle attachments and users will complain anyway so // until we fix the code to handle all kinds of msgs correctly we should not even make users // think that all msgs are imported ok. This will also help users to identify which msgs are // not imported and help to debug the problem. #if 0 if (NS_FAILED( rv)) { /* NS_PRECONDITION( FALSE, "Manual breakpoint"); */ IMPORT_LOG1( "Message #%d failed.\n", (int) (*pMsgCount)); DumpAttachments(); // -------------------------------------------------------------- // This is the OLD way of writing out the message which uses // all kinds of crufty old crap for attachments. // Since we now use Compose to send attachments, // this is only fallback error stuff. // Attachments get lost. if (attachCount) { lostAttach = PR_TRUE; attachCount = 0; } BOOL needsTerminate = FALSE; if (!WriteMessage( destOutputStream, &msg, attachCount, &needsTerminate)) { IMPORT_LOG0( "*** Error writing message\n"); *pAbort = PR_TRUE; return( NS_ERROR_FAILURE); } if (needsTerminate) { if (!WriteMimeBoundary( destOutputStream, &msg, TRUE)) { IMPORT_LOG0( "*** Error writing message mime boundary\n"); *pAbort = PR_TRUE; return( NS_ERROR_FAILURE); } } } #endif // Just for YUCKS, let's try an extra endline WriteData( destOutputStream, "\x0D\x0A", 2); } } return( NS_OK); }