// Log an error from an XML node. This kind of error is quite frequent, // as the chat is processing many XMPP stanzas. void ErrorLog_AddNewMessage(PSZAC pszErrorContext, const CXmlNode * pXmlNodeError) { Assert(pszErrorContext != NULL); CBin binError; binError.BinAppendStringWithNullTerminator(pszErrorContext); binError.BinAppendXmlNode(pXmlNodeError); binError.BinAppendNullTerminator(); g_arraypErrors.AddError_UI(IN &binError); }
// Generic function to log an error void ErrorLog_AddNewMessage(PSZAC pszErrorContext, PSZUC pszErrorDetails) { Assert(pszErrorContext != NULL); if (pszErrorDetails == NULL) pszErrorDetails = c_szuEmpty; CBin binError; binError.BinAppendStringWithNullTerminator(pszErrorContext); binError.BinAppendStringWithNullTerminator((PSZAC)pszErrorDetails); g_arraypErrors.AddError_UI(IN &binError); }
void OSocketWeb::SL_Connected() { m_eSocketState = eSocketState_WaitingForHandshake; MessageLog_AppendTextFormatCo(d_coBlue, "WebSocket connected $s\n", isValid() ? "valid" : "INVALID"); SHashSha1 hashNonce; HashSha1_InitRandom(OUT &hashNonce); CBin bin; bin.BinAppendText_VE( "GET / HTTP/1.1\r\n" "Upgrade: websocket\r\n" "Connection: Upgrade\r\n" "Sec-WebSocket-Key: {h/}\r\n" "Sec-WebSocket-Version: 13\r\n\r\n", &hashNonce); MessageLog_AppendTextFormatCo(d_coGoldenRod, "Writing:\n$B", &bin); write(bin.PszaGetUtf8NZ(), bin.CbGetData()); }
String^ Panel1::CurrentDirectory::get() { CBin bin; FarPanelDirectory* arg = (FarPanelDirectory*)bin.Data(); arg->StructSize = sizeof(FarPanelDirectory); for(;;) { //_120325_180317 build 2556 - 0 if OPIF_SHORTCUT is not set size_t size = Info.PanelControl(_handle, FCTL_GETPANELDIRECTORY, bin.Size(), arg); if (0 == size) return String::Empty; if (!bin(size)) break; arg = (FarPanelDirectory*)bin.Data(); arg->StructSize = sizeof(FarPanelDirectory); } return gcnew String(arg->Name); }
void WLayoutApplicationMayanX::SaveUsersDocument(const CXmlNode * pXmlNodeGetDocument){ QFileDialog dialog; dialog.setFileMode(QFileDialog::Directory); if(dialog.exec()) { QString dirname= dialog.selectedFiles().first(); if( !dirname.isNull() ) { if (pXmlNodeGetDocument == NULL) return; if (pXmlNodeGetDocument != NULL) { CBin file; file.BinAppendBinaryDataFromBase64Szv(pXmlNodeGetDocument->PszuFindElementOrAttributeValue("DocData")); CString sDocName = pXmlNodeGetDocument->PszuFindElementOrAttributeValue("DocName"); QString filename=QString(sDocName); file.BinFileWriteE(dirname+"/"+filename); } } } }
void WLayoutApplicationMayanX::SL_ButtonUploadADocument() { QFileDialog dialog; dialog.setFileMode(QFileDialog::AnyFile); if(dialog.exec()) { if(!dialog.selectedFiles().isEmpty()) { QString pathToFile=dialog.selectedFiles().first(); QString name= pathToFile.split("/").last(); CBin binFile; binFile.BinFileReadE(pathToFile); CInternetRequestWebMethodXmlMayanX oRequest("UploadADocument"); oRequest.BinAppendXmlElementText("eType", (PSZUC)"1"); oRequest.BinAppendXmlElementText("sDocID", (PSZUC)"F83CK23"); oRequest.BinAppendXmlElementText("sDocName", (PSZUC)name.toStdString().c_str()); oRequest.BinAppendXmlElementBinaryBase64("bDocData", binFile); m_oInternetServer.RequestSend(&oRequest); } } }
void WLayoutApplicationMayanX::SL_SocketMessage(CBin & binszvFrameData) { PSZUC pszFrameData = binszvFrameData.PbGetData(); PSZR pszrEvent = PszrStringContainsSubString(pszFrameData, "Event\":"); if (pszrEvent == NULL) return; //MessageLog_AppendTextFormatCo(d_coBlue, "Transaction message: $s\n", pszFrameData); int eEvent = atoi((const char *)pszrEvent); if (eEvent != 5) return; // If the event is not a transaction, ignore it PSZR pszrSubstring = PszrStringContainsSubString(pszFrameData, "\\\"P\\\":"); if (pszrSubstring != NULL) { SStringToNumber stn; InitToGarbage(OUT &stn, sizeof(stn)); stn.uFlags = STN_mskfNoLeadingSpaces | STN_mskfNoSkipTailingSpaces | STN_mskfAllowRandomTail | STN_mskfAllowHexPrefix | STN_mskfMustHaveDigits | STN_mskfUnsignedInteger; stn.pszuSrc = pszrSubstring; if (FStringToNumber(INOUT &stn)) { if (stn.u.nData > m_nPriceMax) { m_nPriceMax = stn.u.nData; if (m_nPriceMin == 0) m_nPriceMin = m_nPriceMax; } if (stn.u.nData < m_nPriceMin) m_nPriceMin = stn.u.nData; m_pwLabelPriceLast->Label_SetTextFormat_VE_Gsb("Last price: $I (min=$I, max=$I)", stn.u.nData, m_nPriceMin, m_nPriceMax); if (stn.u.nData > m_nPriceLast) m_pwLabelPriceLast->setStyleSheet("color: green"); else m_pwLabelPriceLast->Label_SetTextColorError(); m_nPriceLast = stn.u.nData; //MessageLog_AppendTextFormatCo(d_coBlue, "WebSocket Price: $I\n", stn.u.nData); } } }
void WLayoutApplicationMayanX::SL_InternetRequestCompleted(QNetworkReply * poNetworkReply) { CInternetResponseWebMethodXmlSoap oInternetResponse(poNetworkReply); // First of all, check if there is an error from the server CXmlNode * pXmlNodeError = oInternetResponse.PGetXmlNodeError(); if (pXmlNodeError != NULL) { MessageLog_AppendTextFormatSev(eSeverityErrorWarning, "SL_InternetRequestCompleted() with the following error:\n^N", pXmlNodeError); int nCode = pXmlNodeError->NFindElementOrAttributeValueNumeric("nCode"); if (nCode == eCodeUserNotFound) { // The user is not found or does not exist, therefore clear the m_strxUserID so we may retry m_pApplication->m_strxUserID.Empty(); } if (nCode == eCodeUserAlreadyExist) { // The user already exists, so fetch the xUserID from the m_pApplication->m_strxUserID = pXmlNodeError->PszuFindElementValue("xDescriptionParam"); SL_ExchangeLogin(); // Attempt to login again } return; } CXmlNode * pXmlNode = oInternetResponse.PGetXmlNodeResponse("UserRegister"); if (pXmlNode != NULL) { m_pApplication->m_strxUserID = pXmlNode->m_pszuTagValue; if (!m_pApplication->m_strxUserID.FIsEmptyString()) SL_ExchangeLogin(); // Attempt to login with the new UserID. else EMessageBoxWarning("The API 'UserRegister' returned an invalid UserID of value '$S'", &m_pApplication->m_strxUserID); return; } pXmlNode = oInternetResponse.PGetXmlNodeResponse("UserLogin"); if (pXmlNode != NULL) { CBin binChallenge; binChallenge.BinAppendBinaryDataFromBase64Szv(pXmlNode->PszuFindElementValue("bChallenge")); if (!binChallenge.FIsEmptyBinary()) { // We received a challenge, so respond to it now CBin binResponseData = m_pApplication->m_pProfileParent->m_strKeyPublic; binResponseData.BinAppendCBin(binChallenge); //MessageLog_AppendTextFormatCo(d_coBlue, " bIdentity: {B/}\n bChallenge: {B/}\n bIdentity + bChallenge: {B/}\n", &m_pTreeItemParent->m_binKeyPublic, &binChallenge, &binResponseData); binResponseData.BinHashToMd5(); CInternetRequestWebMethodXmlMayanX oRequest("UserLogin"); oRequest.BinAppendXmlElementText("xUserID", m_pApplication->m_strxUserID); oRequest.BinAppendXmlElementBinaryBase64("bResponse", binResponseData); m_oInternetServer.RequestSend(&oRequest); return; } if (m_oInternetServer.m_strxSessionID.FIsEmptyString()) { m_oInternetServer.m_strxSessionID = pXmlNode->PszuFindElementValue("xSessionID"); //m_oInternetServer.m_strxSessionID = (PSZUC)"as8323jas932e"; if (!m_oInternetServer.m_strxSessionID.FIsEmptyString()) { MessageLog_AppendTextFormatCo(d_coBlue, "Login successful: xSessionID = $S\n", &m_oInternetServer.m_strxSessionID); OLayoutHorizontal * poLayoutOrder = new OLayoutHorizontal((QWidget *)NULL); m_poLayoutButtons->addRow(poLayoutOrder); m_pwEditQuantity = new WEditNumber; poLayoutOrder->Layout_AddLabelAndWidgetH_PA("Quantity:", m_pwEditQuantity); m_pwEditPrice = new WEditNumber; poLayoutOrder->Layout_AddLabelAndWidgetH_PA("Price:", m_pwEditPrice); WButtonTextWithIcon * pwButton = new WButtonTextWithIcon("Place Order", eMenuIcon_Bitcoin); // eMenuIconCoffeeBuy); poLayoutOrder->addWidget(pwButton); poLayoutOrder->addWidget(PA_CHILD new QWidget, 1); connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonUserOrderAdd())); //Updating user balance OLayoutHorizontal * poLayoutUserBalance = new OLayoutHorizontal((QWidget *)NULL); m_poLayoutButtons->addRow(poLayoutUserBalance); m_pwEditUpdateBalanceQuantity = new WEditNumber; m_pwEditUpdateBalanceUserId = new WEditNumber; poLayoutUserBalance->Layout_AddLabelAndWidgetH_PA("User Id:", m_pwEditUpdateBalanceUserId); poLayoutUserBalance->Layout_AddLabelAndWidgetH_PA("Quantity:", m_pwEditUpdateBalanceQuantity); m_pwLabelBalance=new WLabel; pwButton = new WButtonTextWithIcon("Update Balance", eMenuIcon_Bitcoin); // eMenuIconCoffeeBuy); poLayoutUserBalance->addWidget(pwButton); poLayoutUserBalance->addWidget(m_pwLabelBalance); poLayoutUserBalance->addWidget(PA_CHILD new QWidget, 1); connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonUserBalanceUpdate())); //Cancel an Order OLayoutHorizontal * poLayoutCancelAnOrder = new OLayoutHorizontal((QWidget *)NULL); m_poLayoutButtons->addRow(poLayoutCancelAnOrder); m_pwEditIdToCancelOrder = new WEditNumber; poLayoutCancelAnOrder->Layout_AddLabelAndWidgetH_PA("Id:", m_pwEditIdToCancelOrder); pwButton = new WButtonTextWithIcon("Cancel Order", eMenuIcon_Bitcoin); // eMenuIconCoffeeBuy); poLayoutCancelAnOrder->addWidget(pwButton); poLayoutCancelAnOrder->addWidget(PA_CHILD new QWidget, 1); connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonUserOrderCancel())); //Update an Order OLayoutHorizontal * poLayoutUpdateAnOrder = new OLayoutHorizontal((QWidget *)NULL); m_poLayoutButtons->addRow(poLayoutUpdateAnOrder); m_pwEditIdToUpdateOrder = new WEditNumber; poLayoutUpdateAnOrder->Layout_AddLabelAndWidgetH_PA("Id:", m_pwEditIdToUpdateOrder); m_pwEditPriceToUpdateOrder = new WEditNumber; poLayoutUpdateAnOrder->Layout_AddLabelAndWidgetH_PA("Price:", m_pwEditPriceToUpdateOrder); m_pwEditQuantityToUpdateOrder = new WEditNumber; poLayoutUpdateAnOrder->Layout_AddLabelAndWidgetH_PA("Quantity:", m_pwEditQuantityToUpdateOrder); pwButton = new WButtonTextWithIcon("Update Order", eMenuIcon_Bitcoin); // eMenuIconCoffeeBuy); poLayoutUpdateAnOrder->addWidget(pwButton); poLayoutUpdateAnOrder->addWidget(PA_CHILD new QWidget, 1); connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonUserOrderUpdate())); //Update User's Account OLayoutHorizontal* poLayoutUpdateUsersAccount = new OLayoutHorizontal((QWidget *)NULL); m_poLayoutButtons->addRow(poLayoutUpdateUsersAccount); m_pwEditUpdateAccountId=new WEditNumber; m_pwEditUpdateAccountName = new WEdit; m_pwEditUpdateAccountRole = new WEditNumber; poLayoutUpdateUsersAccount->Layout_AddLabelAndWidgetH_PA("User Id:", m_pwEditUpdateAccountId); poLayoutUpdateUsersAccount->Layout_AddLabelAndWidgetH_PA("User Name:", m_pwEditUpdateAccountName); poLayoutUpdateUsersAccount->Layout_AddLabelAndWidgetH_PA("User Role:", m_pwEditUpdateAccountRole); pwButton = new WButtonTextWithIcon("Update User Account", eMenuIcon_Bitcoin); // eMenuIconCoffeeBuy); poLayoutUpdateUsersAccount->addWidget(pwButton); poLayoutUpdateUsersAccount->addWidget(PA_CHILD new QWidget, 1); connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonUserAccountUpdate())); //Get User's Document OLayoutHorizontal* poLayoutUserDocuments = new OLayoutHorizontal((QWidget *)NULL); m_poLayoutButtons->addRow(poLayoutUserDocuments); m_pwEditGetUserDocumentId=new WEditNumber; poLayoutUserDocuments->Layout_AddLabelAndWidgetH_PA("Document Id:", m_pwEditGetUserDocumentId); pwButton = new WButtonTextWithIcon("Get Document", eMenuIcon_Bitcoin); // eMenuIconCoffeeBuy); poLayoutUserDocuments->addWidget(pwButton); poLayoutUserDocuments->addWidget(PA_CHILD new QWidget, 1); connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonUserDocumentGet())); //Buttons to Fetch Data OLayoutHorizontal* poLayoutFetchData = new OLayoutHorizontal((QWidget *)NULL); m_poLayoutButtons->addRow(poLayoutFetchData); //Fetching User's Balances pwButton = new WButtonTextWithIcon("Fetch User's' Balances", eMenuIcon_Bitcoin); // eMenuIconCoffeeBuy); poLayoutFetchData->addWidget(pwButton); connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonFetchUserBalances())); //Fetching Users pwButton = new WButtonTextWithIcon("Fetch Users", eMenuIcon_Bitcoin); // eMenuIconCoffeeBuy); poLayoutFetchData->addWidget(pwButton); connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonFetchUsers())); //Fetching User's Documents pwButton = new WButtonTextWithIcon("Fetch User's Documents", eMenuIcon_Bitcoin); // eMenuIconCoffeeBuy); poLayoutFetchData->addWidget(pwButton); connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonFetchUserDocuments())); //Upload a Document pwButton = new WButtonTextWithIcon("Upload a Document...", eMenuIcon_Bitcoin); // eMenuIconCoffeeBuy); poLayoutFetchData->addWidget(pwButton); connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonUploadADocument())); poLayoutFetchData->addWidget(PA_CHILD new QWidget, 1); /* // We have a valid Session ID, so we may download the bids. For this, we will display a new button WButtonTextWithIcon * pwButton = new WButtonTextWithIcon("Download Market Bids", eMenuIconCoffeeBuy); m_poLayoutButtons->addRow(pwButton); connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonDownloadMarketBids())); */ m_pwLabelWelcome->hide(); m_pwButtonRegister->hide(); DisplayOrders(0); DisplayUserBalances(0); } } return; } // if (UserLogin) pXmlNode = oInternetResponse.PGetXmlNodeResponse("UserOrderAdd"); if (pXmlNode != NULL) { DisplayOrders(pXmlNode); DisplayMarketOrders(pXmlNode); // Also add the new order to the Market Orders return; } pXmlNode = oInternetResponse.PGetXmlNodeResponse("UserOrders"); if (pXmlNode != NULL) { DisplayOrders(pXmlNode); return; } pXmlNode = oInternetResponse.PGetXmlNodeResponse("MarketOrders"); if (pXmlNode != NULL) { DisplayMarketOrders(pXmlNode); return; } pXmlNode = oInternetResponse.PGetXmlNodeResponse("UserBalanceUpdate"); if (pXmlNode != NULL) { DisplayUserBalanceUpdated(pXmlNode); return; } pXmlNode = oInternetResponse.PGetXmlNodeResponse("FetchUserBalances"); if (pXmlNode != NULL) { MessageLog_AppendTextFormatCo(d_coRed, "Fetching user balances\n\n"); DisplayUserBalances(pXmlNode); return; } pXmlNode = oInternetResponse.PGetXmlNodeResponse("FetchUsers"); if (pXmlNode != NULL) { MessageLog_AppendTextFormatCo(d_coRed, "Fetching all users\n\n"); DisplayUsers(pXmlNode); return; } pXmlNode = oInternetResponse.PGetXmlNodeResponse("UserAccountUpdate"); if (pXmlNode != NULL) { MessageLog_AppendTextFormatCo(d_coRed, "updating user account\n\n"); DisplayUserAccountUpdate(pXmlNode); return; } pXmlNode = oInternetResponse.PGetXmlNodeResponse("UserDocuments"); if (pXmlNode != NULL) { MessageLog_AppendTextFormatCo(d_coRed, "getting all user's documents\n\n"); DisplayAllUsersDocuments(pXmlNode); return; } pXmlNode = oInternetResponse.PGetXmlNodeResponse("UserDocumentGet"); if (pXmlNode != NULL) { MessageLog_AppendTextFormatCo(d_coRed, "getting all user's documents\n\n"); SaveUsersDocument(pXmlNode); return; } pXmlNode = oInternetResponse.PGetXmlNodeResponse("UserOrderUpdate"); if (pXmlNode != NULL) { UserOrderUpdate(pXmlNode); return; } pXmlNode = oInternetResponse.PGetXmlNodeResponse("UserOrderCancel"); if (pXmlNode != NULL) { UserOrderCancel(pXmlNode); return; } } // SL_InternetRequestCompleted()
oexUINT CBin::GroupAvg( oexINT nType, oexUINT uOffset, oexUINT uInterval, oexUINT uGroups, CBin &bin, oexINT nFlags ) { // Sanity check if ( 0 >= uGroups || !getUsed() ) return 0; // Get skip value oexUINT uSkip = nFlags & 0x0f; if ( uSkip >= uGroups ) uSkip = 0; // Get element size oexUINT uESize = obj::StaticSize( nType ); if ( !uESize ) return 0; // Total samples oexUINT uSamples = getUsed() / uESize; if ( uSamples < uInterval ) return 0; // How many samples per group oexUINT nSamplesPerGroup = ( uInterval - uSkip ) / ( uGroups - uSkip ); if ( !nSamplesPerGroup ) return 0; // Allocate memory oexUINT uBytes = uGroups * uESize; if ( bin.Size() < uBytes ) if ( !bin.Allocate( uBytes ) ) return oexFALSE; // Allocate an array to hold the counts TMem< oexUINT > aCnts; if ( !aCnts.OexNew( uGroups ).Ptr() ) return oexFALSE; // Memory to hold acc TMem< oexLONGDOUBLE > aAcc; if ( !aAcc.OexNew( uGroups ).Ptr() ) return oexFALSE; // Initialize group averages for ( oexUINT i = 0; i < uGroups; i++ ) aAcc[ i ] = 0, aCnts[ i ] = 0; // Accumulate all samples while( ( uOffset + uInterval ) < uSamples ) { // Accumulate samples in this interval for ( oexUINT s = 0; s < uInterval; s++ ) { // Get the value oexLONGDOUBLE dV; switch( nType ) { case obj::tInt : dV = getINT( uOffset + s ); break; case obj::tFloat : dV = getFLOAT( uOffset + s ); break; case obj::tDouble : dV = getDOUBLE( uOffset + s ); break; default : dV = 0; } // end switch // Range check and add // if ( 1000000 > oex::cmn::Abs( dV ) && .0000001 < oex::cmn::Abs( dV ) ) if ( s < uSkip ) aAcc[ s ] = dV, aCnts[ s ]++; else { oexUINT o = uSkip + s / nSamplesPerGroup; if ( o >= uGroups ) o = uGroups - 1; aAcc[ o ] += dV; aCnts[ o ]++; } // end else } // end for uOffset += uInterval; } // end while // Calculate averages switch( nType ) { case obj::tInt : for ( oexUINT g = 0; g < uGroups; g++ ) bin.setINT( g, aCnts[ g ] ? oexINT( aAcc[ g ] / aCnts[ g ] ) : 0 ); break; case obj::tFloat : for ( oexUINT g = 0; g < uGroups; g++ ) bin.setFLOAT( g, aCnts[ g ] ? oexFLOAT( aAcc[ g ] / aCnts[ g ] ) : 0 ); break; case obj::tDouble : for ( oexUINT g = 0; g < uGroups; g++ ) bin.setDOUBLE( g, aCnts[ g ] ? oexDOUBLE( aAcc[ g ] / aCnts[ g ] ) : 0 ); break; default : return 0; } // end switch // Number of bytes we used bin.setUsed( uBytes ); return uOffset; }