MsgRouting AwtChoice::WmNotify(UINT notifyCode) { if (notifyCode == CBN_SELCHANGE) { DoCallback("handleAction", "(I)V", SendMessage(CB_GETCURSEL)); } return mrDoDefault; }
void TestHttpClient::callback(struct mg_connection * conn, int event, void * data) { auto d = conn->mgr->user_data; auto p = reinterpret_cast<TestHttpClient*>(d); p->DoCallback(conn, event, data); }
MsgRouting AwtTextComponent::WmNotify(UINT notifyCode) { if (notifyCode == EN_CHANGE) { DoCallback("valueChanged", "()V"); } return mrDoDefault; }
void AwtMenuItem::DoCommand() { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); // peer is sun.awt.windows.WMenuItemPeer jobject peer = GetPeer(env); if (IsCheckbox()) { UINT nState = ::GetMenuState(GetMenuContainer()->GetHMenu(), GetID(), MF_BYCOMMAND); DASSERT(nState != 0xFFFFFFFF); DoCallback("handleAction", "(Z)V", ((nState & MF_CHECKED) == 0)); } else { DoCallback("handleAction", "(JI)V", TimeHelper::getMessageTimeUTC(), (jint)AwtComponent::GetJavaModifiers()); } }
int WebController::OnEventWsConnect(struct mg_connection *conn) { //if websocket /ws is param here //printf("event %d param: %s\n", ev, conn->uri); //We need to send something to the websocket DoCallback("KMotionX"); return MG_FALSE; }
/*---------------------------------------------------------------------- | PLT_ThreadTaskCallback::Callback +---------------------------------------------------------------------*/ NPT_Result PLT_ThreadTaskCallback::Callback() { // acquire global lock NPT_AutoLock lock(m_Lock); // invoke callback return DoCallback(); }
MsgRouting AwtCheckbox::WmNotify(UINT notifyCode) { if (notifyCode == BN_CLICKED) { BOOL fChecked = !GetState(); DoCallback("handleAction", "(Z)V", fChecked); } return mrDoDefault; }
MsgRouting AwtList::WmNotify(UINT notifyCode) { if (notifyCode == LBN_SELCHANGE || notifyCode == LBN_DBLCLK) { /* Fixed an asserion failure when clicking on an empty List. */ int nCurrentSelection = SendListMessage(LB_GETCURSEL); if (nCurrentSelection != LB_ERR && GetCount() > 0) { if (notifyCode == LBN_SELCHANGE) { DoCallback("handleListChanged", "(I)V", nCurrentSelection); } else if (notifyCode == LBN_DBLCLK) { DoCallback("handleAction", "(IJI)V", nCurrentSelection, TimeHelper::getMessageTimeUTC(), (jint)AwtComponent::GetJavaModifiers()); } } } return mrDoDefault; }
void AwtLabel::DoPaint(HDC hDC, RECT& r) { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); if ((r.right-r.left) > 0 && (r.bottom-r.top) > 0 && m_peerObject != NULL && m_callbacksEnabled) { if (env->EnsureLocalCapacity(3) < 0) return; long x,y; SIZE size; /* self is sun.awt.windows.WLabelPeer */ jobject self = GetPeer(env); DASSERT(self); /* target is java.awt.Label */ jobject target = env->GetObjectField(self, AwtObject::targetID); jobject font = GET_FONT(target, self); jstring text = (jstring)env->GetObjectField(target, AwtLabel::textID); size = AwtFont::getMFStringSize(hDC, font, text); ::SetTextColor(hDC, GetColor()); /* Redraw whole label to eliminate display noise during resizing. */ VERIFY(::GetClientRect(GetHWnd(), &r)); VERIFY(::FillRect (hDC, &r, GetBackgroundBrush())); y = (r.top + r.bottom - size.cy) / 2; jint alignment = env->GetIntField(target, AwtLabel::alignmentID); switch (alignment) { case java_awt_Label_CENTER: x = (r.left + r.right - size.cx) / 2; break; case java_awt_Label_RIGHT: x = r.right - 2 - size.cx; break; case java_awt_Label_LEFT: default: x = r.left + 2; break; } /* draw string */ if (isEnabled()) { AwtComponent::DrawWindowText(hDC, font, text, x, y); } else { AwtComponent::DrawGrayText(hDC, font, text, x, y); } DoCallback("handlePaint", "(IIII)V", r.left, r.top, r.right-r.left, r.bottom-r.top); env->DeleteLocalRef(target); env->DeleteLocalRef(font); env->DeleteLocalRef(text); } }
inline void AwtScrollbar::DoScrollCallbackCoalesce(const char* methodName, int newPos) { if (methodName == m_prevCallback && newPos == m_prevCallbackPos) { DTRACE_PRINTLN2("AwtScrollbar: ignoring duplicate callback %s(%d)", methodName, newPos); } else { DoCallback(methodName, "(I)V", newPos); m_prevCallback = methodName; m_prevCallbackPos = newPos; } }
BOOL CNetFile::EndThread(LPVOID pData) {_STT(); if ( m_hFile != NULL ) { InternetCloseHandle( m_hFile ); m_hFile = NULL; } // end if if ( m_hConnect != NULL ) { InternetCloseHandle( m_hConnect ); m_hConnect = NULL; } // end if if ( m_hInternet != NULL ) { InternetCloseHandle( m_hInternet ); m_hInternet = NULL; } // end if // Close file if needed if ( m_bCloseFileAfterDownload ) m_local.Close(); // Set pointer back to start of file else m_local.SetPtrPosBegin( 0 ); // Update download status if ( m_dwTransferError != 0 ) m_dwTransferStatus = NETFILE_DS_ERROR; m_dwTransferStatus = NETFILE_DS_DONE; // Lose upload buffers if ( m_bUpload ) { if ( m_pMem != NULL ) { delete m_pMem; m_pMem = NULL; } // end if m_dwMemSize = 0; } // end if // Post callback DoCallback( (WPARAM)m_dwTransferStatus, (LPARAM)this ); return TRUE; }
MsgRouting AwtTextComponent::WmNotify(UINT notifyCode) { if (notifyCode == EN_CHANGE) { /* * Ignore notifications if the text hasn't been changed. * EN_CHANGE sent on character formatting changes as well. */ if (m_bIgnoreEnChange == FALSE) { m_bCanUndo = TRUE; DoCallback("valueChanged", "()V"); } else { m_bCanUndo = FALSE; } } return mrDoDefault; }
/***************************************************************************\ * ShutdownConversation * * Description: * This function causes an imediate termination of the given conversation * and generates apropriate callbacks to notify the application. * * History: * 11-12-91 sanfords Created. \***************************************************************************/ VOID ShutdownConversation( PCONV_INFO pcoi, BOOL fMakeCallback) { CheckDDECritIn; if (pcoi->state & ST_CONNECTED) { pcoi->state &= ~ST_CONNECTED; if (IsWindow(pcoi->hwndPartner)) { PostMessage(pcoi->hwndPartner, WM_DDE_TERMINATE, (DWORD)pcoi->hwndConv, 0); } if (fMakeCallback && !(pcoi->pcii->afCmd & CBF_SKIP_DISCONNECTS)) { DoCallback(pcoi->pcii, (WORD)XTYP_DISCONNECT, 0, pcoi->hConv, 0, 0, 0, 0, (pcoi->state & ST_ISSELF) ? 1L : 0L); } MONCONV(pcoi, FALSE); } FreeConversationResources(pcoi); }
BOOL CNetFile::InitThread(LPVOID pData) {_STT(); // Verify open file if ( !m_local.IsOpen() && !m_bMem ) return FALSE; // Crack the url ZeroMemory( &m_cui, sizeof( m_cui ) ); CWinFile::CrackUrl( m_szUrl, &m_cui ); m_dwTransferError = 0; // Open internet handle m_dwTransferStatus = NETFILE_DS_INITIALIZING; // Don't know the length m_bGetTotalLength = FALSE; m_dwTotalLength = 0; // Post callback DoCallback( (WPARAM)m_dwTransferStatus, (LPARAM)this ); m_hInternet = InternetOpen( m_szUserAgent, m_dwAccessFlags, // INTERNET_OPEN_TYPE_DIRECT, // INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, m_dwInetFlags ); if ( m_hInternet == NULL ) { m_dwTransferStatus = NETFILE_DS_ERROR; m_dwTransferError = GetLastError(); DoCallback( (WPARAM)m_dwTransferStatus, (LPARAM)this ); return FALSE; } // end if if ( *m_szUsername != 0 || m_sHeaders.size() || m_sData.size() ) { if ( m_bUpload ) { DWORD dwPort = ( m_cui.dwPort != 0 ) ? m_cui.dwPort : INTERNET_DEFAULT_FTP_PORT; m_hConnect = InternetConnect( m_hInternet, m_cui.szHostName, (UINT)dwPort, m_szUsername, m_szPassword, INTERNET_SERVICE_FTP, m_bPassive ? INTERNET_FLAG_PASSIVE : 0, 0 ); } // end if else { DWORD dwPort = ( m_cui.dwPort != 0 ) ? m_cui.dwPort : INTERNET_DEFAULT_HTTP_PORT; m_hConnect = InternetConnect( m_hInternet, m_cui.szHostName, (UINT)dwPort, m_szUsername, m_szPassword, INTERNET_SERVICE_HTTP, 0, 0 ); } // end else if ( m_hConnect == NULL ) { m_dwTransferStatus = NETFILE_DS_ERROR; m_dwTransferError = GetLastError(); DoCallback( (WPARAM)m_dwTransferStatus, (LPARAM)this ); return FALSE; } // end if } // end if // Attempt to open the file m_dwTransferStatus = NETFILE_DS_CONNECTING; // Post callback DoCallback( (WPARAM)m_dwTransferStatus, (LPARAM)this ); if ( !m_bUpload ) { HINTERNET handle = m_hInternet; if ( m_hConnect != NULL ) handle = m_hConnect; if ( m_sHeaders.size() == 0 && m_sData.size() == 0 ) { m_hFile = InternetOpenUrl( handle, m_szUrl, NULL, 0, INTERNET_FLAG_TRANSFER_BINARY | m_dwOpenFlags, 0 ); if ( m_hFile == NULL ) { m_dwTransferStatus = NETFILE_DS_ERROR; m_dwTransferError = GetLastError(); DoCallback( (WPARAM)m_dwTransferStatus, (LPARAM)this ); return FALSE; } // end if } // end if else { CStr fname = m_cui.szUrlPath; DWORD dwData = m_sData.strlen(); LPCTSTR pData = m_sData; // Add variables to url if GET if ( !strcmpi( m_sMethod, "GET" ) ) { fname += "?"; fname += m_sData; pData = NULL; dwData = 0; } // end if // Accept whatever parameters came with the link else fname += m_cui.szExtraInfo; m_hFile = HttpOpenRequest( handle, m_sMethod, fname, NULL, NULL, NULL, INTERNET_FLAG_TRANSFER_BINARY | m_dwOpenFlags, 0 ); if ( m_hFile == NULL ) { m_dwTransferStatus = NETFILE_DS_ERROR; m_dwTransferError = GetLastError(); DoCallback( (WPARAM)m_dwTransferStatus, (LPARAM)this ); return FALSE; } // end if if ( !HttpSendRequest( m_hFile, m_sHeaders, m_sHeaders.strlen(), (LPVOID)pData, dwData ) ) { m_dwTransferStatus = NETFILE_DS_ERROR; m_dwTransferError = GetLastError(); DoCallback( (WPARAM)m_dwTransferStatus, (LPARAM)this ); return FALSE; } // end if } // end else // Want to know the length m_bGetTotalLength = TRUE; } // end if else { m_dwDataWritten = 0; if ( m_hConnect == NULL ) { m_hFile = InternetOpenUrl( m_hInternet, m_szUrl, NULL, 0, INTERNET_FLAG_TRANSFER_BINARY | m_dwOpenFlags, 0 ); } // end if else { DWORD i = 0; while( m_cui.szUrlPath[ i ] != 0 && ( m_cui.szUrlPath[ i ] == '\\' || m_cui.szUrlPath[ i ] == '/' ) ) i++; m_hFile = FtpOpenFile( m_hConnect, &m_cui.szUrlPath[ i ], GENERIC_WRITE, INTERNET_FLAG_TRANSFER_BINARY, 0 ); } // end else if ( m_hFile == NULL ) { m_dwTransferStatus = NETFILE_DS_ERROR; m_dwTransferError = GetLastError(); DoCallback( (WPARAM)m_dwTransferStatus, (LPARAM)this ); return FALSE; } // end if if ( !m_bMem ) { if ( m_pMem != NULL ) { delete m_pMem; m_pMem = NULL; } // end if m_dwMemSize = m_local.Size(); // Anything to upload? if ( m_dwMemSize == 0 ) return FALSE; // Allocate memory m_pMem = new BYTE[ m_dwMemSize + 1 ]; if ( m_pMem == NULL ) return FALSE; // Read in the data DWORD read = 0; if ( !m_local.Read( m_pMem, m_dwMemSize, &read ) || read != m_dwMemSize ) { m_dwTransferStatus = NETFILE_DS_ERROR; m_dwTransferError = GetLastError(); DoCallback( (WPARAM)m_dwTransferStatus, (LPARAM)this ); return FALSE; } // end if } // end if } // end else return TRUE; }
/***************************************************************************\ * _ClientEventCallback * * Description: * Called from the server side to perform event callbacks. * * History: * 11-12-91 sanfords Created. \***************************************************************************/ DWORD _ClientEventCallback( PCL_INSTANCE_INFO pcii, PEVENT_PACKET pep) { HDDEDATA hData; EnterDDECrit; switch (pep->EventType) { case 0: // MonitorFlags change event - everybody gets it pcii->MonitorFlags = pep->Data; break; case MF_CALLBACKS: { MONCBSTRUCT mcb; mcb = *((MONCBSTRUCT *)&pep->Data); mcb.hsz1 = NORMAL_HSZ_FROM_LATOM(GlobalToLocalAtom((GATOM)mcb.hsz1)); mcb.hsz2 = NORMAL_HSZ_FROM_LATOM(GlobalToLocalAtom((GATOM)mcb.hsz2)); if ( mcb.wType == XTYP_REGISTER || mcb.wType == XTYP_UNREGISTER) { mcb.hsz2 = INST_SPECIFIC_HSZ_FROM_LATOM((LATOM)mcb.hsz2); } hData = InternalCreateDataHandle(pcii, (LPSTR)&mcb, pep->cbEventData, 0, HDATA_NOAPPFREE | HDATA_READONLY | HDATA_EXECUTE, 0, 0); if (hData) { DoCallback(pcii, (WORD)XTYP_MONITOR, 0, 0, 0, 0, hData, 0L, pep->EventType); InternalFreeDataHandle((HDDEDATA)hData, TRUE); DeleteAtom(LATOM_FROM_HSZ(mcb.hsz1)); DeleteAtom(LATOM_FROM_HSZ(mcb.hsz2)); } } break; case MF_LINKS: { MONLINKSTRUCT ml; ml = *((MONLINKSTRUCT *)&pep->Data); ml.hszSvc = NORMAL_HSZ_FROM_LATOM(GlobalToLocalAtom((GATOM)ml.hszSvc)); ml.hszTopic = NORMAL_HSZ_FROM_LATOM(GlobalToLocalAtom((GATOM)ml.hszTopic)); ml.hszItem = NORMAL_HSZ_FROM_LATOM(GlobalToLocalAtom((GATOM)ml.hszItem)); hData = InternalCreateDataHandle(pcii, (LPSTR)&ml, pep->cbEventData, 0, HDATA_NOAPPFREE | HDATA_READONLY | HDATA_EXECUTE, 0, 0); if (hData) { DoCallback(pcii, (WORD)XTYP_MONITOR, 0, 0, 0, 0, hData, 0L, pep->EventType); InternalFreeDataHandle((HDDEDATA)hData, TRUE); DeleteAtom(LATOM_FROM_HSZ(ml.hszSvc)); DeleteAtom(LATOM_FROM_HSZ(ml.hszTopic)); DeleteAtom(LATOM_FROM_HSZ(ml.hszItem)); } } break; case MF_CONV: { MONCONVSTRUCT mc; mc = *((MONCONVSTRUCT *)&pep->Data); mc.hszSvc = NORMAL_HSZ_FROM_LATOM(GlobalToLocalAtom((GATOM)mc.hszSvc)); mc.hszTopic = NORMAL_HSZ_FROM_LATOM(GlobalToLocalAtom((GATOM)mc.hszTopic)); hData = InternalCreateDataHandle(pcii, (LPSTR)&mc, pep->cbEventData, 0, HDATA_NOAPPFREE | HDATA_READONLY | HDATA_EXECUTE, 0, 0); if (hData) { DoCallback(pcii, (WORD)XTYP_MONITOR, 0, 0, 0, 0, hData, 0L, pep->EventType); InternalFreeDataHandle((HDDEDATA)hData, TRUE); DeleteAtom(LATOM_FROM_HSZ(mc.hszSvc)); DeleteAtom(LATOM_FROM_HSZ(mc.hszTopic)); } } break; case MF_HSZ_INFO: if (!(pcii->flags & IIF_UNICODE)) { LPSTR pszAnsi; /* * Translate HSZ string back into ANSI */ if (WCSToMB(((PMONHSZSTRUCT)&pep->Data)->str, ((int)pep->cbEventData - (int)((PMONHSZSTRUCT)&pep->Data)->cb) / sizeof(WCHAR), &pszAnsi, (int)pep->cbEventData - (int)((PMONHSZSTRUCT)&pep->Data)->cb, TRUE)) { strcpy(((PMONHSZSTRUCTA)&pep->Data)->str, pszAnsi); UserLocalFree(pszAnsi); } ((PMONHSZSTRUCT)&pep->Data)->cb = sizeof(MONHSZSTRUCTA); } // fall through case MF_SENDMSGS: case MF_POSTMSGS: if (pep->EventType == MF_POSTMSGS) { PMONMSGSTRUCT pmms = (PMONMSGSTRUCT)&pep->Data; BYTE buf[32]; /* * We may need to translate the Execute string to/from * UNICODE depending on what type of monitor this is * going to. */ if (pmms->wMsg == WM_DDE_EXECUTE) { BOOL fUnicodeText; int flags; flags = (IS_TEXT_UNICODE_UNICODE_MASK | IS_TEXT_UNICODE_REVERSE_MASK | (IS_TEXT_UNICODE_NOT_UNICODE_MASK & (~IS_TEXT_UNICODE_ILLEGAL_CHARS)) | IS_TEXT_UNICODE_NOT_ASCII_MASK); #ifdef ISTEXTUNICODE_WORKS fUnicodeText = RtlIsTextUnicode(pmms->dmhd.Data, min(32, pmms->dmhd.cbData), &flags); #else fUnicodeText = (*(LPSTR)pmms->dmhd.Data == '\0'); #endif if (pcii->flags & IIF_UNICODE && !fUnicodeText) { /* Ascii->UNICODE */ RtlMultiByteToUnicodeN((LPWSTR)buf, 32, NULL, (LPSTR)&pmms->dmhd.Data, min(32, pmms->dmhd.cbData)); RtlCopyMemory(&pmms->dmhd.Data, buf, 32); } else if (!(pcii->flags & IIF_UNICODE) && fUnicodeText) { /* UNICODE->Ascii */ RtlUnicodeToMultiByteN((LPSTR)buf, 32, NULL, (LPWSTR)&pmms->dmhd.Data, min(32, pmms->dmhd.cbData)); RtlCopyMemory(&pmms->dmhd.Data, buf, 32); } } } case MF_ERRORS: hData = InternalCreateDataHandle(pcii, (LPSTR)&pep->Data, pep->cbEventData, 0, HDATA_NOAPPFREE | HDATA_READONLY | HDATA_EXECUTE, 0, 0); if (hData) { DoCallback(pcii, (WORD)XTYP_MONITOR, 0, 0, 0, 0, hData, 0L, pep->EventType); InternalFreeDataHandle((HDDEDATA)hData, TRUE); } break; } LeaveDDECrit; return (0); }
MsgRouting AwtCheckbox::OwnerDrawItem(UINT /*ctrlId*/, DRAWITEMSTRUCT& drawInfo) { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); if (env->EnsureLocalCapacity(4) < 0) { return mrConsume; } jobject self = GetPeer(env); jobject target = env->GetObjectField(self, AwtObject::targetID); HDC hDC = drawInfo.hDC; RECT rect = drawInfo.rcItem; int checkSize; UINT nState; SIZE size; jobject font = GET_FONT(target, self); jstring str = (jstring)env->GetObjectField(target, AwtCheckbox::labelID); size = AwtFont::getMFStringSize(hDC, font, str); jobject group = env->GetObjectField(target, AwtCheckbox::groupID); if (group != NULL) nState = DFCS_BUTTONRADIO; else nState = DFCS_BUTTONCHECK; if (GetState()) nState |= DFCS_CHECKED; else nState &= ~DFCS_CHECKED; if (drawInfo.itemState & ODS_SELECTED) nState |= DFCS_PUSHED; if (drawInfo.itemAction & ODA_DRAWENTIRE) { VERIFY(::FillRect (hDC, &rect, GetBackgroundBrush())); } /* draw check mark */ checkSize = GetCheckSize(); RECT boxRect; boxRect.left = (GetRTL()) ? rect.right - checkSize : rect.left; boxRect.top = (rect.bottom - rect.top - checkSize)/2; boxRect.right = boxRect.left + checkSize; boxRect.bottom = boxRect.top + checkSize; ::DrawFrameControl(hDC, &boxRect, DFC_BUTTON, nState); /* * draw string * * 4 is a heuristic number */ rect.left = rect.left + checkSize + checkSize/4; if (drawInfo.itemAction & ODA_DRAWENTIRE) { BOOL bEnabled = isEnabled(); int x = (GetRTL()) ? rect.right - (checkSize + checkSize / 4 + size.cx) : rect.left; int y = (rect.top + rect.bottom - size.cy) / 2; if (bEnabled) { AwtComponent::DrawWindowText(hDC, font, str, x, y); } else { AwtComponent::DrawGrayText(hDC, font, str, x, y); } } /* Draw focus rect */ RECT focusRect; const int margin = 2; /* 2 is a heuristic number */ focusRect.left = (GetRTL()) ? rect.right - checkSize - checkSize / 4 - 2 * margin - size.cx : rect.left - margin; focusRect.top = (rect.top+rect.bottom-size.cy)/2; focusRect.right = (GetRTL()) ? rect.right - checkSize - checkSize / 4 + margin : focusRect.left + size.cx + 2 * margin; focusRect.bottom = focusRect.top + size.cy; /* draw focus rect */ if ((drawInfo.itemState & ODS_FOCUS) && ((drawInfo.itemAction & ODA_FOCUS)|| (drawInfo.itemAction &ODA_DRAWENTIRE))) { VERIFY(::DrawFocusRect(hDC, &focusRect)); } /* erase focus rect */ else if (!(drawInfo.itemState & ODS_FOCUS) && (drawInfo.itemAction & ODA_FOCUS)) { VERIFY(::DrawFocusRect(hDC, &focusRect)); } /* Notify any subclasses */ rect = drawInfo.rcItem; DoCallback("handlePaint", "(IIII)V", rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top); env->DeleteLocalRef(target); env->DeleteLocalRef(font); env->DeleteLocalRef(str); env->DeleteLocalRef(group); return mrConsume; }
int StartServer(const char *nssCertDBDir, SSLSNISocketConfig sniSocketConfig, void *sniSocketConfigArg) { const char *debugLevel = PR_GetEnv("MOZ_TLS_SERVER_DEBUG_LEVEL"); if (debugLevel) { int level = atoi(debugLevel); switch (level) { case DEBUG_ERRORS: gDebugLevel = DEBUG_ERRORS; break; case DEBUG_WARNINGS: gDebugLevel = DEBUG_WARNINGS; break; case DEBUG_VERBOSE: gDebugLevel = DEBUG_VERBOSE; break; default: PrintPRError("invalid MOZ_TLS_SERVER_DEBUG_LEVEL"); return 1; } } const char *callbackPort = PR_GetEnv("MOZ_TLS_SERVER_CALLBACK_PORT"); if (callbackPort) { gCallbackPort = atoi(callbackPort); } if (InitializeNSS(nssCertDBDir) != SECSuccess) { PR_fprintf(PR_STDERR, "InitializeNSS failed"); return 1; } if (NSS_SetDomesticPolicy() != SECSuccess) { PrintPRError("NSS_SetDomesticPolicy failed"); return 1; } if (SSL_ConfigServerSessionIDCache(0, 0, 0, nullptr) != SECSuccess) { PrintPRError("SSL_ConfigServerSessionIDCache failed"); return 1; } UniquePRFileDesc serverSocket(PR_NewTCPSocket()); if (!serverSocket) { PrintPRError("PR_NewTCPSocket failed"); return 1; } PRSocketOptionData socketOption; socketOption.option = PR_SockOpt_Reuseaddr; socketOption.value.reuse_addr = true; PR_SetSocketOption(serverSocket.get(), &socketOption); PRNetAddr serverAddr; PR_InitializeNetAddr(PR_IpAddrLoopback, LISTEN_PORT, &serverAddr); if (PR_Bind(serverSocket.get(), &serverAddr) != PR_SUCCESS) { PrintPRError("PR_Bind failed"); return 1; } if (PR_Listen(serverSocket.get(), 1) != PR_SUCCESS) { PrintPRError("PR_Listen failed"); return 1; } UniquePRFileDesc rawModelSocket(PR_NewTCPSocket()); if (!rawModelSocket) { PrintPRError("PR_NewTCPSocket failed for rawModelSocket"); return 1; } UniquePRFileDesc modelSocket(SSL_ImportFD(nullptr, rawModelSocket.release())); if (!modelSocket) { PrintPRError("SSL_ImportFD of rawModelSocket failed"); return 1; } if (SSL_SNISocketConfigHook(modelSocket.get(), sniSocketConfig, sniSocketConfigArg) != SECSuccess) { PrintPRError("SSL_SNISocketConfigHook failed"); return 1; } // We have to configure the server with a certificate, but it's not one // we're actually going to end up using. In the SNI callback, we pick // the right certificate for the connection. if (ConfigSecureServerWithNamedCert(modelSocket.get(), DEFAULT_CERT_NICKNAME, nullptr, nullptr) != SECSuccess) { return 1; } if (gCallbackPort != 0) { if (DoCallback()) { return 1; } } while (true) { PRNetAddr clientAddr; PRFileDesc* clientSocket = PR_Accept(serverSocket.get(), &clientAddr, PR_INTERVAL_NO_TIMEOUT); HandleConnection(clientSocket, modelSocket); } return 0; }
BOOL CNetFile::DoThread(LPVOID pData) {_STT(); if ( !m_bUpload ) { m_dwTransferStatus = NETFILE_DS_DOWNLOADING; // Post callback DoCallback( (WPARAM)m_dwTransferStatus, (LPARAM)this ); DWORD ready = 0; // Get available data if ( !InternetQueryDataAvailable( m_hFile, &ready, 0, 0 ) ) { m_dwTransferError = GetLastError(); return FALSE; } // end if // Quit if no more data if ( ready == 0 ) return FALSE; // Get total length if needed if ( m_bGetTotalLength ) { m_bGetTotalLength = FALSE; // Send the query command char bufQuery[ 32 ] = "0"; DWORD dwLengthBufQuery = sizeof( bufQuery ); DWORD dwHeaderIndex = 0; HttpQueryInfo( m_hFile, HTTP_QUERY_CONTENT_LENGTH, bufQuery, &dwLengthBufQuery, &dwHeaderIndex ); // Did we find the header? if ( dwHeaderIndex != ERROR_HTTP_HEADER_NOT_FOUND ) // Convert length from ASCII string to a DWORD. m_dwTotalLength = (DWORD)atol( bufQuery ); } // end if while ( ready ) { // Don't byte of more than this computer can chew DWORD size = ( ready < m_dwBlockSize ) ? ready : m_dwBlockSize; // Allocate a buffer to save new data LPBYTE buf = new BYTE[ size + 1 ]; if ( buf == NULL ) { m_dwTransferError = ERROR_NOT_ENOUGH_MEMORY; return FALSE; } // end if // Attempt to read new data DWORD read = 0; if ( !InternetReadFile( m_hFile, buf, size, &read ) ) { delete [] buf; m_dwTransferError = GetLastError(); return FALSE; } // end if // Check for end of file if ( read == 0 ) { m_dwTransferStatus = NETFILE_DS_DONE; return FALSE; } // end if if ( m_bMem ) { if ( m_pMem != NULL ) { LPBYTE temp = new BYTE[ m_dwDataRead + size + 1 ]; if ( temp == NULL ) { m_dwTransferError = ERROR_NOT_ENOUGH_MEMORY; return FALSE; } // end if memcpy( temp, m_pMem, m_dwDataRead ); memcpy( &temp[ m_dwDataRead ], buf, size ); temp[ m_dwDataRead + size ] = NULL; delete [] m_pMem; m_pMem = temp; } // end if else { m_pMem = new BYTE[ size + 1 ]; if ( m_pMem == NULL ) { m_dwTransferError = ERROR_NOT_ENOUGH_MEMORY; return FALSE; } // end if memcpy( m_pMem, buf, size ); m_pMem[ size ] = NULL; } // end else } // end if // Write the data to the file else if ( !m_local.Write( buf, read ) ) { delete [] buf; m_dwTransferError = GetLastError(); return FALSE; } // end if // Delete buffer delete [] buf; // Add this to data received m_dwDataRead += size; // Read the next block ready -= size; } // end while } else { // Do we have any memory if ( m_pMem == NULL || m_dwMemSize == 0 ) { m_dwTransferStatus = NETFILE_DS_ERROR; return FALSE; } // end if m_dwTransferStatus = NETFILE_DS_UPLOADING; // Post callback DoCallback( (WPARAM)m_dwTransferStatus, (LPARAM)this ); // Don't byte of more than this computer can chew DWORD left = m_dwMemSize - m_dwDataWritten; DWORD write = ( left < m_dwBlockSize ) ? left : m_dwBlockSize; DWORD written = 0; // Attempt to write some data if ( !InternetWriteFile( m_hFile, &m_pMem[ m_dwDataWritten ], write, &written ) ) { m_dwTransferStatus = NETFILE_DS_ERROR; m_dwTransferError = GetLastError(); return FALSE; } // end if // Count this data m_dwDataWritten += written; // Have we written all the data? if ( m_dwDataWritten == m_dwMemSize ) { m_dwTransferStatus = NETFILE_DS_DONE; return FALSE; } // end if } // end else // Wait a bit Sleep( 15 ); // Keep going return TRUE; }
PyObject *CPythonHandler::Callback( HANDLER_TYPE typ, const char *format /* = NULL */, ... ) { va_list va; PyObject *args; PyObject *ret = NULL; if (format && *format) { va_start(va, format); args = Py_VaBuildValue((char *)format, va); va_end(va); } else args = PyTuple_New(0); if (args == NULL) return NULL; if (!PyTuple_Check(args)) { PyObject *a; a = PyTuple_New(1); if (a == NULL) goto done; if (PyTuple_SET_ITEM(a, 0, args) < 0) { Py_DECREF(a); goto done; } // 'args' ref consumed by _SET_ITEM. args = a; } ret = DoCallback(typ, args); if (!ret) { if (m_engine->m_reload_exception && PyErr_ExceptionMatches(m_engine->m_reload_exception)) { PyErr_Clear(); // Need to call term first PyObject *temp_args = Py_BuildValue("(i)", 0); ret = DoCallback(HANDLER_TERM, temp_args); Py_XDECREF(temp_args); if (!ret) { ExtensionError(NULL, "Terminating for reload failed"); PyErr_Clear(); } Py_XDECREF(ret); // Now force the reload and refresh of all callbacks. if (!LoadHandler(true)) goto done; Py_XDECREF(m_callback_init); m_callback_init = NULL; Py_XDECREF(m_callback_do); m_callback_do = NULL; Py_XDECREF(m_callback_term); m_callback_term = NULL; // call init again temp_args = Py_BuildValue("(z)", NULL); ret = DoCallback(HANDLER_INIT, temp_args); Py_XDECREF(temp_args); if (!ret) { ExtensionError(NULL, "Reinitializing after import failed"); PyErr_Clear(); } Py_XDECREF(ret); // And make the original call again. ret = DoCallback(typ, args); } } done: Py_DECREF(args); return ret; }