Beispiel #1
0
void __cdecl SmileyDownloadThread(void*)
{
	bool needext = false;
	HANDLE hHttpDwnl = NULL;
	WaitForSingleObject(g_hDlMutex, 3000);
	while (!Miranda_Terminated() && dlQueue.getCount()) {
		ReleaseMutex(g_hDlMutex);
		if (_taccess(dlQueue[0].fname.c_str(), 0) != 0) {
			InternetDownloadFile(T2A_SM(dlQueue[0].url.c_str()), T2A_SM(dlQueue[0].fname.c_str()), hHttpDwnl);
			WaitForSingleObject(g_hDlMutex, 3000);

			CMString fname(dlQueue[0].fname);
			if (dlQueue[0].needext) { fname += GetImageExt(fname); needext = true; }
			_trename(dlQueue[0].fname.c_str(), fname.c_str());
		}
		else WaitForSingleObject(g_hDlMutex, 3000);

		dlQueue.remove(0);
	}
	dlQueue.destroy();
	if (hHttpDwnl) Netlib_CloseHandle(hHttpDwnl);
	threadRunning = false;
	ReleaseMutex(g_hDlMutex);

	if (!Miranda_Terminated()) {
		if (needext)
			CallServiceSync(MS_SMILEYADD_RELOAD, 0, 0);
		else
			NotifyEventHooks(hEvent1, 0, 0);
	}
}
int AskStatusMessageThread(HWND hwnd)
{
  DWORD time;
  HANDLE h;
  HANDLE ACK=0;
  pdisplayNameCacheEntry pdnce=NULL;
  h=GetCurrChain(); 
  if (!h) return 0;

  ISTREADSTARTED=1;
  while (h)
  { 
    time=GetTickCount();
    if ((time-RequestTick)<ASKPERIOD)
    {
            SleepEx(ASKPERIOD-(time-RequestTick)+10,TRUE);
            if (Miranda_Terminated()) 
            {
              ISTREADSTARTED=0;
              return 0; 
            }
    }

	{
		pdnce = GetDisplayNameCacheEntry((HANDLE)h);
		if (pdnce->ApparentMode!=ID_STATUS_OFFLINE) //don't ask if contact is always invisible (should be done with protocol)
			ACK=(HANDLE)CallContactService(h,PSS_GETAWAYMSG,0,0);
	}   
    if (!ACK)
    {
      ACKDATA ack;
      ack.hContact=h;
      ack.type=ACKTYPE_AWAYMSG;
      ack.result=ACKRESULT_FAILED;
      if (pdnce)
        ack.szModule=pdnce->szProto;
      else
        ack.szModule=NULL;
      ClcProtoAck((WPARAM)h,(LPARAM) &ack);
    }
    RequestTick=time;
    h=GetCurrChain();
    if (h) SleepEx(ASKPERIOD,TRUE); else break;
    if (Miranda_Terminated()) 
    {
      ISTREADSTARTED=0;
      return 0; 
    }

  }
  ISTREADSTARTED=0;
  return 1;
}
Beispiel #3
0
void __cdecl UpdateMsgsThreadProc(void *)
{
	int numAccs;
	PROTOACCOUNT **accs;
	ProtoEnumAccounts(&numAccs, &accs);

	while (WaitForSingleObject(g_hTerminateUpdateMsgsThread, 0) == WAIT_TIMEOUT && !Miranda_Terminated()) {
		DWORD MinUpdateTimeDifference = g_MoreOptPage.GetDBValueCopy(IDC_MOREOPTDLG_UPDATEMSGSPERIOD) * 1000; // in milliseconds
		for (int i = 0; i < numAccs; i++) {
			PROTOACCOUNT *p = accs[i];
			if (CallProtoService(p->szModuleName, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_MODEMSGSEND && !IsAnICQProto(p->szModuleName)) {
				int Status = CallProtoService(p->szModuleName, PS_GETSTATUS, 0, 0);
				if (Status < ID_STATUS_OFFLINE || Status > ID_STATUS_OUTTOLUNCH) {
					Status = g_ProtoStates[p->szModuleName].Status;
				}
				if (CallProtoService(p->szModuleName, PS_GETCAPS, PFLAGNUM_3, 0) & Proto_Status2Flag(Status) && g_ProtoStates[p->szModuleName].CurStatusMsg.GetUpdateTimeDifference() >= MinUpdateTimeDifference) {
					TCString CurMsg(GetDynamicStatMsg(INVALID_CONTACT_ID, p->szModuleName));
					if ((TCString)g_ProtoStates[p->szModuleName].CurStatusMsg != (const TCHAR*)CurMsg) { // if the message has changed
						g_ProtoStates[p->szModuleName].CurStatusMsg = CurMsg;
						CallAllowedPS_SETAWAYMSG(p->szModuleName, Status, (char*)_T2A(CurMsg));
					}
				}
			}
		}
		SleepEx(PARSE_INTERVAL, true);
	}
}
Beispiel #4
0
void ScheduleThread(void*)
{
	time_t waitTime = INFINITE;

	while (true)
	{
wait:	WaitForSingleObject(hScheduleEvent, waitTime);

		while (ScheduleTask *task = tasks[0])
		{
			if (Miranda_Terminated())
				return;

			mir_cslock lock(threadLock);

			time_t timestamp = time(NULL);
			if (task->timestamp > timestamp)
			{
				waitTime = (task->timestamp - timestamp - 1) * 1000;
				goto wait;
			}

			tasks.remove(task);

			mir_forkthread(ExecuteTaskThread, task);
		}

		waitTime = INFINITE;
	}
}
Beispiel #5
0
void __cdecl UpdateMsgsThreadProc(void *)
{
	int ProtoCount;
	PROTOCOLDESCRIPTOR **proto;
	CallService(MS_PROTO_ENUMPROTOCOLS, (WPARAM)&ProtoCount, (LPARAM)&proto);
	int I;
	while (WaitForSingleObject(g_hTerminateUpdateMsgsThread, 0) == WAIT_TIMEOUT && !Miranda_Terminated())
	{
		DWORD MinUpdateTimeDifference = g_MoreOptPage.GetDBValueCopy(IDC_MOREOPTDLG_UPDATEMSGSPERIOD) * 1000; // in milliseconds
		for (I = 0; I < ProtoCount; I++)
		{
			if (proto[I]->type == PROTOTYPE_PROTOCOL && CallProtoService(proto[I]->szName, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_MODEMSGSEND && !IsAnICQProto(proto[I]->szName))
			{
				int Status = CallProtoService(proto[I]->szName, PS_GETSTATUS, 0, 0);
				if (Status < ID_STATUS_OFFLINE || Status > ID_STATUS_OUTTOLUNCH)
				{
					Status = g_ProtoStates[proto[I]->szName].Status;
				}
				if (CallProtoService(proto[I]->szName, PS_GETCAPS, PFLAGNUM_3, 0) & Proto_Status2Flag(Status) && g_ProtoStates[proto[I]->szName].CurStatusMsg.GetUpdateTimeDifference() >= MinUpdateTimeDifference)
				{
					TCString CurMsg(GetDynamicStatMsg(INVALID_HANDLE_VALUE, proto[I]->szName));
					if ((TCString)g_ProtoStates[proto[I]->szName].CurStatusMsg != (const TCHAR*)CurMsg) // if the message has changed
					{
						g_ProtoStates[proto[I]->szName].CurStatusMsg = CurMsg;
						CallAllowedPS_SETAWAYMSG(proto[I]->szName, Status, (char*)TCHAR2ANSI(CurMsg));
					}
				}
			}
		}
		SleepEx(PARSE_INTERVAL, true);
	}
}
Beispiel #6
0
void aim_direct_connection_initiated(HANDLE hNewConnection, DWORD dwRemoteIP, CAimProto* ppro)//for receiving stuff via dc
{
	 file_transfer *ft;

	char cip[20];
	ppro->LOG("Buddy connected from IP: %s", long_ip_to_char_ip(dwRemoteIP, cip));

	//okay someone connected to us or we initiated the connection- we need to figure out who they are and if they belong
	for (int i=21; --i; )
	{
		ft = ppro->ft_list.find_by_ip(dwRemoteIP);

		if (ft == NULL) ft = ppro->ft_list.find_suitable();
		if (ft || Miranda_Terminated()) break;
		Sleep(100);
	}

	if (ft)
	{
		ft->hConn = hNewConnection;
		ppro->aim_dc_helper(ft);
	}
	else 
		Netlib_CloseHandle(hNewConnection);
}
Beispiel #7
0
static int RecvWithTimeoutTime(NetlibConnection *nlc, unsigned dwTimeoutTime, char *buf, int len, int flags)
{
	DWORD dwTimeNow;

	if (!sslApi.pending(nlc->hSsl)) {
		while ((dwTimeNow = GetTickCount()) < dwTimeoutTime) {
			unsigned dwDeltaTime = min(dwTimeoutTime - dwTimeNow, 1000);
			int res = WaitUntilReadable(nlc->s, dwDeltaTime);

			switch (res) {
			case SOCKET_ERROR:
				return SOCKET_ERROR;

			case 1:
				return NLRecv(nlc, buf, len, flags);
			}

			if (nlc->termRequested || Miranda_Terminated())
				return 0;
		}
		SetLastError(ERROR_TIMEOUT);
		return SOCKET_ERROR;
	}
	return NLRecv(nlc, buf, len, flags);
}
bool NetlibReconnect(NetlibConnection *nlc)
{
	char buf[4];
	bool opened = nlc->s != INVALID_SOCKET;
	if (opened) {
		switch (WaitUntilReadable(nlc->s, 0, true)) {
		case SOCKET_ERROR:
			opened = false;
			break;

		case 0:
			opened = true;
			break;

		case 1:
			opened = recv(nlc->s, buf, 1, MSG_PEEK) > 0;
			break;
		}

		if (!opened)
			NetlibDoClose(nlc, true);
	}

	if (!opened) {
		if (Miranda_Terminated())
			return false;

		if (nlc->usingHttpGateway) {
			nlc->proxyAuthNeeded = true;
			return my_connect(nlc, &nlc->nloc);
		}
		return NetlibDoConnect(nlc);
	}
	return true;
}
Beispiel #9
0
void DeleteJob::waitingThread(void *arg) 
{
	DeleteJob *job = (DeleteJob *)arg;

	while(!Miranda_Terminated())
	{
		mir_cslockfull lock(mutexJobCount);
		if (iRunningJobCount < MAX_RUNNING_JOBS)
		{
			iRunningJobCount++;
			lock.unlock();
			job->run();
			delete job;

			lock.lock();
			iRunningJobCount--;
			lock.unlock();

			jobDone.release();
			return;
		}

		lock.unlock();
		jobDone.wait();
	}

	delete job;
}
Beispiel #10
0
static int HttpPeekFirstResponseLine(NetlibConnection *nlc, DWORD dwTimeoutTime, DWORD recvFlags, int *resultCode, char **ppszResultDescr, int *length)
{
	int bytesPeeked;
	char buffer[2048];
	char *peol;

	while (true) {
		bytesPeeked = RecvWithTimeoutTime(nlc, dwTimeoutTime, buffer, _countof(buffer) - 1, MSG_PEEK | recvFlags);

		if (bytesPeeked == 0) {
			SetLastError(ERROR_HANDLE_EOF);
			return 0;
		}
		if (bytesPeeked == SOCKET_ERROR)
			return 0;

		buffer[bytesPeeked] = '\0';
		if ((peol = strchr(buffer, '\n')) != NULL)
			break;

		if ((int)mir_strlen(buffer) < bytesPeeked) {
			SetLastError(ERROR_BAD_FORMAT);
			return 0;
		}
		if (bytesPeeked == _countof(buffer) - 1) {
			SetLastError(ERROR_BUFFER_OVERFLOW);
			return 0;
		}
		if (Miranda_Terminated()) return 0;
		Sleep(10);
	}

	if (peol == buffer) {
		SetLastError(ERROR_BAD_FORMAT);
		return 0;
	}

	*peol = '\0';

	if (_strnicmp(buffer, "HTTP/", 5)) {
		SetLastError(ERROR_BAD_FORMAT);
		return 0;
	}

	size_t off = strcspn(buffer, " \t");
	if (off >= (unsigned)bytesPeeked)
		return 0;

	char* pResultCode = buffer + off;
	*(pResultCode++) = 0;

	char* pResultDescr;
	*resultCode = strtol(pResultCode, &pResultDescr, 10);

	if (ppszResultDescr)
		*ppszResultDescr = mir_strdup(lrtrimp(pResultDescr));

	if (length) *length = peol - buffer + 1;
	return 1;
}
Beispiel #11
0
void __cdecl KeepAliveThread(LPVOID param)
{
	CSametimeProto* proto = (CSametimeProto*)param;
	int i = 120;
	proto->debugLog(_T("KeepAliveThread() start"));

	while (1) {

		if (i <= 0) {
			i = 120;
			// send keepalive every 120 * 250 = 30000[ms]
			if (mwSession_isStarted(proto->session) && proto->session) {
				mwSession_sendKeepalive(proto->session);
			}
		}

		i--;

		SleepEx(250, TRUE);

		EnterCriticalSection(&(proto->session_cs));
		if (Miranda_Terminated() || !proto->session) {
			LeaveCriticalSection(&(proto->session_cs));
			proto->debugLog(_T("KeepAliveThread() end"));
			break;
		}
		LeaveCriticalSection(&(proto->session_cs));
	}

	return;
}
Beispiel #12
0
static void msgloop_loop(void * vqlink)
{
	WSAEVENT hReadEvent;
	SOCKET rx_socket = vqp_link_rx_socket((vqp_link_t) vqlink);

	s_fLoopStarted = TRUE;

	hReadEvent = WSACreateEvent();
	WSAEventSelect(rx_socket, hReadEvent, FD_READ);

	while(!Miranda_Terminated() && !s_fStopLoop) {
		DWORD nEvent = WSAWaitForMultipleEvents(
				1, &hReadEvent, FALSE, WSA_INFINITE, TRUE);

		if(nEvent==WSA_WAIT_EVENT_0) {
			vqp_msg_t msg;

			WSAResetEvent(hReadEvent);
	
			if(!vqp_link_recv((vqp_link_t) vqlink, &msg)) {
				QueueUserAPC(
					s_lpfnMsgHandleApc,
					s_hMainThread, (ULONG_PTR)msg);
			}
		}
	}

	WSACloseEvent(hReadEvent);

	/* wait for pending user APC */
	while(SleepEx(10, TRUE) == WAIT_IO_COMPLETION) /* nothing */;

	/* signal that we've finished */
	SetEvent(s_hStopWaitEvent);
}
Beispiel #13
0
void __cdecl CIcqProto::KeepAliveThread(void *arg)
{
	serverthread_info *info = (serverthread_info*)arg;
	icq_packet packet;
	DWORD dwInterval = getDword("KeepAliveInterval", KEEPALIVE_INTERVAL);

	debugLogA("Keep alive thread starting.");

	info->hKeepAliveEvent = CreateEvent(NULL, FALSE, FALSE, NULL);

	for (;;)
	{
		DWORD dwWait = ICQWaitForSingleObject(info->hKeepAliveEvent, dwInterval);
		if (serverThreadHandle == NULL) // connection lost, end
			break;
		if (dwWait == WAIT_TIMEOUT)
		{
			// Send a keep alive packet to server
			packet.wLen = 0;
			write_flap(&packet, ICQ_PING_CHAN);
			sendServPacket(&packet);
		}
		else if (dwWait == WAIT_IO_COMPLETION)
			// Possible shutdown in progress
			if (Miranda_Terminated()) break;
			else
				break;
	}

	debugLogA("Keep alive thread ended.");

	CloseHandle(info->hKeepAliveEvent);
	info->hKeepAliveEvent = NULL;
}
Beispiel #14
0
// temporary timer for first run
// when this is run, it kill the old startup timer and create the permenant one above
VOID CALLBACK timerProc2(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
{
	KillTimer(NULL, timerId);
	ThreadRunning = FALSE;

	if (db_get_b(NULL, MODULE, "AutoUpdate", 1) && !Miranda_Terminated()) {
		if (db_get_b(NULL, MODULE, "StartupRetrieve", 1))
			CheckAllFeeds(0, 1);
		timerId = SetTimer(NULL, 0, 30000, (TIMERPROC)timerProc);
	}
}
Beispiel #15
0
void GGPROTO::showpopup(const TCHAR* nickname, const TCHAR* msg, int flags)
{
    if (Miranda_Terminated()) return;

    PopupData *puData = (PopupData*)mir_calloc(sizeof(PopupData));
    puData->flags = flags;
    puData->title = mir_tstrdup(nickname);
    puData->text = mir_tstrdup(msg);
    puData->gg = this;

    CallFunctionAsync(sttMainThreadCallback, puData);
}
unsigned int CALLBACK MessagePumpThread(void *param) 
{
	HWND hwndTip = 0;

	MSG hwndMsg = {0};
	while (GetMessage(&hwndMsg, 0, 0, 0) > 0 && !Miranda_Terminated()) 
	{
		if (!IsDialogMessage(hwndMsg.hwnd, &hwndMsg)) 
		{
			switch(hwndMsg.message) 
			{
				case MUM_CREATEPOPUP:
					if(hwndTip) DestroyWindow(hwndTip);
					// if child of clist, zorder is right, but it steals the first click on a contact :(

					// copy topmost exstyle from clist, since we'll put clist under tip in WM_CREATE message
					//LONG clist_exstyle = GetWindowLong((HWND)CallService(MS_CLUI_GETHWND, 0, 0), GWL_EXSTYLE);
					//hwndTip = CreateWindowEx((clist_exstyle & WS_EX_TOPMOST), POP_WIN_CLASS, _T("TipperPopup"), WS_POPUP, 0, 0, 0, 0, 0/*(HWND)CallService(MS_CLUI_GETHWND, 0, 0)*/, 0, hInst, (LPVOID)hwndMsg.lParam);

					hwndTip = CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_TOPMOST, POP_WIN_CLASS, _T("TipperPopup"), WS_POPUP, 0, 0, 0, 0, 0/*(HWND)CallService(MS_CLUI_GETHWND, 0, 0)*/, 0, hInst, (LPVOID)hwndMsg.lParam);
					if(hwndMsg.lParam) free((LPVOID)hwndMsg.lParam);
					break;

				case MUM_DELETEPOPUP:
					if(hwndTip) {
						DestroyWindow(hwndTip);
						hwndTip = NULL;
					}
					break;

				case MUM_GOTSTATUS:
					if(hwndTip) SendMessage(hwndTip, PUM_SETSTATUSTEXT, hwndMsg.wParam, hwndMsg.lParam);
					else if(hwndMsg.lParam) free((void *)hwndMsg.lParam);
					break;

				case MUM_REDRAW:
					if(hwndTip) SendMessage(hwndTip, PUM_REFRESH_VALUES, hwndMsg.wParam, hwndMsg.lParam);
					break;

				case MUM_GOTAVATAR:
					if(hwndTip) SendMessage(hwndTip, PUM_SETAVATAR, hwndMsg.wParam, hwndMsg.lParam);
					break;

				default:
					TranslateMessage(&hwndMsg);
					DispatchMessage(&hwndMsg);
					break;
			}
		}
	}

	return 0;
}
Beispiel #17
0
void CSametimeProto::showPopup(const TCHAR* msg, SametimePopupEnum flag)
{
	if (Miranda_Terminated()) return;

	PopupData *puData = (PopupData*)mir_calloc(sizeof(PopupData));
	puData->flag = flag;
	puData->title = mir_tstrdup(m_tszUserName);
	puData->text = mir_tstrdup(msg);
	puData->proto = this;

	CallFunctionAsync(sttMainThreadCallback, puData);
}
Beispiel #18
0
void CMsnProto::MSN_ShowPopup(const TCHAR* nickname, const TCHAR* msg, int flags, const char* url, MCONTACT hContact)
{
	if (Miranda_Terminated()) return;

	PopupData *pud = (PopupData*)mir_calloc(sizeof(PopupData));
	pud->flags = flags;
	pud->url = mir_strdup(url);
	pud->title = mir_tstrdup(nickname);
	pud->text = mir_tstrdup(msg);
	pud->proto = this;

	CallFunctionAsync(sttMainThreadCallback, pud);
}
Beispiel #19
0
static BOOL CallBackAndWait(struct CpuUsageThreadParams *param,BYTE nCpuUsage)
{
	if (param->hFirstEvent != NULL) {
		/* return value for PollCpuUsage() */
		*param->pidThread=GetCurrentThreadId();
		SetEvent(param->hFirstEvent);
		param->hFirstEvent=NULL;
		/* lower priority after first call */
		SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_IDLE);
	}
	if (!param->pfnDataAvailProc(nCpuUsage,param->lParam)) return FALSE;
	SleepEx(param->dwDelayMillis,TRUE);
	return !Miranda_Terminated();
}
Beispiel #20
0
void gg_showpopup(GGPROTO* gg, const char* nickname, const char* msg, int flags)
{
    PopupData* puData;

    if (Miranda_Terminated()) return;

    puData = (PopupData*)mir_alloc(sizeof(PopupData));
    puData->flags = flags;
    puData->title = mir_strdup(nickname);
    puData->text = mir_strdup(msg);
    puData->gg = gg;

    CallFunctionAsync(sttMainThreadCallback, puData);
}
Beispiel #21
0
void CMsnProto::MSN_GoOffline(void)
{
	if (m_iStatus == ID_STATUS_OFFLINE) return;

	msnLoggedIn = false;

	if (mStatusMsgTS)
		ForkThread(&CMsnProto::msn_storeProfileThread, NULL);

	mir_free(msnPreviousUUX);
	msnPreviousUUX = NULL;
	msnSearchId = NULL;

	if (!Miranda_Terminated())
		MSN_EnableMenuItems(false);

	MSN_FreeGroups();
	MsgQueue_Clear();
	clearCachedMsg();

	if (!Miranda_Terminated()) {
		int msnOldStatus = m_iStatus; m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
		ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)msnOldStatus, ID_STATUS_OFFLINE);
		isIdle = false;

		int count = -1;
		for (;;) {
			MsnContact *msc = Lists_GetNext(count);
			if (msc == NULL) break;

			if (ID_STATUS_OFFLINE != getWord(msc->hContact, "Status", ID_STATUS_OFFLINE)) {
				setWord(msc->hContact, "Status", ID_STATUS_OFFLINE);
				setDword(msc->hContact, "IdleTS", 0);
			}
		}
	}
}
Beispiel #22
0
int ModeChange(WPARAM, LPARAM lparam)
{
	ACKDATA *ack = (ACKDATA *)lparam;

	if (ack->type != ACKTYPE_STATUS || ack->result != ACKRESULT_SUCCESS || ack->hContact != NULL) return 0;
	courProtoName = (char *)ack->szModule;
	if (!IsWatchedProtocol(courProtoName) && strncmp(courProtoName, "MetaContacts", 12))
		return 0;

	DBWriteTimeTS(time(NULL), NULL);

	//	isetting=CallProtoService(ack->szModule,PS_GETSTATUS,0,0);
	WORD isetting = (WORD)ack->lParam;
	if (isetting < ID_STATUS_OFFLINE) isetting = ID_STATUS_OFFLINE;
	if ((isetting > ID_STATUS_OFFLINE) && ((WORD)ack->hProcess <= ID_STATUS_OFFLINE)) {
		//we have just loged-in
		db_set_dw(NULL, "UserOnline", ack->szModule, GetTickCount());
		if (!Miranda_Terminated() && IsWatchedProtocol(ack->szModule)) {
			logthread_info *info = (logthread_info *)mir_alloc(sizeof(logthread_info));
			mir_strncpy(info->sProtoName, courProtoName, _countof(info->sProtoName));
			info->hContact = 0;
			info->currStatus = 0;

			mir_forkthread(cleanThread, info);
		}
	}
	else if ((isetting == ID_STATUS_OFFLINE) && ((WORD)ack->hProcess > ID_STATUS_OFFLINE)) {
		//we have just loged-off
		if (IsWatchedProtocol(ack->szModule)) {
			char str[MAXMODULELABELLENGTH + 9];
			time_t t;

			time(&t);
			mir_snprintf(str, "OffTime-%s", ack->szModule);
			db_set_dw(NULL, S_MOD, str, t);
		}
	}

	if (isetting == db_get_w(NULL, S_MOD, courProtoName, ID_STATUS_OFFLINE))
		return 0;

	db_set_w(NULL, S_MOD, courProtoName, isetting);

	if (g_bFileActive)
		FileWrite(NULL);

	courProtoName = NULL;
	return 0;
}
Beispiel #23
0
void __cdecl CAimProto::aim_dc_helper(void* param) //only called when we are initiating a direct connection with someone else
{
	file_transfer *ft = (file_transfer*)param;	

	sendBroadcast(ft->hContact, ACKTYPE_FILE, ACKRESULT_CONNECTED, ft, 0);

	NETLIBPACKETRECVER packetRecv = {0};
	packetRecv.cbSize = sizeof(packetRecv);
	packetRecv.dwTimeout = 350000;

	HANDLE hServerPacketRecver = (HANDLE) CallService(MS_NETLIB_CREATEPACKETRECVER, (WPARAM)ft->hConn, 2048 * 4);

	int result;
	if (ft->sending)//we are sending
		result = sending_file(ft, hServerPacketRecver, packetRecv);
	else 
		result = receiving_file(ft, hServerPacketRecver, packetRecv);

	Netlib_CloseHandle(hServerPacketRecver);
	Netlib_CloseHandle(ft->hConn);
	ft->hConn = NULL;

	if (result == 0)
	{
		sendBroadcast(ft->hContact, ACKTYPE_FILE, ACKRESULT_SUCCESS, ft, 0);
	}
	else
	{
		if (!ft->requester && result == 1 && !Miranda_Terminated())
		{
			ft->accepted = false;
			HANDLE hConn = aim_peer_connect(AIM_PROXY_SERVER, get_default_port());
			if (hConn) 
			{
				LOG("Connected to proxy ip because we want to use a proxy for the file transfer.");
				ft->requester = true;
				ft->hConn = hConn;
				ForkThread(&CAimProto::aim_proxy_helper, ft);
				return;
			}
		}
		aim_file_ad(hServerConn, seqno, ft->sn, ft->icbm_cookie, true, 0);
		sendBroadcast(ft->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, ft, 0);
	}

	ft_list.remove_by_ft(ft);
}
Beispiel #24
0
void __cdecl SendThread(LPVOID param) {

	mwFileTransfer* ft = (mwFileTransfer*)param;
	if (!ft) return;
	CSametimeProto* proto = getProtoFromMwFileTransfer(ft);
	FileTransferClientData* ftcd = (FileTransferClientData*)mwFileTransfer_getClientData(ft);

	proto->debugLog(_T("SendThread() start"));

	PROTOFILETRANSFERSTATUS pfts = {0};

	pfts.cbSize = sizeof(pfts);
	pfts.flags = PFTS_UTF;
	pfts.hContact = ftcd->hContact;
	if (ftcd->sending == 1)
		pfts.flags |= PFTS_SENDING;

	pfts.pszFiles = NULL;
	pfts.totalFiles = ftcd->first->ft_count;
	pfts.totalBytes = ftcd->first->totalSize;

	while(SendFileChunk(proto, ft, ftcd) && !Miranda_Terminated()) {
		pfts.currentFileNumber = ftcd->ft_number;
		pfts.totalProgress = ftcd->sizeToHere + mwFileTransfer_getSent(ft);
		pfts.szWorkingDir = ftcd->save_path;
		pfts.szCurrentFile = (char*)mwFileTransfer_getFileName(ft);
		pfts.currentFileSize = mwFileTransfer_getFileSize(ft);
		pfts.currentFileProgress = mwFileTransfer_getSent(ft);
		pfts.currentFileTime = 0; //?

		proto->ProtoBroadcastAck(ftcd->hContact, ACKTYPE_FILE, ACKRESULT_DATA, ftcd->hFt, (LPARAM)&pfts);

		SleepEx(500,TRUE);
	}

	proto->ProtoBroadcastAck(ftcd->hContact, ACKTYPE_FILE, ACKRESULT_SUCCESS, ftcd->hFt, 0);

	mwFileTransfer_removeClientData(ft);
	if (ftcd->save_path) free(ftcd->save_path);
	if (ftcd->buffer) delete[] ftcd->buffer;
	delete ftcd;
	
	proto->debugLog(_T("SendThread() end"));
	return;
}
Beispiel #25
0
// main auto-update timer
VOID CALLBACK timerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
{
	// only run if it is not current updating and the auto update option is enabled
	if (!ThreadRunning && !Miranda_Terminated()) {
		BOOL HaveUpdates = FALSE;
		for (MCONTACT hContact = db_find_first(MODULE); hContact; hContact = db_find_next(hContact, MODULE)) {
			if (db_get_dw(hContact, MODULE, "UpdateTime", DEFAULT_UPDATE_TIME)) {
				double diff = difftime(time(NULL), db_get_dw(hContact, MODULE, "LastCheck", 0));
				if (db_get_b(NULL, MODULE, "AutoUpdate", 1) != 0 && diff >= db_get_dw(hContact, MODULE, "UpdateTime", DEFAULT_UPDATE_TIME) * 60) {
					UpdateListAdd(hContact);
					HaveUpdates = TRUE;
				}
			}
		}
		if (!ThreadRunning && HaveUpdates)
			mir_forkthread(UpdateThreadProc, (LPVOID)FALSE);
	}
}
Beispiel #26
0
void ShowNotification(const char *caption, const char *message, int flags, MCONTACT hContact)
{
	if (Miranda_Terminated())
		return;

	if (ServiceExists(MS_POPUP_ADDPOPUPT) && db_get_b(NULL, "Popup", "ModuleIsEnabled", 1))
	{
		POPUPDATA ppd = { 0 };
		ppd.lchContact = hContact;
		mir_strncpy(ppd.lpzContactName, caption, MAX_CONTACTNAME);
		mir_strncpy(ppd.lpzText, message, MAX_SECONDLINE);

		if (!PUAddPopup(&ppd))
			return;
	}

	::MessageBoxA(NULL, message, caption, MB_OK | flags);
}
Beispiel #27
0
void CSteamProto::ShowNotification(const TCHAR *caption, const wchar_t *message, int flags, MCONTACT hContact)
{
	if (Miranda_Terminated())
		return;

	if (ServiceExists(MS_POPUP_ADDPOPUPT) && db_get_b(NULL, "Popup", "ModuleIsEnabled", 1))
	{
		POPUPDATAT ppd = { 0 };
		ppd.lchContact = hContact;
		wcsncpy(ppd.lpwzContactName, caption, MAX_CONTACTNAME);
		wcsncpy(ppd.lpwzText, message, MAX_SECONDLINE);
		ppd.lchIcon = IcoLib_GetIcon(MODULE"_main");

		if (!PUAddPopupT(&ppd))
			return;
	}

	MessageBox(NULL, message, caption, MB_OK | flags);
}
HANDLE GetCurrChain()
{
  struct AskChain * workChain;
  HANDLE res=NULL;
  while (LockChainDeletion)   
  {
    SleepEx(0,TRUE);
    if (Miranda_Terminated()) return 0;
  }
  LockChainAddition=1;
  if (FirstChain)
  {
    res=FirstChain->ContactRequest;
    workChain=FirstChain->Next;
    mir_free(FirstChain);
    FirstChain=(AskChain *)workChain;
  }
  LockChainAddition=0;
  return res;
}
int AddHandleToChain(HANDLE hContact)
{
  AskChain * workChain;
  while (LockChainAddition) 
  {
    SleepEx(0,TRUE);
    if (Miranda_Terminated()) return 0;
  }
  LockChainDeletion=1;
  {
    //check that handle is present
     AskChain * wChain;
     wChain=FirstChain;
     if (wChain)
     {
       do {
         if (wChain->ContactRequest==hContact)
         {
           LockChainDeletion=0;
           return 0;
         }
       } while(wChain=(AskChain *)wChain->Next);
     }
  }
  if (!FirstChain)  
  {
    FirstChain=mir_alloc(sizeof(AskChain));
    workChain=FirstChain;

  }
  else 
  {
    LastChain->Next=mir_alloc(sizeof(AskChain));
    workChain=(AskChain *)LastChain->Next;
  }
  LastChain=workChain;
  workChain->Next=NULL;
  workChain->ContactRequest=hContact;
  LockChainDeletion=0;
  return 1;
}
Beispiel #30
0
void UpdateThreadProc(LPVOID AvatarCheck)
{
	WaitForSingleObject(hUpdateMutex, INFINITE);
	if (ThreadRunning) {
		ReleaseMutex(hUpdateMutex);
		return;
	}
	ThreadRunning = TRUE;	// prevent 2 instance of this thread running
	ReleaseMutex(hUpdateMutex);

	// update news by getting the first station from the queue until the queue is empty
	while (UpdateListHead != NULL && !Miranda_Terminated()) {
		if ((BOOL)AvatarCheck)
			CheckCurrentFeedAvatar(UpdateGetFirst());
		else
			CheckCurrentFeed(UpdateGetFirst());
	}

	// exit the update thread
	ThreadRunning = FALSE;
}