Пример #1
0
bool ConnectToSelf()
{
    char host[MAX_HOST_LENGTH];
    DWORD length = MAX_HOST_LENGTH;
    MPD_Context *pRightContext, *pLeftContext;

    host[0] = '\0';
    GetComputerName(host, &length);

    // Initialize the new contexts
    pRightContext = CreateContext();
    if (pRightContext == NULL)
	return false;
    strncpy(pRightContext->pszHost, host, MAX_HOST_LENGTH);
    pRightContext->nCurPos = 0;
    pRightContext->nState = MPD_IDLE;
    pRightContext->nLLState = MPD_READING_CMD;
    pRightContext->nType = MPD_RIGHT_SOCKET;

    pLeftContext = CreateContext();
    if (pLeftContext == NULL)
    {
	RemoveContext(pRightContext);
	return false;
    }
    strncpy(pLeftContext->pszHost, host, MAX_HOST_LENGTH);
    pLeftContext->nCurPos = 0;
    pLeftContext->nState = MPD_IDLE;
    pLeftContext->nLLState = MPD_READING_CMD;
    pLeftContext->nType = MPD_LEFT_SOCKET;

    MakeLoopAsync(&pLeftContext->sock, &pRightContext->sock);
    if (pLeftContext->sock == INVALID_SOCKET || pRightContext->sock == INVALID_SOCKET)
    {
	RemoveContext(pLeftContext);
	RemoveContext(pRightContext);
	return false;
    }

    // overwrite the old left and right contexts
    g_pRightContext = pRightContext;
    g_pLeftContext = pLeftContext;
    strncpy(g_pszRightHost, host, MAX_HOST_LENGTH);
    strncpy(g_pszLeftHost, host, MAX_HOST_LENGTH);

    //dbg_printf("ConnectToSelf succeeded\n");
    return true;
}
void VRemoteDebugPilot::TreatRemoveContextMsg(RemoteDebugPilotMsg_t& ioMsg)
{
	std::map< OpaqueDebuggerContext, VContextDescriptor* >::iterator ctxIt = fContextArray.find(ioMsg.ctx);
	RemoveContext(ctxIt);
	fPipeStatus = VE_OK;
	fPipeOutSem.Unlock();
}
// ----------------------------------------------------------------------------------------
// Free all resources again
// ----------------------------------------------------------------------------------------
void VSimpleCopyPostprocess::DeInitializePostProcessor()
{
  if (!m_bIsInitialized)
    return;

  RemoveContext();

  m_bIsInitialized = false;
}
// ----------------------------------------------------------------------------------------
// Free all resources again
// ----------------------------------------------------------------------------------------
void VPostProcessScreenMasks::DeInitializePostProcessor()
{
  if (!m_bIsInitialized)
    return;

  m_bIsInitialized = false;

  RemoveContext();
}
Пример #5
0
// ----------------------------------------------------------------------------------------
// Free all resources again
// ----------------------------------------------------------------------------------------
void VPostProcessFXAA::DeInitializePostProcessor()
{
  if (!m_bIsInitialized)
    return;

  m_spMask = NULL;
  RemoveContext();

  m_bIsInitialized = false;
}
void CslIrcThread::LibIrcError(CslIrcContext *context,wxInt32 error)
{
    LOG_DEBUG("libirc error (%d): \n",error,irc_strerror(errno));

    wxEvtHandler *handler=context->EvtHandler;
    CslIrcEvent evt(context->Target,CslIrcEvent::ERR);
    evt.Strings.Add(A2U(irc_strerror(error)));
    evt.Ints.Add(error);

    switch (error)
    {
        case LIBIRC_ERR_INVAL:
            wxASSERT_MSG(error!=LIBIRC_ERR_INVAL,wxT("Invalid arguments."));
            break;
        case LIBIRC_ERR_RESOLV:
        case LIBIRC_ERR_SOCKET:
        case LIBIRC_ERR_CONNECT:
        case LIBIRC_ERR_CLOSED:
        case LIBIRC_ERR_NOMEM:
            RemoveContext(context);
            break;
        case LIBIRC_ERR_ACCEPT:
        case LIBIRC_ERR_NODCCSEND:
        case LIBIRC_ERR_READ:
        case LIBIRC_ERR_WRITE:
        case LIBIRC_ERR_STATE:
        case LIBIRC_ERR_TIMEOUT:
        case LIBIRC_ERR_OPENFILE:
            break;
        case LIBIRC_ERR_TERMINATED:
            RemoveContext(context);
            break;
    }

    wxPostEvent(handler,evt);
}
Пример #7
0
void WorldAsynContextManager::FreeContext(AsynContext* pContext)
{
	RemoveContext( pContext->nContextID );
	FACTORY_DELOBJ(pContext);
}
Пример #8
0
void RunWorkerThread()
{
    DWORD dwKey, nBytes;
    OVERLAPPED *p_Ovl;
    int error;
    MPD_Context *pContext;
    int ret_val;

    while (true)
    {
        if (GetQueuedCompletionStatus(g_hCommPort, &nBytes, &dwKey, &p_Ovl, INFINITE))
        {
            //dbg_printf("RunWorkerThread::%d bytes\n", nBytes);
            if (dwKey == EXIT_WORKER_KEY)
                ExitThread(0);
            pContext = (MPD_Context*)dwKey;
            if (nBytes)
            {
                if (nBytes == 1)
                {
                    pContext->bReadPosted = false;
                    if (!RunRead(pContext, &ret_val))
                        ErrorExit("RunRead returned FALSE", ret_val);

                    if (pContext->bDeleteMe)
                    {
                        RemoveContext(pContext);
                        pContext = NULL;
                    }
                    else
                    {
                        // post the next read
                        error = PostContextRead(pContext);
                        if (error)
                        {
                            if (error == ERROR_NETNAME_DELETED || error == ERROR_IO_PENDING || error == WSAECONNABORTED)
                                dbg_printf("RunWorkerThread:Post read for %s(%d) failed, error %d\n", ContextTypeToString(pContext), pContext->sock, error);
                            else
                                err_printf("RunWorkerThread:Post read for %s(%d) failed, error %d\n", ContextTypeToString(pContext), pContext->sock, error);
                            RemoveContext(pContext);
                            pContext = NULL;
                        }
                    }
                }
                else
                {
                    dbg_printf("RunWorkerThread: nBytes = %d, *** unexpected ***\n", nBytes);
                    error = PostContextRead(pContext);
                    if (error)
                    {
                        err_printf("RunWorkerThread:Post read for %s(%d) failed, error %d\n", ContextTypeToString(pContext), pContext->sock, error);
                        RemoveContext(pContext);
                        pContext = NULL;
                    }
                }
            }
            else
            {
                dbg_printf("RunWorkerThread::closing context %s(%d)\n", ContextTypeToString(pContext), pContext->sock);
                RemoveContext(pContext);
                pContext = NULL;
            }
        }
        else
        {
            error = GetLastError();
            if (error == ERROR_NETNAME_DELETED || error == ERROR_IO_PENDING || error == WSAECONNABORTED)
            {
                dbg_printf("RunWorkerThread: GetQueuedCompletionStatus failed, error %d\n", error);
            }
            else
            {
                err_printf("RunWorkerThread: GetQueuedCompletionStatus failed, error %d\n", error);
            }
            //return;
        }
    }
}
Пример #9
0
void RemoveAllContexts()
{
    while (g_pList)
	RemoveContext(g_pList);
}
Пример #10
0
/******************************************************************************
 * So, we're finished with sending (regardless of success or failure)         *
 * This Message might be referenced by several Queue-Items, if we're the last,*
 * we need to free the memory and send bounce messages (on terminal failure)  *
 * else we just free our SMTP-Message struct.                                 *
 ******************************************************************************/
eNextState FinalizeMessageSend_DB(AsyncIO *IO)
{
	const char *Status;
	SmtpOutMsg *Msg = IO->Data;
	StrBuf *StatusMessage;

	if (Msg->MyQEntry->AllStatusMessages != NULL)
		StatusMessage = Msg->MyQEntry->AllStatusMessages;
	else
		StatusMessage = Msg->MyQEntry->StatusMessage;


	if (Msg->MyQEntry->Status == 2) {
		SetSMTPState(IO, eSTMPfinished);
		Status = "Delivery successful.";
	}
	else if (Msg->MyQEntry->Status == 5) {
		SetSMTPState(IO, eSMTPFailTotal);
		Status = "Delivery failed permanently; giving up.";
	}
	else {
		SetSMTPState(IO, eSMTPFailTemporary);
		Status = "Delivery failed temporarily; will retry later.";
	}
			
	EVS_syslog(LOG_INFO,
		   "%s Time[%fs] Recipient <%s> @ <%s> (%s) Status message: %s\n",
		   Status,
		   Msg->IO.Now - Msg->IO.StartIO,
		   Msg->user,
		   Msg->node,
		   Msg->name,
		   ChrPtr(StatusMessage));


	Msg->IDestructQueItem = DecreaseQReference(Msg->MyQItem);

	Msg->nRemain = CountActiveQueueEntries(Msg->MyQItem, 0);

	if (Msg->MyQEntry->Active && 
	    !Msg->MyQEntry->StillActive &&
	    CheckQEntryIsBounce(Msg->MyQEntry))
	{
		/* are we casue for a bounce mail? */
		Msg->MyQItem->SendBounceMail |= (1<<Msg->MyQEntry->Status);
	}

	if ((Msg->nRemain > 0) || Msg->IDestructQueItem)
		Msg->QMsgData = SerializeQueueItem(Msg->MyQItem);
	else
		Msg->QMsgData = NULL;

	/*
	 * Uncompleted delivery instructions remain, so delete the old
	 * instructions and replace with the updated ones.
	 */
	EVS_syslog(LOG_DEBUG, "%ld", Msg->MyQItem->QueMsgID);
	CtdlDeleteMessages(SMTP_SPOOLOUT_ROOM, &Msg->MyQItem->QueMsgID, 1, "");
	Msg->MyQItem->QueMsgID = -1;

	if (Msg->IDestructQueItem)
		smtpq_do_bounce(Msg->MyQItem, Msg->msgtext, Msg->pCurrRelay);

	if (Msg->nRemain > 0)
	{
		struct CtdlMessage *msg;
		msg = malloc(sizeof(struct CtdlMessage));
		memset(msg, 0, sizeof(struct CtdlMessage));
		msg->cm_magic = CTDLMESSAGE_MAGIC;
		msg->cm_anon_type = MES_NORMAL;
		msg->cm_format_type = FMT_RFC822;
		CM_SetAsFieldSB(msg, eMesageText, &Msg->QMsgData);
		CM_SetField(msg, eMsgSubject, HKEY("QMSG"));
		Msg->MyQItem->QueMsgID =
			CtdlSubmitMsg(msg, NULL, SMTP_SPOOLOUT_ROOM, QP_EADDR);
		EVS_syslog(LOG_DEBUG, "%ld", Msg->MyQItem->QueMsgID);
		CM_Free(msg);
	}
	else {
		CtdlDeleteMessages(SMTP_SPOOLOUT_ROOM,
				   &Msg->MyQItem->MessageID,
				   1,
				   "");
		FreeStrBuf(&Msg->QMsgData);
	}

	RemoveContext(Msg->IO.CitContext);
	return eAbort;
}
Пример #11
0
static void
gotstatus(int nnrun)
{
	CURLMsg *msg;
	int nmsg;

	global.nrun = nnrun;

	CURLM_syslog(LOG_DEBUG,
		     "gotstatus(): about to call curl_multi_info_read\n");
	while ((msg = curl_multi_info_read(global.mhnd, &nmsg))) {
		CURL_syslog(LOG_DEBUG,
			    "got curl multi_info message msg=%d\n",
			    msg->msg);

		if (CURLMSG_DONE == msg->msg) {
			CURL *chnd;
			void *chandle = NULL;
			CURLcode sta;
			CURLMcode msta;
			AsyncIO*IO;

			chandle = NULL;;
			chnd = msg->easy_handle;
			sta = curl_easy_getinfo(chnd,
						CURLINFO_PRIVATE,
						&chandle);
			if (sta) {
				syslog(LOG_ERR,
				       "error asking curl for private"
				       " cookie of curl handle: %s\n",
				       curl_easy_strerror(sta));
				continue;
			}
			IO = (AsyncIO *)chandle;
			if (IO->ID == 0) {
				EVCURL_syslog(LOG_ERR,
					      "Error, invalid IO context %p\n",
					      IO);
				continue;
			}
			SetEVState(IO, eCurlGotStatus);

			EVCURLM_syslog(LOG_DEBUG, "request complete\n");

			IO->CitContext->lastcmd = IO->Now = ev_now(event_base);

			ev_io_stop(event_base, &IO->recv_event);
			ev_io_stop(event_base, &IO->send_event);

			sta = msg->data.result;
			if (sta) {
				EVCURL_syslog(LOG_ERR,
					      "error description: %s\n",
					      IO->HttpReq.errdesc);
				IO->HttpReq.CurlError = curl_easy_strerror(sta);
				EVCURL_syslog(LOG_ERR,
					      "error performing request: %s\n",
					      IO->HttpReq.CurlError);
				if (sta == CURLE_OPERATION_TIMEDOUT)
				{
					IO->SendBuf.fd = 0;
					IO->RecvBuf.fd = 0;
				}
			}
			sta = curl_easy_getinfo(chnd,
						CURLINFO_RESPONSE_CODE,
						&IO->HttpReq.httpcode);
			if (sta)
				EVCURL_syslog(LOG_ERR,
					      "error asking curl for "
					      "response code from request: %s\n",
					      curl_easy_strerror(sta));
			EVCURL_syslog(LOG_DEBUG,
				      "http response code was %ld\n",
				      (long)IO->HttpReq.httpcode);


			curl_slist_free_all(IO->HttpReq.headers);
			IO->HttpReq.headers = NULL;
			msta = curl_multi_remove_handle(global.mhnd, chnd);
			if (msta)
				EVCURL_syslog(LOG_ERR,
					      "warning problem detaching "
					      "completed handle from curl multi: "
					      "%s\n",
					      curl_multi_strerror(msta));

			ev_cleanup_stop(event_base, &IO->abort_by_shutdown);

			IO->HttpReq.attached = 0;
			switch(IO->SendDone(IO))
			{
			case eDBQuery:
				FreeURL(&IO->ConnectMe);
				QueueAnDBOperation(IO);
				break;
			case eSendDNSQuery:
			case eReadDNSReply:
			case eConnect:
			case eSendReply:
			case eSendMore:
			case eSendFile:
			case eReadMessage:
			case eReadMore:
			case eReadPayload:
			case eReadFile:
				break;
			case eTerminateConnection:
			case eAbort:
				curl_easy_cleanup(IO->HttpReq.chnd);
				IO->HttpReq.chnd = NULL;
				FreeStrBuf(&IO->HttpReq.ReplyData);
				FreeURL(&IO->ConnectMe);
				RemoveContext(IO->CitContext);
				IO->Terminate(IO);
			}
		}
	}
}
Пример #12
0
bool AuthenticateAcceptedConnection(MPD_Context **pp)
{
    int ret_val;
    MPD_Context *p;

    if (pp == NULL)
	return false;
    p = *pp;

    // generate the challenge string and the encrypted result
    if (!GenAuthenticationStrings(p->pszOut, p->pszCrypt))
    {
	err_printf("AuthenticateAcceptedConnection: failed to generate the authentication strings\n");
	RemoveContext(p);
	*pp = NULL;
	return false;
    }

    // write the challenge string
    if (WriteString(p->sock, p->pszOut) == SOCKET_ERROR)
    {
	err_printf("AuthenticateAcceptedConnection: Writing challenge string failed, error %d\n", WSAGetLastError());
	RemoveContext(p);
	*pp = NULL;
	return false;
    }

    // read the response
    if (!ReadString(p->sock, p->pszIn))
    {
	err_printf("AuthenticateAcceptedConnection: Reading challenge response failed, error %d\n", WSAGetLastError());
	RemoveContext(p);
	*pp = NULL;
	return false;
    }

    // compare the response with the encrypted result and write success or failure
    if (strcmp(p->pszIn, p->pszCrypt) == 0)
	ret_val = WriteString(p->sock, "SUCCESS");
    else
	ret_val = WriteString(p->sock, "FAIL");
    if (ret_val == SOCKET_ERROR)
    {
	err_printf("AuthenticateAcceptedConnection: Writing authentication result failed, error %d\n", WSAGetLastError());
	RemoveContext(p);
	*pp = NULL;
	return false;
    }

    // read the type of connection
    if (!ReadString(p->sock, p->pszIn))
    {
	err_printf("AuthenticateAcceptedConnection: Reading the connection type failed, error %d\n", WSAGetLastError());
	RemoveContext(p);
	*pp = NULL;
	return false;
    }

    // set the state appropriate for the type of connection
    if (stricmp(p->pszIn, "console") == 0)
    {
	dbg_printf("AuthenticateAcceptedConnection: MPD_CONSOLE_SOCKET(%d)\n", p->sock);
	p->nType = MPD_CONSOLE_SOCKET;
	p->nLLState= MPD_READING_CMD;
    }
    else if (strnicmp(p->pszIn, "left ", 5) == 0)
    {
	dbg_printf("AuthenticateAcceptedConnection: MPD_LEFT_SOCKET(%d)\n", p->sock);
	p->nType = MPD_LEFT_SOCKET;
	p->nLLState= MPD_READING_CMD;
	strncpy(p->pszHost, &p->pszIn[5], MAX_HOST_LENGTH);
	p->pszHost[MAX_HOST_LENGTH-1] = '\0';
    }
    else if (strnicmp(p->pszIn, "right ", 6) == 0)
    {
	dbg_printf("AuthenticateAcceptedConnection: MPD_RIGHT_SOCKET(%d)\n", p->sock);
	p->nType = MPD_RIGHT_SOCKET;
	p->nLLState= MPD_READING_CMD;
	strncpy(p->pszHost, &p->pszIn[6], MAX_HOST_LENGTH);
	p->pszHost[MAX_HOST_LENGTH-1] = '\0';
    }
    else
    {
	err_printf("AuthenticateAcceptedConnection: unknown socket type read: '%s'\n", p->pszIn);
	RemoveContext(p);
	*pp = NULL;
	return false;
    }
    p->nState = MPD_IDLE;

    return true;
}
Пример #13
0
bool AuthenticateConnectedConnection(MPD_Context **pp, char *passphrase/* = MPD_DEFAULT_PASSPHRASE*/)
{
    int error;
    MPD_Context *p;
    char phrase[MPD_PASSPHRASE_MAX_LENGTH];
    char *result;

    if (pp == NULL)
	return false;
    p = *pp;

    strcpy(phrase, passphrase);

    // read the challenge string
    if (!ReadString(p->sock, p->pszIn))
    {
	err_printf("AuthenticateConnectedConnection: Reading challenge string failed, error %d\n", WSAGetLastError());
	RemoveContext(p);
	*pp = NULL;
	return false;
    }

    // crypt the passphrase + the challenge
    if (strlen(phrase) + strlen(p->pszIn) > MPD_PASSPHRASE_MAX_LENGTH)
    {
	err_printf("AuthenticateConnectedConnection: unable to process passphrase.\n");
	RemoveContext(p);
	*pp = NULL;
	return false;
    }
    strcat(phrase, p->pszIn);
    if (g_bCryptFirst) // this is not safe code because two threads can enter this Initialize... block at the same time
    {
	InitializeCriticalSection(&g_hCryptCriticalSection);
	g_bCryptFirst = false;
    }
    EnterCriticalSection(&g_hCryptCriticalSection);
    result = crypt(phrase, MPD_SALT_VALUE);
    strcpy(p->pszOut, result);
    LeaveCriticalSection(&g_hCryptCriticalSection);

    // write the response
    if (WriteString(p->sock, p->pszOut) == SOCKET_ERROR)
    {
	error = WSAGetLastError();
	Translate_Error(error, p->pszOut);
	err_printf("AuthenticateConnectedConnection: WriteString of the encrypted response string failed: %d\n%s\n", error, p->pszOut);
	RemoveContext(p);
	*pp = NULL;
	return false;
    }

    // read the result
    if (!ReadString(p->sock, p->pszIn))
    {
	error = WSAGetLastError();
	Translate_Error(error, p->pszOut);
	err_printf("AuthenticateConnectedConnection: reading authentication result failed: error %d\n%s\n", error, p->pszOut);
	RemoveContext(p);
	*pp = NULL;
	return false;
    }
    if (strcmp(p->pszIn, "SUCCESS"))
    {
	dbg_printf("host authentication failed.\n");
	RemoveContext(p);
	*pp = NULL;
	return false;
    }
    return true;
}
void VRemoteDebugPilot::HandleConnectedState()
{
	XBOX::VError			err;
	VSize					msgLen;
	bool					isMsgTerminated;
	sBYTE*					tmpStr;
	sBYTE*					endStr;
	unsigned long long		id;
	XBOX::VString			resp;

	msgLen = K_MAX_SIZE;
	err = fWS->ReadMessage((void*)fTmpData,msgLen,isMsgTerminated);
	if (err)
	{
		DebugMsg("VRemoteDebugPilot::HandleConnectedState fWS->ReadMessage pb\n");
		fWS->Close();
		fState = DISCONNECTING_STATE;
		return;
	}
	if (msgLen)
	{
		if (msgLen < K_MAX_SIZE)
		{
			fTmpData[msgLen] = 0;
		}
		else
		{
			fTmpData[K_MAX_SIZE-1] = 0;
		}
		DebugMsg("VRemoteDebugPilot::HandleConnectedState received msg(len=%d)='%s'\n",msgLen,fTmpData);

		{
			tmpStr = strstr(fTmpData,K_DBG_PROTOCOL_ABORT_STR);
			if (tmpStr && fClientId.GetLength())
			{
				tmpStr += strlen(K_DBG_PROTOCOL_ABORT_STR);
				endStr = strchr(tmpStr,'"');
				*endStr = 0;
				id = atoi(tmpStr);
				std::map< OpaqueDebuggerContext, VContextDescriptor* >::iterator	ctxIt = fContextArray.find((OpaqueDebuggerContext)id);
				if ( testAssert(ctxIt != fContextArray.end()) )
				{
					if (!(*ctxIt).second->fPage)
					{
						if ((*ctxIt).second->fSem)
						{
							(*ctxIt).second->fSem->Unlock();
							ReleaseRefCountable(&(*ctxIt).second->fSem);
						}
						RemoveContext(ctxIt);
					}
					else
					{
						VChromeDbgHdlPage*	l_page = (*ctxIt).second->fPage;
						testAssert(l_page->Abort() == VE_OK);
					}
					//RemoveContext(id);
				}
			}
			else
			{
				tmpStr = strstr(fTmpData,K_DBG_PROTOCOL_GET_URL_STR);
				if (tmpStr && fClientId.GetLength())
				{
					tmpStr += strlen(K_DBG_PROTOCOL_GET_URL_STR);
					endStr = strchr(tmpStr,'"');
					*endStr = 0;
					id = atoi(tmpStr);
					std::map< OpaqueDebuggerContext, VContextDescriptor* >::iterator	ctxIt = fContextArray.find((OpaqueDebuggerContext)id);
					if ( testAssert(ctxIt != fContextArray.end()) )
					{
						// test if a a page has already been attributed to this context
						if (testAssert(!(*ctxIt).second->fPage))
						{
							xbox_assert((*ctxIt).second->fTraceContainer);
							(*ctxIt).second->fPage = new VChromeDbgHdlPage((*ctxIt).second->fTraceContainer);
							(*ctxIt).second->fPage->Init(id,fHTTPServer,NULL);
							err = (*ctxIt).second->fPage->Start((OpaqueDebuggerContext)id);
							/*sPages[l_i].value.fFifo.Reset();
							sPages[l_i].value.fOutFifo.Reset();*/
						}
						if (!err)
						{
							resp = CVSTR("{\"method\":\"setURLContext\",\"contextId\":\"");
							resp.AppendLong8(id);
							resp += CVSTR("\",\"url\":\"");
							resp.AppendLong8((*ctxIt).second->fPage->GetPageNb());
							resp += CVSTR("\",\"id\":\"");
							resp += fClientId;
							resp += CVSTR("\"}");
							err = SendToBrowser( resp );
						}

						if (err)
						{
							fWS->Close();
							fState = DISCONNECTING_STATE;
							return;
						}
					}
					else
					{
						DebugMsg("VRemoteDebugPilot::HandleConnectedState unknown context = %d\n",id);
					}
				}
				else
				{
					DebugMsg("VRemoteDebugPilot::HandleConnectedState received msg2(len=%d)='%s'\n",msgLen,fTmpData);
				}
			}
		}
	}
}